2

I have a bunch of popup Dialogs throughout the app I'm working on. What I wanted to do is turn them all into a BottomSheet presentation. Right now, I have one class where I'm instantiating the Dialogs from and able to reuse them throughout the app.

What would I need to do: to do the same to be able to reuse BottomSheetDialogFragments? Rather than creating a BottomSheet presentation from a screen to screen basis, is there a way to have all of them in one class and just call them when I need to from a different screen?

Adding a little bit more context. Let's say I have a CloseDialog, LogoutConfirmationDialog and I use them on multiple screens currently. I would like to do the same with the Android BottomSheet presentation modal if I was to turn these two Dialogs into a BottomSheet presentation.

JuJu Juned
  • 134
  • 8

1 Answers1

0

You can create a custom fragment and inherit "BottomSheetDialogFragment"

class CustomBtmSheetFragment : BottomSheetDialogFragment() 
    {

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



            override fun getTheme(): Int = R.style.CustomBottomSheetDialog

            override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =
                BottomSheetDialog(requireContext(), theme)

            override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

                dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

            }


    }
Ranan
  • 21
  • 2