galex
05/23/2023, 9:59 AMBackHandlerBottomSheetDialogFragmentBottomSheetDialoggalex
05/23/2023, 3:32 PMonBackPressedprivate lateinit var dialog: ComponentDialog
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    return BottomSheetDialog(requireContext(), theme).apply {
        fullyExpanded()
        notDraggable()
        withoutBackgroundDim()
    }.also { dialog = it }
}private val ComponentDialog.asBackPressedDispatcherOwner: OnBackPressedDispatcherOwner
        get() = object : OnBackPressedDispatcherOwner {
            override val lifecycle: Lifecycle
                get() = this@asBackPressedDispatcherOwner.lifecycle
            override val onBackPressedDispatcher: OnBackPressedDispatcher
                get() = this@asBackPressedDispatcherOwner.onBackPressedDispatcher
        }CompositionLocalProvider(
    LocalOnBackPressedDispatcherOwner provides dialog.asBackPressedDispatcherOwner
) {
    MainChatScreen(::dismiss)
}Ian Lake
05/23/2023, 4:09 PMOnBackPressedDispatcherOwnerIan Lake
05/23/2023, 4:10 PMIan Lake
05/23/2023, 4:13 PMViewTreeOnBackPressedDispatcherOwnerLocalOnBackPressedDispatcherOwnerIan Lake
05/23/2023, 4:14 PMIan Lake
05/23/2023, 4:17 PMIan Lake
05/23/2023, 4:18 PMgalex
05/24/2023, 8:29 AMoverride fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return BottomSheetDialog(requireContext(), theme).apply {
            (...)
            initViewTreeOwners()
        }
    }private fun ComponentDialog.initViewTreeOwners() {
    window?.decorView?.let {
        it.setViewTreeLifecycleOwner(this)
        it.setViewTreeOnBackPressedDispatcherOwner(this)
        it.setViewTreeSavedStateRegistryOwner(this)
    }
}