package com.microsoft.reacttestapp.component import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import com.facebook.react.ReactActivity import com.facebook.react.ReactRootView import com.facebook.react.interfaces.fabric.ReactSurface import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.microsoft.reacttestapp.TestApp class ComponentBottomSheetDialogFragment : BottomSheetDialogFragment() { companion object { const val TAG = "ReactComponentBottomSheetDialog" private const val DISPLAY_NAME = "displayName" private const val INITIAL_PROPERTIES = "initialProperties" private const val NAME = "name" fun newInstance(component: ComponentViewModel): ComponentBottomSheetDialogFragment { val args = Bundle() args.putString(NAME, component.name) args.putString(DISPLAY_NAME, component.displayName) args.putBundle(INITIAL_PROPERTIES, component.initialProperties) val fragment = ComponentBottomSheetDialogFragment() fragment.arguments = args return fragment } } private var surface: ReactSurface? = null override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View { val activity = requireActivity() as ReactActivity val application = activity.application as TestApp val surface = application.reactHost.createSurface( activity, requireNotNull(requireArguments().getString(NAME)), requireArguments().getBundle(INITIAL_PROPERTIES) ) this.surface = requireNotNull(surface) surface.start() return surface.view as View } }