Skip to content

Commit

Permalink
avoid scheduling frame callback if there are no events
Browse files Browse the repository at this point in the history
Summary:
changelog: [internal]

FabricEventDispatcher does not need to run on every frame. Whenever a new event is added to Fabric's event queue, it will call `FabricUIManager.onRequestEventBeat` in Java. This in turn calls `FabricEventDispatcher.maybePostFrameCallbackFromNonUI` and adds a frame callback on the Choreographer.

This makes code simpler, as we do not need to manage the frame callback subscription.

Reviewed By: sammy-SC

Differential Revision: D50604303
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Nov 27, 2023
1 parent 8344474 commit 2f80479
Showing 1 changed file with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.systrace.Systrace;
Expand Down Expand Up @@ -84,7 +85,9 @@ public void removeBatchEventDispatchedListener(BatchEventDispatchedListener list

@Override
public void onHostResume() {
maybePostFrameCallbackFromNonUI();
if (!ReactFeatureFlags.enableOnDemandReactChoreographer) {
maybePostFrameCallbackFromNonUI();
}
}

@Override
Expand All @@ -94,17 +97,21 @@ public void onHostPause() {

@Override
public void onHostDestroy() {
stopFrameCallback();
if (!ReactFeatureFlags.enableOnDemandReactChoreographer) {
stopFrameCallback();
}
}

public void onCatalystInstanceDestroyed() {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
stopFrameCallback();
}
});
if (!ReactFeatureFlags.enableOnDemandReactChoreographer) {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
stopFrameCallback();
}
});
}
}

private void stopFrameCallback() {
Expand Down Expand Up @@ -133,7 +140,7 @@ private class ScheduleDispatchFrameCallback implements Choreographer.FrameCallba
public void doFrame(long frameTimeNanos) {
UiThreadUtil.assertOnUiThread();

if (mShouldStop) {
if (ReactFeatureFlags.enableOnDemandReactChoreographer || mShouldStop) {
mIsPosted = false;
} else {
post();
Expand Down

0 comments on commit 2f80479

Please sign in to comment.