mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
avoid scheduling frame callback if there are no events (#41658)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/41658 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 fbshipit-source-id: ce2c7b77678bfc14aa7ecac71e40f78263c7036a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3a045b6026
commit
86c5abac2a
+17
-10
@@ -11,6 +11,7 @@ import android.view.Choreographer;
|
||||
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;
|
||||
@@ -84,7 +85,9 @@ public class FabricEventDispatcher implements EventDispatcher, LifecycleEventLis
|
||||
|
||||
@Override
|
||||
public void onHostResume() {
|
||||
maybePostFrameCallbackFromNonUI();
|
||||
if (!ReactFeatureFlags.enableOnDemandReactChoreographer) {
|
||||
maybePostFrameCallbackFromNonUI();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,17 +97,21 @@ public class FabricEventDispatcher implements EventDispatcher, LifecycleEventLis
|
||||
|
||||
@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() {
|
||||
@@ -133,7 +140,7 @@ public class FabricEventDispatcher implements EventDispatcher, LifecycleEventLis
|
||||
public void doFrame(long frameTimeNanos) {
|
||||
UiThreadUtil.assertOnUiThread();
|
||||
|
||||
if (mShouldStop) {
|
||||
if (ReactFeatureFlags.enableOnDemandReactChoreographer || mShouldStop) {
|
||||
mIsPosted = false;
|
||||
} else {
|
||||
post();
|
||||
|
||||
Reference in New Issue
Block a user