Created
July 18, 2024 09:56
-
-
Save mdjastrzebski/3f7b1ee9377f797bf610dad2906c61c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.example.flutter_brownfield_app | |
import android.content.Context | |
import android.view.View | |
import com.facebook.react.ReactRootView | |
import io.flutter.plugin.platform.PlatformView | |
/** | |
* This view is used to embed React Native view directly in the native view hierarchy. It allows to | |
* mix and match Flutter and React Native views on one screen. | |
*/ | |
internal class ReactView(context: Context, id: Int, creationParams: Map<String?, Any?>?) : PlatformView { | |
private val reactNativeHost = (context.applicationContext as MainApplication).reactNativeHost | |
private val reactRootView: ReactRootView = ReactRootView(context) | |
override fun getView(): View { | |
return reactRootView | |
} | |
override fun dispose() { | |
reactRootView.unmountReactApplication() | |
} | |
init { | |
val moduleName = creationParams?.get("moduleName") as String | |
reactRootView.startReactApplication(reactNativeHost.reactInstanceManager, moduleName, null) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment