/** @param c The {@link ComponentContext} the RecyclerBinder will use. */ public RecyclerBinder build(ComponentContext c) { componentContext = new ComponentContext( c.getAndroidContext(), c.getLogTag(), c.getLogger(), c.getTreePropsCopy()); if (layoutInfo == null) { layoutInfo = new LinearLayoutInfo(c.getAndroidContext(), VERTICAL, false); } return new RecyclerBinder(this); } }
@Before public void setup() { mContext = new ComponentContext( new ContextThemeWrapper(RuntimeEnvironment.application, R.style.TestTheme)); mDimen = mContext.getResources().getDimensionPixelSize(R.dimen.test_dimen); mLargeDimen = mContext.getResources().getDimensionPixelSize(R.dimen.test_large_dimen); }
/** * 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); } }
public SectionContext(ComponentContext context) { this( context.getAndroidContext(), context.getLogTag(), context.getLogger(), context.getTreePropsCopy()); }
public void init(ComponentContext context) { mResources = context.getAndroidContext().getResources(); mTheme = context.getAndroidContext().getTheme(); mResourceCache = context.getResourceCache(); }
private static void assertSameBaseContext( ComponentContext scopedContext, ComponentContext willRenderContext) { if (scopedContext.getAndroidContext() != willRenderContext.getAndroidContext()) { final ComponentsLogger logger = scopedContext.getLogger(); if (logger != null) { logger.emitMessage( ComponentsLogger.LogLevel.ERROR, "Found mismatching base contexts between the Component's Context (" + scopedContext.getAndroidContext() + ") and the Context used in willRender (" + willRenderContext.getAndroidContext() + ")!"); } } }
static ComponentContext withComponentTree(ComponentContext context, ComponentTree componentTree) { ComponentContext componentContext = new ComponentContext(context, ComponentsPools.acquireStateHandler(), null, null); componentContext.mComponentTree = componentTree; return componentContext; }
@Nullable static Drawable getBackgroundOrDefault(ComponentContext c, Drawable specifiedBackground) { if (specifiedBackground != null) { return specifiedBackground; } final int[] attrs = {android.R.attr.background}; TypedArray a = c.getAndroidContext().obtainStyledAttributes(null, attrs, android.R.attr.editTextStyle, 0); Drawable defaultBackground = a.getDrawable(0); a.recycle(); return defaultBackground; }
@Before public void setup() { mContext = new ComponentContext(RuntimeEnvironment.application); mLithoView = new LithoView(mContext); mParent = new FrameLayout(mContext.getAndroidContext()); mParent.setLeft(0); mParent.setTop(0); mParent.setRight(10); mParent.setBottom(10); mParent.addView(mLithoView); }
Component.isNestedTree((Component) this) && !resolveNestedTree; final TreeProps parentTreeProps = context.getTreeProps(); context.setTreeProps(getTreePropsForChildren(context, parentTreeProps)); if (deferNestedTreeResolution) { node = ComponentsPools.acquireInternalNode(context); node.markIsNestedTreeHolder(context.getTreeProps()); } else if (component.canResolve()) { context.setTreeProps(component.getScopedContext().getTreePropsCopy()); node = (InternalNode) component.resolve(context); } else { node = null; } else { node = context.resolveLayout(layoutComponent); if (TransitionUtils.areTransitionsEnabled(context.getAndroidContext())) { if (needsPreviousRenderData()) { node.addComponentNeedingPreviousRenderData((Component) this);
final KeyHandler keyHandler = (ComponentsConfiguration.useGlobalKeys || ComponentsConfiguration.isDebugModeEnabled) ? new KeyHandler(mContext.getLogger()) : null; new ComponentContext( context, StateHandler.acquireNewInstance(mStateHandler), keyHandler, treeProps);
@Test public void testResolveDrawableAttribute() { Column column = Column.create(mContext).backgroundAttr(testAttrDrawable, 0).build(); InternalNode node = Layout.create(mContext, column); Drawable d = mContext.getResources().getDrawable(test_bg); ComparableDrawableWrapper comparable = (ComparableDrawableWrapper) acquire(mContext.getAndroidContext(), node.getBackground()); assertThat(comparable.getWrappedDrawable()).isEqualTo(d); }
private void logDuplicateManualKeyWarning(Component component, String key) { final ComponentsLogger logger = mScopedContext.getLogger(); if (logger != null) { logger.emitMessage( ComponentsLogger.LogLevel.WARNING, "The manual key " + key + " you are setting on this " + component.getSimpleName() + " is a duplicate and will be changed into a unique one. " + "This will result in unexpected behavior if you don't change it."); } }
parentContext.isNestedTreeResolutionExperimentEnabled() ? parentContext : node.getContext(), component.getScopedContext() == null ? null : component.getScopedContext().getAndroidContext(); if (TransitionUtils.areTransitionsEnabled(scopedAndroidContext)) { if (isTracing) { && delegate.getScopedContext().getComponentTree() != null) { layoutState.mComponents.add(delegate);
@Test public void testCreationWithInputs() { ComponentTree componentTree = mComponentTreeBuilder .layoutThreadLooper(mLooper) .build(); assertSameAsInternalState(componentTree, mRoot, "mRoot"); assertEqualToInternalState(componentTree, true, "mIsLayoutDiffingEnabled"); assertThat(componentTree.isIncrementalMountEnabled()).isTrue(); assertThat(mContext.getLogger()).isEqualTo(mComponentsLogger); assertThat(mContext.getLogTag()).isEqualTo(mLogTag); Handler handler = getInternalState(componentTree, "mLayoutThreadHandler"); assertThat(mLooper).isSameAs(handler.getLooper()); }
public T accessibilityRoleDescription(@StringRes int stringId) { return accessibilityRoleDescription(mContext.getResources().getString(stringId)); }
public static PerfEvent populatePerfEventFromLogger( ComponentContext c, ComponentsLogger logger, PerfEvent perfEvent) { final String logTag = c.getLogTag(); if (logTag == null) { logger.cancelPerfEvent(perfEvent); @Nullable final TreeProps treeProps = c.getTreeProps(); if (treeProps == null) { return perfEvent;
if (context.isNestedTreeResolutionExperimentEnabled()) { if (node.getParent() != null) { context = node.getParent().getContext(); } else if (context.getLogger() != null) { context .getLogger() .emitMessage( ComponentsLogger.LogLevel.ERROR,
/** Set a key on the component that is local to its parent. */ public T key(@Nullable String key) { if (key == null) { final ComponentsLogger logger = mContext.getLogger(); if (logger != null) { final String componentName = mContext.getComponentScope() != null ? mContext.getComponentScope().getSimpleName() : "unknown component"; final String message = "Setting a null key from " + componentName + " which is usually a mistake! If it is not, explicitly set the String 'null'"; logger.emitMessage(ComponentsLogger.LogLevel.ERROR, message); } key = "null"; } mComponent.setKey(key); return getThis(); }
void init(ComponentContext context) { mContext = context; mId = sIdGenerator.getAndIncrement(); mStateHandler = mContext.getStateHandler(); mReferenceCount.set(1); mTestOutputs = ComponentsConfiguration.isEndToEndTestRun ? new ArrayList<TestOutput>(8) : null; mOrientation = context.getResources().getConfiguration().orientation; }