Skip to content

Commit

Permalink
Add events for Incremental Mount Start/End.
Browse files Browse the repository at this point in the history
Summary: Adding support for events for Incremental Mount Start/End so we can visualize the mount related events that happen in a IM pass.

Reviewed By: LukeDefeo

Differential Revision: D51805156

fbshipit-source-id: fbfb93d3a40d09fa6cfbc6b10dcad781aac08af2
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Dec 5, 2023
1 parent c122a97 commit 8ab3077
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions litho-core/src/main/java/com/facebook/litho/BaseMountingView.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import com.facebook.rendercore.RenderCoreExtensionHost;
import com.facebook.rendercore.RenderTree;
import com.facebook.rendercore.RenderTreeUpdateListener;
import com.facebook.rendercore.debug.DebugEvent;
import com.facebook.rendercore.debug.DebugEventAttribute;
import com.facebook.rendercore.debug.DebugEventDispatcher;
import com.facebook.rendercore.extensions.RenderCoreExtension;
import com.facebook.rendercore.transitions.AnimatedRootHost;
import com.facebook.rendercore.visibility.VisibilityOutput;
Expand All @@ -48,6 +51,7 @@
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import kotlin.Unit;

public abstract class BaseMountingView extends ComponentHost
implements RenderCoreExtensionHost, AnimatedRootHost {
Expand Down Expand Up @@ -691,6 +695,7 @@ public void setSkipMountingIfNotVisible(boolean skipMountingIfNotVisible) {
@UiThread
void performIncrementalMountForVisibleBoundsChange() {
assertMainThread();

if (!hasTree()) {
return;
}
Expand All @@ -700,6 +705,15 @@ void performIncrementalMountForVisibleBoundsChange() {
final Rect currentVisibleArea = new Rect();
final boolean areBoundsVisible = getLocalVisibleRect(currentVisibleArea);

DebugEventDispatcher.dispatch(
DebugEvent.IncrementalMountStart,
() -> String.valueOf(mMountState.getRenderStateId()),
attrs -> {
attrs.put(DebugEventAttribute.VisibleRect, currentVisibleArea);
attrs.put(DebugEventAttribute.BoundsVisible, areBoundsVisible);
return Unit.INSTANCE;
});

if (areBoundsVisible
|| hasComponentsExcludedFromIncrementalMount(getCurrentLayoutState())
// It might not be yet visible but animating from 0 height/width in which case we still
Expand All @@ -708,6 +722,11 @@ void performIncrementalMountForVisibleBoundsChange() {
|| hasBecomeInvisible()) {
mountComponent(currentVisibleArea, true);
}

DebugEventDispatcher.dispatch(
DebugEvent.IncrementalMountEnd,
() -> String.valueOf(mMountState.getRenderStateId()),
attrs -> Unit.INSTANCE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ sealed class DebugEvent(
const val RenderUnitOnVisible = "RenderCore.RenderUnit.OnVisible"
const val RenderUnitOnInvisible = "RenderCore.RenderUnit.OnInvisible"
const val ViewOnLayout = "RenderCore.View.OnLayout"
const val IncrementalMountStart = "RenderCore.IncrementalMount.Start"
const val IncrementalMountEnd = "RenderCore.IncrementalMount.End"
}

/** Returns the value of attribute with [name]. */
Expand Down Expand Up @@ -93,6 +95,8 @@ object DebugEventAttribute {
const val RootHostHashCode = "rootHostHashCode"
const val Name = "name"
const val Key = "key"
const val VisibleRect = "visibleRect"
const val BoundsVisible = "areBoundsVisible"
}

/** Base class for marker events */
Expand Down

0 comments on commit 8ab3077

Please sign in to comment.