|
| 1 | +package com.microsoft.reacttestapp.component |
| 2 | + |
| 3 | +import android.os.Bundle |
| 4 | +import android.view.LayoutInflater |
| 5 | +import android.view.View |
| 6 | +import android.view.ViewGroup |
| 7 | +import com.facebook.react.ReactActivity |
| 8 | +import com.facebook.react.ReactRootView |
| 9 | +import com.facebook.react.interfaces.fabric.ReactSurface |
| 10 | +import com.google.android.material.bottomsheet.BottomSheetDialogFragment |
| 11 | +import com.microsoft.reacttestapp.TestApp |
| 12 | + |
| 13 | +class ComponentBottomSheetDialogFragment : BottomSheetDialogFragment() { |
| 14 | + |
| 15 | + companion object { |
| 16 | + const val TAG = "ReactComponentBottomSheetDialog" |
| 17 | + |
| 18 | + private const val DISPLAY_NAME = "displayName" |
| 19 | + private const val INITIAL_PROPERTIES = "initialProperties" |
| 20 | + private const val NAME = "name" |
| 21 | + |
| 22 | + fun newInstance(component: ComponentViewModel): ComponentBottomSheetDialogFragment { |
| 23 | + val args = Bundle() |
| 24 | + args.putString(NAME, component.name) |
| 25 | + args.putString(DISPLAY_NAME, component.displayName) |
| 26 | + args.putBundle(INITIAL_PROPERTIES, component.initialProperties) |
| 27 | + |
| 28 | + val fragment = ComponentBottomSheetDialogFragment() |
| 29 | + fragment.arguments = args |
| 30 | + return fragment |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + private var surface: ReactSurface? = null |
| 35 | + |
| 36 | + override fun onCreateView( |
| 37 | + inflater: LayoutInflater, |
| 38 | + container: ViewGroup?, |
| 39 | + savedInstanceState: Bundle? |
| 40 | + ): View { |
| 41 | + val activity = requireActivity() as ReactActivity |
| 42 | + val application = activity.application as TestApp |
| 43 | + val surface = application.reactHost.createSurface( |
| 44 | + activity, |
| 45 | + requireNotNull(requireArguments().getString(NAME)), |
| 46 | + requireArguments().getBundle(INITIAL_PROPERTIES) |
| 47 | + ) |
| 48 | + this.surface = requireNotNull(surface) |
| 49 | + surface.start() |
| 50 | + return surface.view as View |
| 51 | + } |
| 52 | +} |
0 commit comments