Skip to content

Commit

Permalink
Make default classes load their own so's
Browse files Browse the repository at this point in the history
Summary:
Make the DefaultTurboModuleManagerDelegate and the DefaultComponentRegistry load their own so's when they're created.

**Motivation:** We are going to use these two classes in Meta apps. And Meta apps will not invoke DefaultNewArchitectureEntryPoint.load.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D51036133
  • Loading branch information
RSNara authored and facebook-github-bot committed Nov 16, 2023
1 parent 46c8a51 commit 7186374
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ private constructor(componentFactory: ComponentFactory) {

@DoNotStrip private external fun initHybrid(componentFactory: ComponentFactory): HybridData

init {
DefaultSoLoader.maybeLoadSoLibrary()
}

companion object {
@JvmStatic
@DoNotStrip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.facebook.react.defaults

import com.facebook.react.config.ReactFeatureFlags
import com.facebook.soloader.SoLoader

/**
* A utility class that serves as an entry point for users setup the New Architecture.
Expand All @@ -27,8 +26,7 @@ object DefaultNewArchitectureEntryPoint {
fun load(
turboModulesEnabled: Boolean = true,
fabricEnabled: Boolean = true,
bridgelessEnabled: Boolean = false,
dynamicLibraryName: String = "appmodules",
bridgelessEnabled: Boolean = false
) {
ReactFeatureFlags.useTurboModules = turboModulesEnabled
ReactFeatureFlags.enableFabricRenderer = fabricEnabled
Expand All @@ -42,8 +40,7 @@ object DefaultNewArchitectureEntryPoint {
this.privateConcurrentReactEnabled = fabricEnabled
this.privateBridgelessEnabled = bridgelessEnabled

SoLoader.loadLibrary("react_newarchdefaults")
SoLoader.loadLibrary(dynamicLibraryName)
DefaultSoLoader.maybeLoadSoLibrary()
}

@Deprecated(
Expand All @@ -56,9 +53,8 @@ object DefaultNewArchitectureEntryPoint {
fabricEnabled: Boolean = true,
bridgelessEnabled: Boolean = false,
@Suppress("UNUSED_PARAMETER") concurrentReactEnabled: Boolean = true,
dynamicLibraryName: String = "appmodules",
) {
load(turboModulesEnabled, fabricEnabled, bridgelessEnabled, dynamicLibraryName)
load(turboModulesEnabled, fabricEnabled, bridgelessEnabled)
}

private var privateFabricEnabled: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 com.facebook.soloader.SoLoader
import com.facebook.soloader.SoLoaderDSONotFoundError

internal class DefaultSoLoader {
companion object {
@Synchronized
@JvmStatic
fun maybeLoadSoLibrary() {
SoLoader.loadLibrary("react_newarchdefaults")
try {
SoLoader.loadLibrary("appmodules")
} catch (e: SoLoaderDSONotFoundError) {
// ignore: DefaultTurboModuleManagerDelegate is still used in apps that don't have
// appmodules.so
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ private constructor(context: ReactApplicationContext, packages: List<ReactPackag
override fun build(context: ReactApplicationContext, packages: List<ReactPackage>) =
DefaultTurboModuleManagerDelegate(context, packages)
}

override fun maybeLoadOtherSoLibraries() {
DefaultSoLoader.maybeLoadSoLibrary()
}
}

0 comments on commit 7186374

Please sign in to comment.