mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
rn-android | Allow injecting a custom ChoreographerProvider via ReactNativeHost into construction of ReactInstanceManager.
Summary: Further propagating extension to the Android choreographer, now allowing to override it from the perspective of ReactNativeHost/ReactInstanceManager(Builder). Changelog: [Android][Added] ReactChoreographer can now use an implementation substitution instead of relying on android.view.Choreographer directly. Reviewed By: javache Differential Revision: D50827973 fbshipit-source-id: 42efaa3ece2c2b45fe4ee04a4bbc87c9d59132c8
This commit is contained in:
1 parent
751f7e97ba
commit
37e509f2b6
3 files changed
+28
-4
No files matched your search
+7
-2
@@ -88,6 +88,7 @@ import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
|
||||
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
|
||||
import com.facebook.react.internal.AndroidChoreographerProvider;
|
||||
import com.facebook.react.internal.ChoreographerProvider;
|
||||
import com.facebook.react.internal.turbomodule.core.TurboModuleManager;
|
||||
import com.facebook.react.internal.turbomodule.core.TurboModuleManagerDelegate;
|
||||
import com.facebook.react.modules.appearance.AppearanceModule;
|
||||
@@ -236,7 +237,8 @@ public class ReactInstanceManager {
|
||||
@Nullable Map<String, RequestHandler> customPackagerCommandHandlers,
|
||||
@Nullable ReactPackageTurboModuleManagerDelegate.Builder tmmDelegateBuilder,
|
||||
@Nullable SurfaceDelegateFactory surfaceDelegateFactory,
|
||||
@Nullable DevLoadingViewManager devLoadingViewManager) {
|
||||
@Nullable DevLoadingViewManager devLoadingViewManager,
|
||||
@Nullable ChoreographerProvider choreographerProvider) {
|
||||
FLog.d(TAG, "ReactInstanceManager.ctor()");
|
||||
initializeSoLoaderIfNecessary(applicationContext);
|
||||
|
||||
@@ -294,7 +296,10 @@ public class ReactInstanceManager {
|
||||
mJSIModulePackage = jsiModulePackage;
|
||||
|
||||
// Instantiate ReactChoreographer in UI thread.
|
||||
ReactChoreographer.initialize(AndroidChoreographerProvider.getInstance());
|
||||
ReactChoreographer.initialize(
|
||||
choreographerProvider != null
|
||||
? choreographerProvider
|
||||
: AndroidChoreographerProvider.getInstance());
|
||||
if (mUseDeveloperSupport) {
|
||||
mDevSupportManager.startInspector();
|
||||
}
|
||||
|
||||
+10
-1
@@ -32,6 +32,7 @@ import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
|
||||
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
|
||||
import com.facebook.react.internal.ChoreographerProvider;
|
||||
import com.facebook.react.jscexecutor.JSCExecutor;
|
||||
import com.facebook.react.jscexecutor.JSCExecutorFactory;
|
||||
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
||||
@@ -72,6 +73,7 @@ public class ReactInstanceManagerBuilder {
|
||||
private @Nullable SurfaceDelegateFactory mSurfaceDelegateFactory;
|
||||
private @Nullable DevLoadingViewManager mDevLoadingViewManager;
|
||||
private @Nullable JSEngineResolutionAlgorithm mJSEngineResolutionAlgorithm = null;
|
||||
private @Nullable ChoreographerProvider mChoreographerProvider = null;
|
||||
|
||||
/* package protected */ ReactInstanceManagerBuilder() {}
|
||||
|
||||
@@ -287,6 +289,12 @@ public class ReactInstanceManagerBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReactInstanceManagerBuilder setChoreographerProvider(
|
||||
@Nullable ChoreographerProvider choreographerProvider) {
|
||||
mChoreographerProvider = choreographerProvider;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new {@link ReactInstanceManager}. Before calling {@code build}, the following
|
||||
* must be called:
|
||||
@@ -350,7 +358,8 @@ public class ReactInstanceManagerBuilder {
|
||||
mCustomPackagerCommandHandlers,
|
||||
mTMMDelegateBuilder,
|
||||
mSurfaceDelegateFactory,
|
||||
mDevLoadingViewManager);
|
||||
mDevLoadingViewManager,
|
||||
mChoreographerProvider);
|
||||
}
|
||||
|
||||
private JavaScriptExecutorFactory getDefaultJSExecutorFactory(
|
||||
|
||||
+11
-1
@@ -21,6 +21,7 @@ import com.facebook.react.common.annotations.DeprecatedInNewArchitecture;
|
||||
import com.facebook.react.devsupport.DevSupportManagerFactory;
|
||||
import com.facebook.react.devsupport.interfaces.DevLoadingViewManager;
|
||||
import com.facebook.react.devsupport.interfaces.RedBoxHandler;
|
||||
import com.facebook.react.internal.ChoreographerProvider;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -87,7 +88,8 @@ public abstract class ReactNativeHost {
|
||||
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
|
||||
.setReactPackageTurboModuleManagerDelegateBuilder(
|
||||
getReactPackageTurboModuleManagerDelegateBuilder())
|
||||
.setJSEngineResolutionAlgorithm(getJSEngineResolutionAlgorithm());
|
||||
.setJSEngineResolutionAlgorithm(getJSEngineResolutionAlgorithm())
|
||||
.setChoreographerProvider(getChoreographerProvider());
|
||||
|
||||
for (ReactPackage reactPackage : getPackages()) {
|
||||
builder.addPackage(reactPackage);
|
||||
@@ -213,4 +215,12 @@ public abstract class ReactNativeHost {
|
||||
protected @Nullable JSEngineResolutionAlgorithm getJSEngineResolutionAlgorithm() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a custom implementation of ChoreographerProvider to be used this host. If null - React
|
||||
* will use default direct android.view.Choreographer-based provider.
|
||||
*/
|
||||
protected @Nullable ChoreographerProvider getChoreographerProvider() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user