-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): initialize SoLoader with merged libraries on 0.76 (#2223)
- Loading branch information
Showing
3 changed files
with
79 additions
and
5 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
69 changes: 69 additions & 0 deletions
69
android/app/src/reactapplication-0.76/java/com/microsoft/reacttestapp/TestApp.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,69 @@ | ||
package com.microsoft.reacttestapp | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.content.Context | ||
import com.facebook.react.PackageList | ||
import com.facebook.react.ReactApplication | ||
import com.facebook.react.ReactHost | ||
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost | ||
import com.facebook.react.soloader.OpenSourceMergedSoMapping | ||
import com.facebook.soloader.SoLoader | ||
import com.microsoft.reacttestapp.manifest.Manifest | ||
import com.microsoft.reacttestapp.manifest.ManifestProvider | ||
import com.microsoft.reacttestapp.react.ReactBundleNameProvider | ||
import com.microsoft.reacttestapp.react.TestAppReactNativeHost | ||
import com.microsoft.reacttestapp.support.ReactTestAppLifecycleEvents | ||
|
||
class TestApp : | ||
Application(), | ||
ReactApplication { | ||
|
||
val bundleNameProvider: ReactBundleNameProvider | ||
get() = reactNativeBundleNameProvider | ||
|
||
val manifest: Manifest by lazy { | ||
ManifestProvider.manifest() | ||
} | ||
|
||
override val reactHost: ReactHost | ||
get() = getDefaultReactHost(this.applicationContext, reactNativeHost) | ||
|
||
override val reactNativeHost: TestAppReactNativeHost | ||
get() = reactNativeHostInternal | ||
|
||
private lateinit var reactNativeBundleNameProvider: ReactBundleNameProvider | ||
private lateinit var reactNativeHostInternal: TestAppReactNativeHost | ||
|
||
fun reloadJSFromServer(activity: Activity, bundleURL: String) { | ||
reactNativeHostInternal.reloadJSFromServer(activity, bundleURL) | ||
} | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
SoLoader.init(this, OpenSourceMergedSoMapping) | ||
|
||
reactNativeBundleNameProvider = ReactBundleNameProvider(this, manifest.bundleRoot) | ||
reactNativeHostInternal = | ||
TestAppReactNativeHost(this, reactNativeBundleNameProvider) | ||
|
||
val eventConsumers = PackageList(this).packages | ||
.filter { it is ReactTestAppLifecycleEvents } | ||
.map { it as ReactTestAppLifecycleEvents } | ||
|
||
eventConsumers.forEach { it.onTestAppInitialized() } | ||
|
||
reactNativeHostInternal.init( | ||
beforeReactNativeInit = { | ||
eventConsumers.forEach { it.onTestAppWillInitializeReactNative() } | ||
}, | ||
afterReactNativeInit = { | ||
eventConsumers.forEach { it.onTestAppDidInitializeReactNative() } | ||
} | ||
) | ||
} | ||
} | ||
|
||
val Context.testApp: TestApp | ||
get() = applicationContext as TestApp |
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