forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultReactNativeHost.kt
71 lines (63 loc) · 2.29 KB
/
DefaultReactNativeHost.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* 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.app.Application
import com.facebook.react.JSEngineResolutionAlgorithm
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackageTurboModuleManagerDelegate
import com.facebook.react.bridge.JSIModulePackage
/**
* A utility class that allows you to simplify the setup of a [ReactNativeHost] for new apps in Open
* Source.
*
* Specifically, for apps that are using the New Architecture, this Default class takes care of
* providing the default TurboModuleManagerDelegateBuilder and the default JSIModulePackage,
* provided the name of the dynamic library to load.
*/
abstract class DefaultReactNativeHost
protected constructor(
application: Application,
) : ReactNativeHost(application) {
override fun getReactPackageTurboModuleManagerDelegateBuilder():
ReactPackageTurboModuleManagerDelegate.Builder? =
if (isNewArchEnabled) {
DefaultTurboModuleManagerDelegate.Builder()
} else {
null
}
override fun getJSIModulePackage(): JSIModulePackage? =
if (isNewArchEnabled) {
DefaultJSIModulePackage(this)
} else {
null
}
override fun getJSEngineResolutionAlgorithm(): JSEngineResolutionAlgorithm? =
when (isHermesEnabled) {
true -> JSEngineResolutionAlgorithm.HERMES
false -> JSEngineResolutionAlgorithm.JSC
null -> null
}
/**
* Returns whether the user wants to use the New Architecture or not.
*
* If true, we will load the default JSI Module Package and TurboModuleManagerDelegate needed to
* enable the New Architecture
*
* If false, the app will not attempt to load the New Architecture modules.
*/
protected open val isNewArchEnabled: Boolean
get() = false
/**
* Returns whether the user wants to use Hermes.
*
* If true, the app will load the Hermes engine, and fail if not found. If false, the app will
* load the JSC engine, and fail if not found. If null, the app will attempt to load JSC first and
* fallback to Hermes if not found.
*/
protected open val isHermesEnabled: Boolean?
get() = null
}