Skip to content

Commit d4d111a

Browse files
committed
refactor, change namings and getter functions
1 parent a4f12a2 commit d4d111a

File tree

1 file changed

+76
-85
lines changed

1 file changed

+76
-85
lines changed

packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt

Lines changed: 76 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -37,87 +37,86 @@ import com.facebook.react.uimanager.ViewManager
3737
import com.facebook.soloader.SoLoader
3838

3939
class RNTesterApplication : Application(), ReactApplication {
40-
private var mReactHost: ReactHostImpl? = null
41-
private val mReactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) {
42-
public override fun getJSMainModuleName(): String {
43-
return "js/RNTesterApp.android"
40+
private var reactHost: ReactHostImpl? = null
41+
override val reactNativeHost: ReactNativeHost
42+
get() {
43+
if (ReactFeatureFlags.enableBridgelessArchitecture) {
44+
throw RuntimeException("Should not use ReactNativeHost when Bridgeless enabled")
4445
}
46+
return object : DefaultReactNativeHost(this) {
47+
public override fun getJSMainModuleName(): String = "js/RNTesterApp.android"
4548

46-
public override fun getBundleAssetName(): String? {
47-
return "RNTesterApp.android.bundle"
48-
}
49+
public override fun getBundleAssetName(): String = "RNTesterApp.android.bundle"
4950

50-
override fun getUseDeveloperSupport(): Boolean {
51-
return BuildConfig.DEBUG
52-
}
51+
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
5352

54-
public override fun getPackages(): List<ReactPackage> {
53+
public override fun getPackages(): List<ReactPackage> {
5554
return listOf(
56-
MainReactPackage(),
57-
object : TurboReactPackage() {
58-
override fun getModule(
59-
name: String, reactContext: ReactApplicationContext): NativeModule? {
60-
if (!ReactFeatureFlags.useTurboModules) {
61-
return null
62-
}
63-
if (SampleTurboModule.NAME == name) {
64-
return SampleTurboModule(reactContext)
65-
}
66-
if (SampleLegacyModule.NAME == name) {
67-
return SampleLegacyModule(reactContext)
68-
}
69-
return null;
70-
}
55+
MainReactPackage(),
56+
object : TurboReactPackage() {
57+
override fun getModule(
58+
name: String, reactContext: ReactApplicationContext): NativeModule? {
59+
if (!ReactFeatureFlags.useTurboModules) {
60+
return null
61+
}
62+
if (SampleTurboModule.NAME == name) {
63+
return SampleTurboModule(reactContext)
64+
}
65+
if (SampleLegacyModule.NAME == name) {
66+
return SampleLegacyModule(reactContext)
67+
}
68+
return null;
69+
}
70+
71+
// Note: Specialized annotation processor for @ReactModule isn't configured in OSS
72+
// yet. For now, hardcode this information, though it's not necessary for most
73+
// modules.
74+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider {
75+
if (ReactFeatureFlags.useTurboModules) {
76+
mapOf(
77+
SampleTurboModule.NAME to
78+
ReactModuleInfo(
79+
SampleTurboModule.NAME,
80+
"SampleTurboModule",
81+
false, // canOverrideExistingModule
82+
false, // needsEagerInit
83+
false, // isCxxModule
84+
true // isTurboModule
85+
),
86+
SampleLegacyModule.NAME to
87+
ReactModuleInfo(
88+
SampleLegacyModule.NAME,
89+
"SampleLegacyModule",
90+
false, // canOverrideExistingModule
91+
false, // needsEagerInit
92+
false, // isCxxModule
93+
false // isTurboModule
94+
)
95+
)
96+
} else {
97+
emptyMap()
98+
}
99+
}
71100

72-
// Note: Specialized annotation processor for @ReactModule isn't configured in OSS
73-
// yet. For now, hardcode this information, though it's not necessary for most
74-
// modules.
75-
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider {
76-
if (ReactFeatureFlags.useTurboModules) {
77-
mapOf(
78-
SampleTurboModule.NAME to
79-
ReactModuleInfo(
80-
SampleTurboModule.NAME,
81-
"SampleTurboModule",
82-
false, // canOverrideExistingModule
83-
false, // needsEagerInit
84-
false, // isCxxModule
85-
true // isTurboModule
86-
),
87-
SampleLegacyModule.NAME to
88-
ReactModuleInfo(
89-
SampleLegacyModule.NAME,
90-
"SampleLegacyModule",
91-
false, // canOverrideExistingModule
92-
false, // needsEagerInit
93-
false, // isCxxModule
94-
false // isTurboModule
95-
)
96-
)
97-
} else {
98-
emptyMap()
99-
}
100-
}
101+
},
102+
object : ReactPackage {
103+
override fun createNativeModules(
104+
reactContext: ReactApplicationContext): List<NativeModule> {
105+
return emptyList()
106+
}
101107

102-
},
103-
object : ReactPackage {
104-
override fun createNativeModules(
105-
reactContext: ReactApplicationContext): List<NativeModule> {
106-
return emptyList()
107-
}
108+
override fun createViewManagers(
109+
reactContext: ReactApplicationContext
110+
): List<ViewManager<*, *>> =
111+
listOf(MyNativeViewManager(), MyLegacyViewManager(reactContext));
112+
})
113+
}
108114

109-
override fun createViewManagers(
110-
reactContext: ReactApplicationContext
111-
): List<ViewManager<*, *>> =
112-
listOf(MyNativeViewManager(), MyLegacyViewManager(reactContext));
113-
})
115+
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
116+
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED_IN_FLAVOR
114117
}
118+
}
115119

116-
override val isNewArchEnabled: Boolean
117-
protected get() = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
118-
override val isHermesEnabled: Boolean
119-
protected get() = BuildConfig.IS_HERMES_ENABLED_IN_FLAVOR
120-
}
121120

122121
override fun onCreate() {
123122
ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik)
@@ -133,39 +132,31 @@ class RNTesterApplication : Application(), ReactApplication {
133132
}
134133
}
135134

