-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): use default app setup for New Arch (#1774)
Fixes a crash on startup and reduces our footprint.
- Loading branch information
Showing
10 changed files
with
41 additions
and
196 deletions.
There are no files selected for viewing
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
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
44 changes: 0 additions & 44 deletions
44
...oid/app/src/new-arch-0.74/java/com/microsoft/reacttestapp/compat/ReactNativeHostCompat.kt
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
android/app/src/new-arch-0.74/java/com/microsoft/reacttestapp/fabric/ComponentsRegistry.kt
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
...c/new-arch-0.74/java/com/microsoft/reacttestapp/turbomodule/TurboModuleManagerDelegate.kt
This file was deleted.
Oops, something went wrong.
81 changes: 22 additions & 59 deletions
81
android/app/src/new-arch/java/com/microsoft/reacttestapp/compat/ReactNativeHostCompat.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 |
---|---|---|
@@ -1,68 +1,31 @@ | ||
package com.microsoft.reacttestapp.compat | ||
|
||
import android.app.Application | ||
import com.facebook.react.ReactInstanceManager | ||
import com.facebook.react.ReactNativeHost | ||
import com.facebook.react.bridge.JSIModulePackage | ||
import com.facebook.react.bridge.JSIModuleProvider | ||
import com.facebook.react.bridge.JSIModuleSpec | ||
import com.facebook.react.bridge.JSIModuleType | ||
import com.facebook.react.bridge.JavaScriptContextHolder | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.UIManager | ||
import com.facebook.react.fabric.ComponentFactory | ||
import com.facebook.react.fabric.CoreComponentsRegistry | ||
import com.facebook.react.fabric.EmptyReactNativeConfig | ||
import com.facebook.react.fabric.FabricJSIModuleProvider | ||
import com.facebook.react.uimanager.ViewManagerRegistry | ||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint | ||
import com.facebook.react.defaults.DefaultReactNativeHost | ||
import com.facebook.soloader.SoLoader | ||
import com.microsoft.reacttestapp.BuildConfig | ||
import com.microsoft.reacttestapp.fabric.ComponentsRegistry | ||
import com.microsoft.reacttestapp.turbomodule.TurboModuleManagerDelegate | ||
import java.lang.ref.WeakReference | ||
|
||
abstract class ReactNativeHostCompat(application: Application) : ReactNativeHost(application) { | ||
override fun getReactPackageTurboModuleManagerDelegateBuilder() = | ||
TurboModuleManagerDelegate.Builder() | ||
|
||
override fun getJSIModulePackage(): JSIModulePackage? { | ||
return if (BuildConfig.ReactTestApp_useFabric) { | ||
object : JSIModulePackage { | ||
|
||
private val reactInstanceManager: ReactInstanceManager? | ||
get() = reactNativeHost.get()?.reactInstanceManager | ||
|
||
private val reactNativeHost: WeakReference<ReactNativeHost> = | ||
WeakReference(this@ReactNativeHostCompat) | ||
|
||
override fun getJSIModules( | ||
reactApplicationContext: ReactApplicationContext, | ||
jsContext: JavaScriptContextHolder? | ||
): ArrayList<JSIModuleSpec<*>> { | ||
return arrayListOf(object : JSIModuleSpec<UIManager?> { | ||
override fun getJSIModuleType(): JSIModuleType = JSIModuleType.UIManager | ||
|
||
override fun getJSIModuleProvider(): JSIModuleProvider<UIManager?> { | ||
val componentFactory = ComponentFactory() | ||
CoreComponentsRegistry.register(componentFactory) | ||
|
||
ComponentsRegistry.register(componentFactory) | ||
|
||
return FabricJSIModuleProvider( | ||
reactApplicationContext, | ||
componentFactory, | ||
EmptyReactNativeConfig(), | ||
ViewManagerRegistry( | ||
reactInstanceManager?.getOrCreateViewManagers( | ||
reactApplicationContext | ||
) | ||
) | ||
) | ||
} | ||
}) | ||
} | ||
abstract class ReactNativeHostCompat(application: Application) : DefaultReactNativeHost( | ||
application | ||
) { | ||
companion object { | ||
init { | ||
try { | ||
DefaultNewArchitectureEntryPoint.load( | ||
/* turboModulesEnabled */ | ||
BuildConfig.ReactTestApp_useFabric, | ||
/* fabricEnabled */ | ||
BuildConfig.ReactTestApp_useFabric | ||
) | ||
} catch (e: UnsatisfiedLinkError) { | ||
// Older versions of `DefaultNewArchitectureEntryPoint` is | ||
// hard coded to load `libappmodules.so` | ||
} | ||
} else { | ||
null | ||
SoLoader.loadLibrary("reacttestapp_appmodules") | ||
} | ||
} | ||
|
||
override val isNewArchEnabled: Boolean = BuildConfig.ReactTestApp_useFabric | ||
override val isHermesEnabled: Boolean? = true | ||
} |
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
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
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
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