public boolean isIncrementalMountEnabled() { return (mComponentTree != null && mComponentTree.isIncrementalMountEnabled()); }
/** * Checks if incremental mount is enabled given a ComponentContext, so you can throw an error if * you require that incremental mount is enabled (e.g. you use visibility callbacks). This is * static to avoid polluting the ComponentContext API. */ public static boolean isIncrementalMountEnabled(ComponentContext c) { return c.getComponentTree().isIncrementalMountEnabled(); }
public void performIncrementalMount(Rect visibleRect, boolean processVisibilityOutputs) { if (mComponentTree == null || !checkMainThreadLayoutStateForIncrementalMount()) { return; } if (mComponentTree.isIncrementalMountEnabled()) { mComponentTree.mountComponent(visibleRect, processVisibilityOutputs); } else { throw new IllegalStateException("To perform incremental mounting, you need first to enable" + " it when creating the ComponentTree."); } }
public void performIncrementalMount() { if (mComponentTree == null || mComponentTree.getMainThreadLayoutState() == null) { return; } if (mComponentTree.isIncrementalMountEnabled()) { mComponentTree.incrementalMountComponent(); } else { throw new IllegalStateException("To perform incremental mounting, you need first to enable" + " it when creating the ComponentTree."); } }
void onAttach(LithoView lithoView) { if (!mComponentTree.isIncrementalMountEnabled()) { return;
private static void assertDefaults(ComponentTree componentTree) { assertEqualToInternalState(componentTree, true, "mIsLayoutDiffingEnabled"); assertThat(componentTree.isIncrementalMountEnabled()).isTrue(); } }
@Override public void setHasTransientState(boolean hasTransientState) { if (hasTransientState) { if (mTransientStateCount == 0 && mComponentTree != null && mComponentTree.isIncrementalMountEnabled()) { final Rect rect = ComponentsPools.acquireRect(); rect.set(0, 0, getWidth(), getHeight()); performIncrementalMount(rect, false); ComponentsPools.release(rect); } mTransientStateCount++; } else { mTransientStateCount--; if (mTransientStateCount == 0 && mComponentTree != null && mComponentTree.isIncrementalMountEnabled()) { // We mounted everything when the transient state was set on this view. We need to do this // partly to unmount content that is not visible but mostly to get the correct visibility // events to be fired. performIncrementalMount(); } if (mTransientStateCount < 0) { mTransientStateCount = 0; } } super.setHasTransientState(hasTransientState); }
void mount(LayoutState layoutState, Rect currentVisibleArea, boolean processVisibilityOutputs) { boolean rectNeedsRelease = false; if (mTransientStateCount > 0 && mComponentTree != null && mComponentTree.isIncrementalMountEnabled()) { // If transient state is set but the MountState is dirty we want to re-mount everything. // Otherwise, we don't need to do anything as the entire LithoView was mounted when the // transient state was set. if (!mMountState.isDirty()) { return; } else { currentVisibleArea = ComponentsPools.acquireRect(); currentVisibleArea.set(0, 0, getWidth(), getHeight()); rectNeedsRelease = true; processVisibilityOutputs = false; } } if (currentVisibleArea == null) { mPreviousMountVisibleRectBounds.setEmpty(); } else { mPreviousMountVisibleRectBounds.set(currentVisibleArea); } mMountState.mount(layoutState, currentVisibleArea, processVisibilityOutputs); if (rectNeedsRelease) { ComponentsPools.release(currentVisibleArea); } }
/** * Call this to tell the LithoView whether it is visible or not. In general, you shouldn't require * this as the system will do this for you. However, when a new activity/fragment is added on top * of the one hosting this view, the LithoView remains in the backstack but receives no callback * to indicate that it is no longer visible. * * @param isVisible if true, this will find the current visible rect and process visibility * outputs using it. If false, any invisible and unfocused events will be called. */ public void setVisibilityHint(boolean isVisible) { assertMainThread(); if (mComponentTree == null || !mComponentTree.isIncrementalMountEnabled()) { return; } if (isVisible) { final Rect currentVisibleArea = ComponentsPools.acquireRect(); if (getLocalVisibleRect(currentVisibleArea)) { mComponentTree.processVisibilityOutputs(); } // if false: no-op, doesn't have visible area, is not ready or not attached ComponentsPools.release(currentVisibleArea); } else { mMountState.clearVisibilityItems(); } }
private void maybePerformIncrementalMountOnView() { if (mComponentTree == null || !mComponentTree.isIncrementalMountEnabled() || !(getParent() instanceof View)) { return;
@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()); }