This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun confirmStartGame() { | |
val fm = supportFragmentManager | |
if (fm.isStateSaved) return | |
val newFragment = StartGameDialogFragment() | |
newFragment.show(newFragment, "game") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun DialogFragment.dialogFragmentComposeView( | |
consumeWindowInsets: Boolean, | |
content: @Composable () -> Unit, | |
): View { | |
return DialogFragmentComposeView( | |
context = requireContext(), | |
dialogProvider = { dialog ?: Dialog(requireContext()) }, | |
).apply { | |
consumeWindowInsets = consumeWindowInsets | |
layoutParams = ViewGroup.LayoutParams( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class DialogFragmentComposeView( | |
context: Context, | |
private val dialogProvider: () -> Dialog, | |
) : AbstractComposeView(context, null, 0), | |
DialogWindowProvider { | |
// The fix is here | |
override val window get() = dialogProvider().window!! | |
private val content = mutableStateOf<(@Composable () -> Unit)?>(null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun DialogFragment.dialogFragmentComposeView( | |
content: @Composable () -> Unit | |
): ComposeView { | |
return ComposeView(requireContext()).apply { | |
layoutParams = ViewGroup.LayoutParams( | |
ViewGroup.LayoutParams.MATCH_PARENT, | |
ViewGroup.LayoutParams.MATCH_PARENT | |
) | |
// Another interesting flaw. If you use other strategies in DialogFragment you may get crashes 🫠 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun DialogContent() { | |
var text by remember { mutableStateOf("") } | |
Scaffold( | |
topBar = { TopBar(onBackClicked = {}) }, | |
) { paddingValues -> | |
Column( | |
modifier = Modifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DialogExample : DialogFragment() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
// Custom style | |
setStyle(STYLE_NORMAL, R.style.FullScreenDialog_Light) | |
} | |
override fun onCreateView( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomDialog : DialogFragment(R.layout.custom_dialog) { | |
private val binding by viewBinding<CustomDialogBinding>() | |
private val viewModel by viewModels<CustomDialogViewModel>() | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
// Setup UI and other stuff ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChooseAttachmentFromStorageUseCase @Inject constructor(...) { | |
suspend fun invoke(...) { | |
val attachmentSource = showPickerBottomSheet(data = ...) | |
... | |
} | |
} |
NewerOlder