https://kotlinlang.org logo
#compose
Title
# compose
s

Scott Peterson

04/04/2022, 1:49 PM
What is everyone using as a date picker in Compose land?
c

Csaba Szugyiczki

04/04/2022, 1:58 PM
We are using MaterialDatePickerDialog from Compose and it is working fine, but a bit tricky to get it work
you can get the activity via LocalContext
val activity = LocalContext.current.getActivity()
Copy code
fun Context.getActivity(): FragmentActivity? {
    var currentContext = this

    while (currentContext is ContextWrapper) {
        if (currentContext is FragmentActivity) {
            return currentContext
        }

        currentContext = currentContext.baseContext
    }

    return null
}
and then use the activity to display the date picker dialog
there was no fully working Compose alternative by the time we needed such component (around last September) not sure about now
t

Tgo1014

04/04/2022, 2:08 PM
s

Scott Peterson

04/05/2022, 12:02 AM
thank you both!
f

FunkyMuse

04/05/2022, 6:59 PM
You can always use the XML date picker inside compose, stackoverflow
30 Views