In this article, we sorted out the startup process of First, let's look at where mReactRootView.startReactApplication( getReactNativeHost().getReactInstanceManager(), appKey, mLaunchOptions); You can see that Follow
1. Create a final ReactContextInitParams initParams = new ReactContextInitParams(jsExecutorFactory, jsBundleLoader); 2. Call
createReactContextFirst look at where it is called: final ReactApplicationContext reactApplicationContext = createReactContext( initParams.getJsExecutorFactory().create(), initParams.getJsBundleLoader()); Its two input parameters are JavaScriptExecutor The first input parameter Looking back at the React Native startup process, the following method is actually called during the creation process: ReactInstanceManager reactInstanceManager = builder.build() private JavaScriptExecutorFactory getDefaultJSExecutorFactory( String appName, String deviceName, Context applicationContext) { try { // If JSC is included, use it as normal initializeSoLoaderIfNecessary(applicationContext); SoLoader.loadLibrary("jscexecutor"); return new JSCExecutorFactory(appName, deviceName); } catch (UnsatisfiedLinkError jscE) { /* ... */ } } That is to say, when we create @Override public JavaScriptExecutor create() throws Exception { WritableNativeMap jscConfig = new WritableNativeMap(); jscConfig.putString("OwnerIdentity", "ReactNative"); jscConfig.putString("AppIdentity", mAppName); jscConfig.putString("DeviceIdentity", mDeviceName); return new JSCExecutor(jscConfig); } Looking down at the definition of @DoNotStrip /* package */ class JSCExecutor extends JavaScriptExecutor { static { SoLoader.loadLibrary("jscexecutor"); } /* package */ JSCExecutor(ReadableNativeMap jscConfig) { super(initHybrid(jscConfig)); } @Override public String getName() { return "JSCExecutor"; } private static native HybridData initHybrid(ReadableNativeMap jscConfig); } So it is clear that the first parameter of JsBundleLoader Similarly, in Coming to its definition, I found that it returns a public static JSBundleLoader createAssetLoader( final Context context, final String assetUrl, final boolean loadSynchronously) { return new JSBundleLoader() { @Override public String loadScript(JSBundleLoaderDelegate delegate) { delegate.loadScriptFromAssets(context.getAssets(), assetUrl, loadSynchronously); return assetUrl; } }; } After creating the createReactContextprivate ReactApplicationContext createReactContext( final ReactApplicationContext reactContext = new ReactApplicationContext(mApplicationContext); CatalystInstanceImpl.Builder catalystInstanceBuilder = /* ... */ try { catalystInstance = catalystInstanceBuilder.build(); } finally { /* ... */ } reactContext.initializeWithInstance(catalystInstance); TurboModuleManager turboModuleManager = new TurboModuleManager( /* ... */ ) catalystInstance.setTurboModuleManager(turboModuleManager); if (mJSIModulePackage != null) { catalystInstance.addJSIModules( /* ... */ ); } catalystInstance.runJSBundle(); return reactContext; In it, initializeWithInstance By calling runJSBundlepublic void runJSBundle() { mJSBundleLoader.loadScript(CatalystInstanceImpl.this); synchronized (mJSCallsPendingInitLock) { mAcceptCalls = true; for (PendingJSCall function : mJSCallsPendingInit) { function.call(this); } mJSCallsPendingInit.clear(); mJSBundleHasLoaded = true; } Systrace.registerListener(mTraceListener); } Execute its public String loadScript(JSBundleLoaderDelegate delegate) { delegate.loadScriptFromAssets(context.getAssets(), assetUrl, loadSynchronously); return assetUrl; } public void loadScriptFromAssets( AssetManager assetManager, String assetURL, boolean loadSynchronously) { mSourceURL = assetURL; jniLoadScriptFromAssets(assetManager, assetURL, loadSynchronously); } The setupReactContextprivate void setupReactContext(final ReactApplicationContext reactContext) { synchronized (mAttachedReactRoots) { catalystInstance.initialize(); for (ReactRoot reactRoot : mAttachedReactRoots) { if (reactRoot.getState().compareAndSet(ReactRoot.STATE_STOPPED, ReactRoot.STATE_STARTED)) { attachRootViewToInstance(reactRoot); } } } UiThreadUtil.runOnUiThread( public void run() { listener.onReactContextInitialized(reactContext); } ) reactContext.runOnJSQueueThread( public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); } ) reactContext.runOnNativeModulesQueueThread( public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT); } ) } Here’s what’s happening here:
Summary of this articleStarting from the source code of the createReactContext and setupReactContext methods, the execution process of the RN startReactApplication method is analyzed, including: The main function of createReactContext is to create The main function of setupReactContext is to initialize all native modules, draw all rootviews, create UI module, JS module and native module threads, and set priorities. This is the end of this article about the React Native startReactApplication method. For more related React Native startReactApplication content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Analysis of Alibaba Cloud CentOS7 server nginx configuration and FAQs
>>: Summary of basic knowledge points of MySql database
What we are simulating now is a master-slave syst...
1. Docker installation and startup yum install ep...
What is wxs? wxs (WeiXin Script) is a scripting l...
Install Ubuntu 20.04 Install NVIDIA drivers Confi...
Yes, CSS has regular expressions too (Amen) Two p...
Newbie, record it yourself 1. Install supervisor....
Table of contents status quo Solution Further sol...
Table of contents 1. Overview 1. Introduction to ...
Share a real-time clock effect implemented with n...
1. Create a new object using the Object.create() ...
Table of contents 1. Spark vs. Hadoop 1.1 Disadva...
This article mainly focuses on the installation a...
1, %: represents any 0 or more characters. It can...
Generally speaking, it is unlikely that you will ...
1. Overview Zabbix is a very powerful and most ...