Skip to content

Commit

Permalink
Enable Template with Bridgeless
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[Android][Changed] - Enable Template with Bridgeless

Differential Revision: D49464580
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Sep 26, 2023
1 parent 35a6630 commit c5fbbb4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ import com.facebook.react.modules.network.NetworkingModule
object ReactNativeFlipper {
@JvmStatic
fun initializeFlipper(context: Context, reactInstanceManager: ReactInstanceManager) {
initializeFlipper(context, reactInstanceManager, false)
}

@JvmStatic
fun initializeFlipper(
context: Context,
reactInstanceManager: ReactInstanceManager,
bridgelessEnabled: Boolean
) {
if (bridgelessEnabled) {
return
}
if (FlipperUtils.shouldEnableFlipper(context)) {
val client = AndroidFlipperClient.getInstance(context)
client.addPlugin(InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.common.annotations.UnstableReactNativeAPI
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.bridgelessEnabled
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper
import com.facebook.react.interfaces.ReactHost
import com.facebook.soloader.SoLoader

@UnstableReactNativeAPI
class MainApplication : Application(), ReactApplication {

override val reactNativeHost: ReactNativeHost =
Expand All @@ -28,13 +33,26 @@ class MainApplication : Application(), ReactApplication {
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}

override val reactHost: ReactHost
get() =
DefaultReactHost.getDefaultReactHost(
context = this,
packageList = PackageList(this).packages,
jsMainModulePath = "index",
isHermesEnabled = BuildConfig.IS_HERMES_ENABLED)

override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
/**
* If you opted-in for the New Architecture, we load the native entry point for this app.
*
* To enable Bridgeless you need to override "bridgelessEnabled" to true.
*/
load()
}
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
ReactNativeFlipper.initializeFlipper(
this, reactNativeHost.reactInstanceManager, bridgelessEnabled)
}
}

0 comments on commit c5fbbb4

Please sign in to comment.