/** * For HostComponents, we don't set a scoped context during layout calculation because we don't * need one, as we could never call a state update on it. Instead it's okay to use the context * that is passed to MountState from the LithoView, which is not scoped. */ private ComponentContext getContextForComponent(Component component) { final ComponentContext c = component.getScopedContext(); return c == null ? mContext : c; }
protected static <E> EventHandler<E> newEventHandler( Component c, int id, Object[] params) { final EventHandler<E> eventHandler = new EventHandler<>(c, id, params); if (c.getScopedContext() != null && c.getScopedContext().getComponentTree() != null) { c.getScopedContext().getComponentTree().recordEventHandler(c, eventHandler); } return eventHandler; }
/** * @return The root {@link DebugComponent} of a LithoView. This should be the start of your * traversal. */ @Nullable public static DebugComponent getRootInstance(Component component) { return getRootInstance(component.getScopedContext().getComponentTree()); }
private static @Nullable void collectMountTimeTransitions( LayoutState layoutState, List<Transition> outList) { final List<Component> componentsNeedingPreviousRenderData = layoutState.getComponentsNeedingPreviousRenderData(); if (componentsNeedingPreviousRenderData == null) { return; } for (int i = 0, size = componentsNeedingPreviousRenderData.size(); i < size; i++) { final Component component = componentsNeedingPreviousRenderData.get(i); final Transition transition = component.createTransition(component.getScopedContext()); if (transition != null) { TransitionUtils.addTransitions(transition, outList, layoutState.mRootComponentName); } } }
private static Component createSpyComponent( ComponentContext context, TestBaseComponent component) { Component spy = spy(component); when(spy.getScopedContext()).thenReturn(context); return spy; }
@Nullable final ComponentContext scopedContext = component.getScopedContext(); if (scopedContext == null) { return null;
private Component setUpSpyLayoutSpecWithNullLayout() { Component component = spy(new TestBaseComponent(false, MountType.NONE, null, false, mPreviousOnErrorConfig)); when(component.getScopedContext()).thenReturn(mContext); return component; }
/** * @return whether the given component will render because it returns non-null from its resolved * onCreateLayout, based on its current props and state. Returns true if the resolved layout * is non-null, otherwise false. * @deprecated Using willRender is regarded as an anti-pattern, since it will load all classes * into memory in order to potentially decide not to use any of them. */ @Deprecated public static boolean willRender(ComponentContext c, Component component) { if (component == null) { return false; } final ComponentContext scopedContext = component.getScopedContext(); if (scopedContext != null) { assertSameBaseContext(scopedContext, c); } if (component.mLayoutCreatedInWillRender != null) { return willRender(component.mLayoutCreatedInWillRender); } component.mLayoutCreatedInWillRender = Layout.create(c, component); return willRender(component.mLayoutCreatedInWillRender); }
private void bindEventAndTriggerHandlers(List<Component> components) { clearUnusedTriggerHandlers(); for (final Component component : components) { mEventHandlersController.bindEventHandlers( component.getScopedContext(), component, component.getGlobalKey()); bindTriggerHandler(component); } mEventHandlersController.clearUnusedEventHandlers(); }
InternalNode resolveLayout(Component component) { final InternalNode layoutCreatedInWillRender = component.consumeLayoutCreatedInWillRender(); if (layoutCreatedInWillRender != null) { return layoutCreatedInWillRender; } component = component.getThreadSafeInstance(); component.updateInternalChildState(this, true); if (ComponentsConfiguration.isDebugModeEnabled) { DebugComponent.applyOverrides(this, component); } final InternalNode node = (InternalNode) component.resolve(component.getScopedContext()); if (component.canResolve()) { final CommonPropsCopyable props = component.getCommonPropsCopyable(); if (props != null) { props.copyInto(component.getScopedContext(), node); } } return node; }
component.transferState(currentStateContainer, component.getStateContainer()); } else { component.createInitialState(component.getScopedContext()); if (component.getScopedContext().isNestedTreeResolutionExperimentEnabled()) { synchronized (this) {
/** * 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); } }
@Test public void testGetAnnotationBundleFromLogger() { final BaseComponentsLogger logger = new TestComponentsLogger() { @Nullable @Override public Map<String, String> getExtraAnnotations(TreeProps treeProps) { final Object o = treeProps.get(MyKey.class); final Map<String, String> map = new LinkedHashMap<>(2); map.put("my_key", String.valueOf((int) o)); map.put("other_key", "value"); return map; } }; final TreeProps treeProps = new TreeProps(); final Component component = mock(Component.class); when(component.getScopedContext()).thenReturn(mContext); treeProps.put(MyKey.class, 1337); mContext.setTreeProps(treeProps); final String res = LogTreePopulator.getAnnotationBundleFromLogger(component, logger); assertThat(res).isEqualTo("my_key:1337:other_key:value:"); }
InternalNode newLayoutBuilder( Component component, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final InternalNode layoutCreatedInWillRender = component.consumeLayoutCreatedInWillRender(); if (layoutCreatedInWillRender != null) { return layoutCreatedInWillRender; } component = component.getThreadSafeInstance(); component.updateInternalChildState(this); if (ComponentsConfiguration.isDebugModeEnabled) { DebugComponent.applyOverrides(this, component); } final InternalNode node = component.createLayout(component.getScopedContext(), false); if (node != NULL_LAYOUT) { applyStyle(node, defStyleAttr, defStyleRes); } return node; }
c = component.getScopedContext();
component.getScopedContext() == null ? null : component.getScopedContext().getAndroidContext(); if (TransitionUtils.areTransitionsEnabled(scopedAndroidContext)) { if (isTracing) { if (delegate.getScopedContext() != null && delegate.getScopedContext().getComponentTree() != null) { layoutState.mComponents.add(delegate);
node.markIsNestedTreeHolder(context.getTreeProps()); } else if (component.canResolve()) { context.setTreeProps(component.getScopedContext().getTreePropsCopy()); node = (InternalNode) component.resolve(context); } else {
component.onMeasure(component.getScopedContext(), node, widthSpec, heightSpec, size);