/** * Prepares a component for calling any pending state updates on it by setting the TreeProps which * the component requires from its parent, setting a scoped component context and applies the * pending state updates. * * @param c component context */ private void applyStateUpdates(ComponentContext c) { setScopedContext(ComponentContext.withComponentScope(c, this)); populateTreeProps(getScopedContext().getTreeProps()); if (hasState()) { c.getStateHandler().applyStateUpdatesForComponent(this); } }
final Component drawableComponent = DrawableComponent.create(reference); drawableComponent.setScopedContext( ComponentContext.withComponentScope(node.getContext(), drawableComponent)); final boolean isOutputUpdated; if (recycle != null) {
@Before public void setup() { MockitoAnnotations.initMocks(this); ComponentsConfiguration.isNestedTreeResolutionExperimentEnabled = true; mContext = new ComponentContext(RuntimeEnvironment.application); mComponent = new InlineLayoutSpec() { @Override @OnCreateLayout protected Component onCreateLayout(ComponentContext c) { return Row.create(c) .marginPx(YogaEdge.LEFT, MARGIN_LEFT) .marginPx(YogaEdge.TOP, MARGIN_TOP) .child( TestDrawableComponent.create(c) .key(KEY_ANCHOR) .widthPx(ANCHOR_WIDTH) .heightPx(ANCHOR_HEIGHT)) .build(); } }; mComponentTree = ComponentTree.create(mContext, mComponent).build(); Whitebox.setInternalState(mComponent, "mGlobalKey", mComponent.getKey()); mContext = ComponentContext.withComponentTree(mContext, mComponentTree); mContext = ComponentContext.withComponentScope(mContext, mComponent); mLithoView = getLithoView(mComponentTree); mAnchorGlobalKey = ComponentKeyUtils.getKeyWithSeparator(Row.create(mContext).build().getTypeId(), KEY_ANCHOR); }
@Before public void setup() { MockitoAnnotations.initMocks(this); mContext = new ComponentContext(RuntimeEnvironment.application); mComponent = new InlineLayoutSpec() { @Override @OnCreateLayout protected Component onCreateLayout(ComponentContext c) { return Row.create(c) .marginPx(YogaEdge.LEFT, MARGIN_LEFT) .marginPx(YogaEdge.TOP, MARGIN_TOP) .child( TestDrawableComponent.create(c) .key("anchor") .widthPx(ANCHOR_WIDTH) .heightPx(ANCHOR_HEIGHT)) .build(); } }; mComponentTree = ComponentTree.create(mContext, mComponent).build(); Whitebox.setInternalState( mComponent, "mGlobalKey", ComponentKeyUtils.getKeyWithSeparator( mComponent.getTypeId(), Row.create(mContext).build().getTypeId())); mContext = ComponentContext.withComponentTree(mContext, mComponentTree); mContext = ComponentContext.withComponentScope(mContext, mComponent); mLithoView = getLithoView(mComponentTree); }
@Test public void testComponentOnSyntheticEventClick() { final Class activityClassToLaunch = PlaygroundActivity.class; final Component component = DemoListItemComponent.create(mComponentsRule.getContext()) .model(new DemoListActivity.DemoListDataModel("My Component", activityClassToLaunch)) .currentIndices(null) .build(); // Here, we make use of Litho's internal event infrastructure and manually dispatch the event. final ComponentContext componentContext = withComponentScope(mComponentsRule.getContext(), component); component .getEventDispatcher() .dispatchOnEvent(DemoListItemComponent.onClick(componentContext), new ClickEvent()); final Intent nextIntent = shadowOf(mComponentsRule.getContext().getAndroidContext()) .getShadowApplication() .getNextStartedActivity(); assertThat(nextIntent.getComponent().getClassName()).isSameAs(activityClassToLaunch.getName()); } }