private void onDetach() { if (mIsAttached) { mIsAttached = false; mMountState.detach(); if (mComponentTree != null) { mComponentTree.detach(); } AccessibilityManagerCompat.removeAccessibilityStateChangeListener( mAccessibilityManager, mAccessibilityStateChangeListener); mSuppressMeasureComponentTree = false; } }
/** * Set a new LithoView to this ComponentTree checking that they have the same context and * clear the ComponentTree reference from the previous LithoView if any. * Be sure this ComponentTree is detach first. */ void setLithoView(@NonNull LithoView view) { assertMainThread(); // It's possible that the view associated with this ComponentTree was recycled but was // never detached. In all cases we have to make sure that the old references between // lithoView and componentTree are reset. if (mIsAttached) { if (mLithoView != null) { mLithoView.setComponentTree(null); } else { detach(); } } else if (mLithoView != null) { // Remove the ComponentTree reference from a previous view if any. mLithoView.clearComponentTree(); } if (!hasSameRootContext(view.getContext(), mContext.getAndroidContext())) { // This would indicate bad things happening, like leaking a context. throw new IllegalArgumentException( "Base view context differs, view context is: " + view.getContext() + ", ComponentTree context is: " + mContext); } mLithoView = view; }
assertThat(mMountedRect).isEqualTo(new Rect(10, 5, 20, 15)); mComponentTree.detach();
mComponentTree.detach();