136-
override val reactNativeHost: ReactNativeHost
137-
get() {
138-
if (ReactFeatureFlags.enableBridgelessArchitecture) {
139-
throw RuntimeException("Should not use ReactNativeHost when Bridgeless enabled")
140-
}
141-
return mReactNativeHost
142-
}
143-
144135
@UnstableReactNativeAPI
145136
override val reactHostInterface: ReactHost
146137
get() {
147-
if (mReactHost == null) {
138+
if (reactHost == null) {
148139
// Create an instance of ReactHost to manager the instance of ReactInstance,
149140
// which is similar to how we use ReactNativeHost to manager instance of ReactInstanceManager
150141
val reactHostDelegate = RNTesterReactHostDelegate(applicationContext)
151142
val reactJsExceptionHandler = RNTesterReactJsExceptionHandler()
152143
val componentFactory = ComponentFactory()
153144
register(componentFactory)
154-
mReactHost = ReactHostImpl(
145+
reactHost = ReactHostImpl(
155146
this.applicationContext,
156147
reactHostDelegate,
157148
componentFactory,
158149
true,
159150
reactJsExceptionHandler,
160151
true)
161152
if (BuildConfig.IS_HERMES_ENABLED_IN_FLAVOR) {
162-
mReactHost!!.jsEngineResolutionAlgorithm = JSEngineResolutionAlgorithm.HERMES
153+
reactHost!!.jsEngineResolutionAlgorithm = JSEngineResolutionAlgorithm.HERMES
163154
} else {
164-
mReactHost!!.jsEngineResolutionAlgorithm = JSEngineResolutionAlgorithm.JSC
155+
reactHost!!.jsEngineResolutionAlgorithm = JSEngineResolutionAlgorithm.JSC
165156
}
166-
reactHostDelegate.reactHost = mReactHost
157+
reactHostDelegate.reactHost = reactHost
167158
}
168-
return mReactHost!!
159+
return reactHost!!
169160
}
170161

171162
@UnstableReactNativeAPI

0 commit comments

Comments
 (0)