-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted RNTesterReactHostDelegate.java to RNTesterReactHostDelegate…
….kt (#38978) Summary: This PR converts RNTesterReactHostDelegate into Kotlin as requested in #38825 . ## Changelog: [INTERNAL] [CHANGED] - Convert to RNTesterReactHostDelegate.java => Kotlin Pull Request resolved: #38978 Test Plan: Run yarn && yarn android All tests should pass Reviewed By: huntie, rshest Differential Revision: D48598018 Pulled By: cortinico fbshipit-source-id: f29eaa32c63835e090baf60bbde6c0c72b9041c2
- Loading branch information
1 parent
e689932
commit 0b6e9bf
Showing
2 changed files
with
124 additions
and
180 deletions.
There are no files selected for viewing
180 changes: 0 additions & 180 deletions
180
...-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterReactHostDelegate.java
This file was deleted.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
...rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterReactHostDelegate.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,124 @@ | ||
/* | ||
* 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.uiapp | ||
|
||
import android.content.Context | ||
import com.facebook.fbreact.specs.SampleLegacyModule | ||
import com.facebook.fbreact.specs.SampleTurboModule | ||
import com.facebook.react.JSEngineResolutionAlgorithm | ||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.ReactPackageTurboModuleManagerDelegate | ||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.bridge.JSBundleLoader | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridgeless.BindingsInstaller | ||
import com.facebook.react.bridgeless.JSCInstance | ||
import com.facebook.react.bridgeless.JSEngineInstance | ||
import com.facebook.react.bridgeless.ReactHostDelegate | ||
import com.facebook.react.bridgeless.ReactHostImpl | ||
import com.facebook.react.bridgeless.hermes.HermesInstance | ||
import com.facebook.react.common.annotations.UnstableReactNativeAPI | ||
import com.facebook.react.config.ReactFeatureFlags | ||
import com.facebook.react.defaults.DefaultTurboModuleManagerDelegate | ||
import com.facebook.react.fabric.ReactNativeConfig | ||
import com.facebook.react.module.model.ReactModuleInfo | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
import com.facebook.react.shell.MainReactPackage | ||
import com.facebook.react.turbomodule.core.TurboModuleManager | ||
import com.facebook.react.uiapp.component.MyLegacyViewManager | ||
import com.facebook.react.uiapp.component.MyNativeViewManager | ||
import com.facebook.react.uimanager.ViewManager | ||
|
||
@UnstableReactNativeAPI | ||
class RNTesterReactHostDelegate internal constructor(context: Context) : ReactHostDelegate { | ||
var reactHost: ReactHostImpl? = null | ||
|
||
override val jsMainModulePath: String = "js/RNTesterApp.android" | ||
|
||
override val jsBundleLoader: JSBundleLoader = | ||
JSBundleLoader.createAssetLoader(context, "assets://RNTesterApp.android.bundle", true) | ||
|
||
@get:Synchronized override val bindingsInstaller: BindingsInstaller? = null | ||
|
||
override val turboModuleManagerDelegateBuilder: ReactPackageTurboModuleManagerDelegate.Builder = | ||
DefaultTurboModuleManagerDelegate.Builder() | ||
|
||
override val jsEngineInstance: JSEngineInstance = | ||
if (reactHost?.jsEngineResolutionAlgorithm == JSEngineResolutionAlgorithm.JSC) { | ||
JSCInstance() | ||
} else { | ||
HermesInstance() | ||
} | ||
|
||
override fun handleInstanceException(error: Exception) {} | ||
|
||
override fun getReactNativeConfig(turboModuleManager: TurboModuleManager): ReactNativeConfig = | ||
ReactNativeConfig.DEFAULT_CONFIG | ||
|
||
override val reactPackages: List<ReactPackage> by lazy { | ||
listOf( | ||
MainReactPackage(), | ||
object : TurboReactPackage() { | ||
override fun getModule( | ||
name: String, | ||
reactContext: ReactApplicationContext | ||
): NativeModule? = | ||
when { | ||
!ReactFeatureFlags.useTurboModules -> null | ||
name == SampleTurboModule.NAME -> SampleTurboModule(reactContext) | ||
name == SampleLegacyModule.NAME -> SampleLegacyModule(reactContext) | ||
else -> null | ||
} | ||
|
||
// Note: Specialized annotation processor for @ReactModule isn't | ||
// configured in OSS | ||
// yet. For now, hardcode this information, though it's not necessary | ||
// for most modules | ||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = | ||
ReactModuleInfoProvider { | ||
if (ReactFeatureFlags.useTurboModules) { | ||
mapOf( | ||
SampleTurboModule.NAME to | ||
ReactModuleInfo( | ||
SampleTurboModule.NAME, | ||
"SampleTurboModule", | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
true // isTurboModule | ||
), | ||
SampleLegacyModule.NAME to | ||
ReactModuleInfo( | ||
SampleLegacyModule.NAME, | ||
"SampleLegacyModule", | ||
false, // canOverrideExistingModule | ||
false, // needsEagerInit | ||
true, // hasConstants | ||
false, // isCxxModule | ||
false // isTurboModule | ||
), | ||
) | ||
} else { | ||
emptyMap() | ||
} | ||
} | ||
}, | ||
object : ReactPackage { | ||
override fun createNativeModules( | ||
reactContext: ReactApplicationContext | ||
): List<NativeModule> = emptyList() | ||
|
||
override fun createViewManagers( | ||
reactContext: ReactApplicationContext | ||
): List<ViewManager<*, *>> = | ||
listOf(MyNativeViewManager(), MyLegacyViewManager(reactContext)) | ||
}) | ||
} | ||
} |