Java Code Examples for com.facebook.litho.LithoView#create()

The following examples show how to use com.facebook.litho.LithoView#create() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StateResettingActivity.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  mData = getData();
  mComponentContext = new ComponentContext(this);

  mLithoView =
      LithoView.create(
          this,
          StateResettingRootComponent.create(mComponentContext)
              .dataModels(mData)
              .showHeader(false)
              .build());

  setContentView(mLithoView);

  fetchHeader();
}
 
Example 2
Source File: PropUpdatingActivity.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  mComponentContext = new ComponentContext(this);

  mDataModels = getData(5);

  mLithoView =
      LithoView.create(
          this,
          SelectedItemRootComponent.create(mComponentContext)
              .dataModels(mDataModels)
              .selectedItem(0)
              .build());

  setContentView(mLithoView);

  fetchData();
}
 
Example 3
Source File: ItemsRerenderingActivity.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  mComponentContext = new ComponentContext(this);

  mLithoView =
      LithoView.create(
          this,
          ItemsRerenderingRootComponent.create(mComponentContext)
              .dataModels(getData(15))
              .build());

  setContentView(mLithoView);

  fetchData();
}
 
Example 4
Source File: ScrollingToBottomActivity.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  mComponentContext = new ComponentContext(this);
  mFeedData = getData(15, 15);

  mLithoView =
      LithoView.create(
          this,
          DelayedLoadingComponent.create(mComponentContext)
              .headerDataModels(null)
              .feedDataModels(mFeedData)
              .build());

  setContentView(mLithoView);

  fetchData();
}
 
Example 5
Source File: TTIMarkerActivity.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  final ComponentContext c = new ComponentContext(this);
  final SectionContext sc = new SectionContext(this);

  final List<Object> data = new ArrayList<>();
  data.add("Hello World");

  final Component component =
      RecyclerCollectionComponent.create(c)
          .section(TTIMarkerSection.create(sc).data(data))
          .build();
  final LithoView lithoView = LithoView.create(c, component);
  setContentView(lithoView);
}
 
Example 6
Source File: FrescoVitoLithoGalleryFragment.java    From fresco with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(
    @Nullable LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState) {
  final ComponentContext c = new ComponentContext(getContext());
  return LithoView.create(
      c,
      RecyclerCollectionComponent.create(c)
          .section(SimpleGallerySection.create(new SectionContext(c)).build())
          .recyclerConfiguration(GridRecyclerConfiguration.create().numColumns(4).build())
          .disablePTR(true)
          .build());
}
 
Example 7
Source File: LifecycleDelegateActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  final LinearLayout parent = new LinearLayout(this);
  parent.setOrientation(LinearLayout.VERTICAL);
  parent.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));

  final ComponentContext componentContext = new ComponentContext(this);
  mLithoView =
      LithoView.create(
          this,
          LifecycleDelegateComponent.create(componentContext)
              .id(mId.getAndIncrement())
              .delegateListener(mDelegateListener)
              .build());
  final LayoutParams params1 = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
  params1.weight = 1;
  mLithoView.setLayoutParams(params1);
  parent.addView(mLithoView);

  mConsoleView = new ConsoleView(this);
  final LayoutParams params2 = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
  params2.weight = 1;
  mConsoleView.setLayoutParams(params2);
  parent.addView(mConsoleView);

  setContentView(parent);
}
 
Example 8
Source File: FrescoVitoLithoSectionsFragment.java    From fresco with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(
    @Nullable LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState) {
  final ComponentContext c = new ComponentContext(getContext());
  return LithoView.create(
      c,
      RecyclerCollectionComponent.create(c)
          .section(SimpleListSection.create(new SectionContext(c)).build())
          .disablePTR(true)
          .build());
}
 
Example 9
Source File: TreePropTestActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  SoLoader.init(this, false);

  final ComponentContext c = new ComponentContext(this);
  final LithoView lithoView = LithoView.create(c, RootComponent.create(c).build());
  setContentView(lithoView);
}
 
Example 10
Source File: DiffingTreePropTestActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  SoLoader.init(this, false);

  final ComponentContext c = new ComponentContext(this);
  final LithoView lithoView = LithoView.create(c, RootDiffingComponent.create(c).build());
  setContentView(lithoView);
}
 
Example 11
Source File: LithoLabApproximateEndActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  final ComponentContext c = new ComponentContext(this);

  final LithoView lithoView =
      LithoView.create(this /* context */, LithoLabEndComponent.create(c).build());

  setContentView(lithoView);
}
 
Example 12
Source File: LithoViewMatchersTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
@Before
public void before() throws Throwable {
  ComponentsConfiguration.isEndToEndTestRun = true;
  final ComponentContext mComponentContext =
      new ComponentContext(InstrumentationRegistry.getTargetContext());
  final Component mTextComponent = MyComponent.create(mComponentContext).text("foobar").build();
  mView = LithoView.create(InstrumentationRegistry.getTargetContext(), mTextComponent);
  ViewHelpers.setupView(mView).setExactWidthPx(200).setExactHeightPx(100).layout();
}
 
