JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.38k stars 1.12k forks source link

method signature of fun rememberDatePickerState has changed - one new argument #3545

Closed skolson closed 10 months ago

skolson commented 10 months ago

Using: Kotlin 1.9 Compose material3 MP 1.5.0-rc02 android compose material3 1.6.0-alpha03

With the above combination, defining an MP Composable using the DatePicker stuff builds fine, but fails at runtime with this exception:

java.lang.NoSuchMethodError: No static method rememberDatePickerState

After research, looks like Android Compose has added a 5th argument to function rememberDatePickerState, so now it has this signature (I'm unsure which release started this):

fun rememberDatePickerState(
    @Suppress("AutoBoxing") initialSelectedDateMillis: Long? = null,
    @Suppress("AutoBoxing") initialDisplayedMonthMillis: Long? = initialSelectedDateMillis,
    yearRange: IntRange = DatePickerDefaults.YearRange,
    initialDisplayMode: DisplayMode = DisplayMode.Picker,
    selectableDates: SelectableDates = object : SelectableDates {}
): DatePickerState

The MP signature for the same function does not have the selectableDates argument. So build works but runtime fails. The Gradle build seems to resolve with the android signature, not the MP signature.

For ongoing compatibility with android Compose, looks like the MP signature for this function needs an update. Here's the current MP signature for this function:

fun rememberDatePickerState(
    @Suppress("AutoBoxing") initialSelectedDateMillis: Long? = null,
    @Suppress("AutoBoxing") initialDisplayedMonthMillis: Long? = initialSelectedDateMillis,
    yearRange: IntRange = DatePickerDefaults.YearRange,
    initialDisplayMode: DisplayMode = DisplayMode.Picker
): DatePickerState
alexzhirkevich commented 10 months ago

SelectableDates was introduced in m3 1.2.0-alpha-02. Compose multiplatform is currently based on m3 1.1.1

mazunin-v-jb commented 10 months ago

Hello! Thanks for submitting the issue.

@alexzhirkevich is right, I'll add a bit more context.

Compatibility between material3 in Compose and material3 alpha in Google might be broken, like in this situation. Please, try to switch on stable 1.1.1 version

You can find more information here

skolson commented 10 months ago

Sounds like Material 3 1.2.0 support is not targeted for CMP 1.5.0. Is there a target release of CMP planned yet for support of Material 3 1.2.0? Also thanks for the info that this started with 1.2.0-alpha02!