Skip to content

Commit

Permalink
Back out "Pulls mount related code into its own method"
Browse files Browse the repository at this point in the history
Summary:
Original commit changeset: 8607dd575d12

Original Phabricator Diff: D57967701

Differential Revision: D58823704

fbshipit-source-id: 4711eb917e3e0c475a32d8a1269dec6ccd01bc98
  • Loading branch information
khouzam authored and facebook-github-bot committed Jun 20, 2024
1 parent e3ce6a7 commit 0c7d5cc
Showing 1 changed file with 49 additions and 61 deletions.
110 changes: 49 additions & 61 deletions litho-core/src/main/java/com/facebook/litho/BaseMountingView.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,83 +452,71 @@ private void maybeMountOrNotifyVisibleBoundsChange(
return;
}

if (shouldPauseMountingWithVisibilityHintFalse()) {
return;
}

final Rect visibleRectToUse;
final boolean processVisibilityOutputs;
if (mTransientStateCount > 0 && hasTree() && 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 BaseMountingView was mounted when
// the transient state was set.
if (!isMountStateDirty()) {
return;
} else {
visibleRectToUse = new Rect(0, 0, getWidth(), getHeight());
processVisibilityOutputs = false;
}
} else {
visibleRectToUse = actualVisibleRect;
processVisibilityOutputs = requestVisibilityEvents;
}
final boolean isDirtyMount = isMountStateDirty();

if (visibleRectToUse == null) {
mPreviousMountVisibleRectBounds.setEmpty();
} else {
mPreviousMountVisibleRectBounds.set(visibleRectToUse);
}

final boolean needsMount = isMountStateDirty() || mountStateNeedsRemount();
if (visibleRectToUse != null && !needsMount) {
layoutState.setShouldProcessVisibilityOutputs(processVisibilityOutputs);
Preconditions.checkNotNull(mMountState.getMountDelegate())
.notifyVisibleBoundsChanged(visibleRectToUse);
} else {
mount(visibleRectToUse, processVisibilityOutputs);
// If this is the first mount, we need to set the hasMounted flag on the TreeState.
final TreeMountInfo mountInfo = getMountInfo();
if (mountInfo != null && !mountInfo.hasMounted) {
mountInfo.isFirstMount = true;
mountInfo.hasMounted = true;
}
}

private void mount(
final @Nullable Rect visibleRect, final boolean shouldProcessVisibilityEvents) {
mIsMounting = true;

final LayoutState layoutState = getCurrentLayoutState();
if (layoutState == null) {
return;
}
if (shouldPauseMountingWithVisibilityHintFalse()) {
return;
}

final boolean isMountStateDirty = isMountStateDirty();
try {

// If this is the first mount, we need to set the hasMounted flag on the TreeState.
final TreeMountInfo mountInfo = getMountInfo();
if (mountInfo != null && !mountInfo.hasMounted) {
mountInfo.isFirstMount = true;
mountInfo.hasMounted = true;
if (shouldPauseMountingWithVisibilityHintFalse()) {
return;
}

final Rect visibleRectToUse;
final boolean processVisibilityOutputs;
if (mTransientStateCount > 0 && hasTree() && 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 BaseMountingView was mounted when
// the transient state was set.
if (!isMountStateDirty()) {
return;
} else {
visibleRectToUse = new Rect(0, 0, getWidth(), getHeight());
processVisibilityOutputs = false;
}
} else {
visibleRectToUse = actualVisibleRect;
processVisibilityOutputs = requestVisibilityEvents;
}

mIsMounting = true;
if (visibleRectToUse == null) {
mPreviousMountVisibleRectBounds.setEmpty();
} else {
mPreviousMountVisibleRectBounds.set(visibleRectToUse);
}

Object onBeforeMountResult = onBeforeMount();

layoutState.setShouldProcessVisibilityOutputs(shouldProcessVisibilityEvents);
layoutState.setShouldProcessVisibilityOutputs(processVisibilityOutputs);

final RenderTree renderTree = layoutState.toRenderTree();
setupMountExtensions();
Preconditions.checkNotNull(mLithoHostListenerCoordinator);
mLithoHostListenerCoordinator.beforeMount(layoutState, visibleRect);
mMountState.mount(renderTree);
LithoStats.incrementComponentMountCount();
drawDebugOverlay(this, layoutState.getComponentTreeId());
final boolean needsMount = isMountStateDirty() || mountStateNeedsRemount();
if (visibleRectToUse != null && !needsMount) {
Preconditions.checkNotNull(mMountState.getMountDelegate())
.notifyVisibleBoundsChanged(visibleRectToUse);
} else {
// Generate the renderTree here so that any operations
// that occur in toRenderTree() happen prior to "beforeMount".
final RenderTree renderTree = layoutState.toRenderTree();
setupMountExtensions();
Preconditions.checkNotNull(mLithoHostListenerCoordinator);
mLithoHostListenerCoordinator.beforeMount(layoutState, visibleRectToUse);
mMountState.mount(renderTree);
LithoStats.incrementComponentMountCount();
drawDebugOverlay(this, layoutState.getComponentTreeId());
}

onAfterMount(onBeforeMountResult);
mIsMountStateDirty = false;

final TreeState treeState = getTreeState();
if (isMountStateDirty && treeState != null) {
if (isDirtyMount && treeState != null) {
treeState.recordRenderData(layoutState);
}
} catch (Exception e) {
Expand All @@ -538,7 +526,7 @@ private void mount(
getMountInfo().isFirstMount = false;
}
mIsMounting = false;
if (isMountStateDirty) {
if (isDirtyMount) {
onDirtyMountComplete();
}
}
Expand Down

0 comments on commit 0c7d5cc

Please sign in to comment.