Example 13
Source File: TooltipTriggerExampleComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
private static PopupWindow createTooltip(final ComponentContext c, final String text) {
  final LithoView tooltip =
      LithoView.create(
          c,
          Column.create(c)
              .paddingDip(YogaEdge.ALL, 15)
              .backgroundColor(LITHO_PINK)
              .child(Text.create(c).text(text).textColor(Color.WHITE))
              .build());
  return new PopupWindow(
      tooltip,
      LinearLayout.LayoutParams.WRAP_CONTENT,
      LinearLayout.LayoutParams.WRAP_CONTENT,
      true);
}
 
Example 14
Source File: TooltipTriggerExampleActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  final ComponentContext componentContext = new ComponentContext(this);
  LithoView content =
      LithoView.create(this, TooltipTriggerExampleComponent.create(componentContext).build());
  content.notifyVisibleBoundsChanged();
  setContentView(content);
}
 
Example 15
Source File: ExpandableElementActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  final LithoView lithoView =
      LithoView.create(
          this,
          ExpandableElementRootComponent.create(new ComponentContext(this))
              .initialMessages(Arrays.asList(MESSAGES))
              .build());
  setContentView(lithoView);
}
 
Example 16
Source File: AnimationCallbacksActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  final ComponentContext componentContext = new ComponentContext(this);
  Component component =
      RecyclerCollectionComponent.create(componentContext)
          .disablePTR(true)
          .section(
              AnimationCallbacksListSection.create(new SectionContext(componentContext)).build())
          .build();
  LithoView lithoView = LithoView.create(this, component);
  setContentView(lithoView);
}
 
Example 17
Source File: AnimationCookBookActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  final ComponentContext componentContext = new ComponentContext(this);
  Component component =
      RecyclerCollectionComponent.create(componentContext)
          .disablePTR(true)
          .section(
              AnimationCookBookListSection.create(new SectionContext(componentContext)).build())
          .build();
  LithoView lithoView = LithoView.create(this, component);
  setContentView(lithoView);
}
 
Example 18
Source File: TransitionsActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  final ComponentContext componentContext = new ComponentContext(this);
  Component component =
      RecyclerCollectionComponent.create(componentContext)
          .disablePTR(true)
          .section(TransitionsListSection.create(new SectionContext(componentContext)).build())
          .build();
  LithoView lithoView = LithoView.create(this, component);
  setContentView(lithoView);
}
 
Example 19
Source File: SharedElementsActivity.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  final ComponentContext c = new ComponentContext(this);
  LithoView lithoView = LithoView.create(this, SharedElementsComponent.create(c).build());
  setContentView(lithoView);
}
 
Example 20
Source File: DetailActivity.java    From litho with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  boolean landLitho = getIntent().getBooleanExtra(INTENT_LAND_LITHO, true);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    // This transition here is used only as an example, any provided/custom Android transition can
    // be used here.
    Slide slide = new Slide(Gravity.BOTTOM);
    slide.setInterpolator(
        AnimationUtils.loadInterpolator(this, android.R.interpolator.linear_out_slow_in));
    if (getWindow() != null) {
      getWindow().setEnterTransition(slide);
    }

    // When landing on an Activity that renders a LithoView we need to postpone the enter
    // transition.
    if (landLitho) {
      postponeEnterTransition();
    }
  }

  super.onCreate(savedInstanceState);
  Spannable titleSpannable =
      new SpannableString("SHARED ELEMENT " + (landLitho ? "LITHO" : "XML"));
  titleSpannable.setSpan(
      new ForegroundColorSpan(Color.RED),
      14,
      titleSpannable.length(),
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  if (landLitho) {
    final ComponentContext componentContext = new ComponentContext(this);
    LithoView.OnDirtyMountListener dirtyMountListener =
        new LithoView.OnDirtyMountListener() {
          @Override
          public void onDirtyMount(LithoView view) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
              // Continue the transition after Litho finishes it's dirty mount.
              startPostponedEnterTransition();
            }
          }
        };
    LithoView lithoView =
        LithoView.create(
            this,
            getContent(
                componentContext, getIntent().getIntExtra(INTENT_COLOR_KEY, 0), titleSpannable));
    lithoView.setOnDirtyMountListener(dirtyMountListener);
    setContentView(lithoView);
  } else {
    setContentView(R.layout.detail_activity_shared_elements);

    ((ImageView) findViewById(R.id.square_imageview))
        .setImageDrawable(new ColorDrawable(getIntent().getIntExtra(INTENT_COLOR_KEY, 0)));

    ((TextView) findViewById(R.id.title_textview)).setText(titleSpannable);
  }
}