forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DefaultReactHost for Template (facebook#39585)
Summary: So that to enable Bridgeless in Template android we only need to override the ReactHostInterface variable in Template's application, see D49464580 Changelog: [Android][Changed] - Add DefaultReactHost Differential Revision: D49463901
- Loading branch information
1 parent
87d2ea9
commit 4c21655
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...s/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultReactHost.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.defaults | ||
|
||
import android.content.Context | ||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.bridge.JSBundleLoader | ||
import com.facebook.react.common.annotations.UnstableReactNativeAPI | ||
import com.facebook.react.fabric.ComponentFactory | ||
import com.facebook.react.interfaces.ReactHost | ||
import com.facebook.react.interfaces.exceptionmanager.ReactJsExceptionHandler | ||
import com.facebook.react.runtime.JSCInstance | ||
import com.facebook.react.runtime.ReactHostImpl | ||
import com.facebook.react.runtime.hermes.HermesInstance | ||
|
||
@UnstableReactNativeAPI | ||
class DefaultReactHost { | ||
companion object { | ||
private var reactHost: ReactHost? = null | ||
|
||
fun getDefaultReactHost( | ||
context: Context, | ||
jsMainModulePath: String, | ||
jsBundleAssetPath: String = "", | ||
packageList: List<ReactPackage>, | ||
isHermesEnabled: Boolean = true | ||
): ReactHost { | ||
if (reactHost == null) { | ||
val jsBundleLoader = | ||
JSBundleLoader.createAssetLoader(context, "assets://$jsBundleAssetPath", true) | ||
val jsEngineInstance = if (isHermesEnabled) HermesInstance() else JSCInstance() | ||
val defaultReactHostDelegate = | ||
DefaultReactHostDelegate( | ||
jsMainModulePath = jsMainModulePath, | ||
jsBundleLoader = jsBundleLoader, | ||
reactPackages = packageList, | ||
jsEngineInstance = jsEngineInstance, | ||
turboModuleManagerDelegateBuilder = DefaultTurboModuleManagerDelegate.Builder()) | ||
val reactJsExceptionHandler = ReactJsExceptionHandler { _ -> } | ||
val componentFactory = ComponentFactory() | ||
DefaultComponentsRegistry.register(componentFactory) | ||
// TODO: T164788699 find alternative of accessing ReactHostImpl for initialising reactHost | ||
reactHost = | ||
ReactHostImpl( | ||
context, | ||
defaultReactHostDelegate, | ||
componentFactory, | ||
true, | ||
reactJsExceptionHandler, | ||
true) | ||
} | ||
return reactHost as ReactHost | ||
} | ||
} | ||
} |