0

I am working on a modulare project where the navigation is handled using NavController and deeplinks.

I have several BottomSheetDialogFragments that I'd like to replace with Jetpack Compose.

The current implementation of BottomSheetDialogFragment looks like this

class MyBottomSheetDialogFragment : BottomSheetDialogFragment() {

    @Inject
    lateinit var viewModelFactory: ViewModelProvider.Factory
    private val viewModel: MyViewModel by viewModels { viewModelFactory }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        AndroidSupportInjection.inject(this)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return BottomSheetFragmentBinding.inflate(
            inflater,
            container,
            false
        ).root
    }
}

It's included in a nav_graph.xml

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/xx"
    app:startDestination="@+id/xxx">

    <dialog
        android:id="@+id/myBottomSheetDialogFragment"
        android:name="path.to.MyBottomSheetDialogFragment">

        <deepLink app:uri="deeplink://myBottomSheetDialogFragment" />

    </dialog>
</navigation>

It's shown using deeplink

findNavController().navigate(
    NavDeepLinkRequest.Builder
        .fromUri(
            Uri
                .parse("deeplink://myBottomSheetDialogFragment")
                .buildUpon()
                .build()
        )
        .build()
)

And it looks like this

enter image description here

I'd like to use JetpackCompose to generate this dialog but I'm confused how to do it. First I don't know if I should use BottomSheetDialogFragment() and simply use SetContent{} in onCreateView or I should use BottomSheetScaffold. The important thing is that it should be shown via deeplink because the modules don't have dependency on each other, so it can't simply create an instance of the dialog and use .show()

Mehdi Satei
  • 1,225
  • 9
  • 26

0 Answers0