maxkeppeler / sheets-compose-dialogs

✨ Enhancing Android UIs: A Jetpack Compose Library supporting a wide range of common use-cases with Material Design 3 Dialogs, Popups, and Bottom Sheets. ✨
https://maxkeppeler.github.io/sheets-compose-dialogs/
Apache License 2.0
780 stars 32 forks source link

[Feature] Provide withButtonView across all views/dialogs #50

Closed russellbanks closed 1 year ago

russellbanks commented 1 year ago

It's often the case that buttons are not needed at all. For example, bottom sheets already have a convenient way to dismiss them, so a positive button is not needed. Using the view (InfoView, etc) counterparts have more use cases of not needing a button such as providing buttons elsewhere or using animations.

Providing withButtonView across all dialogs would be good, or allowing the positive button to be null.

Use case 1:

I want my own button so that I can animate it

studio64_Q3LdExE2z2

Use case 2:

This is a bottom sheet only for information so I don't need any buttons. The user can just swipe it away

studio64_TbJ9e0yYfk

maxkeppeler commented 1 year ago

Which event would trigger the selection then if the button view is not wanted for the views, via a separate invocation to trigger it via the use-case state?

russellbanks commented 1 year ago

Which event would trigger the selection then if the button view is not wanted for the views, via a separate invocation to trigger it via the use-case state?

Yes, a separate invocation via the use-case state would work.

maxkeppeler commented 1 year ago

Great issue and a change I welcome much as well. I will work on this sometime within the next two weeks when I can find time.

maxkeppeler commented 1 year ago

Here's an example:

    val selectedTimeInSeconds = remember { mutableStateOf<Long>(240) }
    val state = rememberUseCaseState(visible = true, onCloseRequest = { closeSelection() })
    DurationDialog(
        state = state,
        selection = DurationSelection(
            withButtonView = false,
        ) { newTimeInSeconds ->
            selectedTimeInSeconds.value = newTimeInSeconds
        },
        config = DurationConfig(
            timeFormat = DurationFormat.HH_MM_SS,
            currentTime = selectedTimeInSeconds.value,
        ),
    )
    val coroutineScope = rememberCoroutineScope()
    coroutineScope.launch {
        delay(5000)
        state.invokePositiveAction()
    Log.d("DurationSample1", "DurationSample1: ${selectedTimeInSeconds.value}")
    }
russellbanks commented 1 year ago

@maxkeppeler onPositiveClick is still a required option even though there can be no buttons now.

InfoView(
   useCaseState = rememberUseCaseState(),
   selection = InfoSelection(withButtonView = false)
)

No value passed for parameter 'onPositiveClick'