maxkeppeler / sheets

⭐ ‎‎‎‏‏‎ ‎Offers a range of beautiful sheets (dialogs & bottom sheets) for quick use in your project. Includes many ways to customize sheets.
https://maxkeppeler.github.io/sheets/
Apache License 2.0
923 stars 77 forks source link

`rememberSheetState` and `rememberLauncherForActivityResult` not working together in the same page #130

Open saadaoui-3 opened 4 months ago

saadaoui-3 commented 4 months ago

Describe the bug Using Kotlin, when i try to execute rememberLauncherForActivityResult to select a file, while another rememberSheetState already exists, i got an exception

android.os.BadParcelableException: Parcelable encountered IOException writing serializable object (name = com.maxkeppeker.sheets.core.models.base.SheetState$SheetStateData)

Library Version:

implementation("com.maxkeppeler.sheets-compose-dialogs:calendar:1.0.2")

To Reproduce Steps to reproduce the behavior:

  1. Use the rememberSheetState somewhere (No need to open the date picker, just include the code to be executed)

    val calendarDialogState = rememberSheetState(onCloseRequest = { dateField.focus = false })
    CalendarDialog(state = calendarDialogState, selection = CalendarSelection.Date { date ->
        dateField.value = date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))
    })
    Button(text = "Select date", onClick = {
        dateField.focus = true
        calendarDialogState.show()
    })
  2. Use rememberLauncherForActivityResult() API to select files

    
    import androidx.activity.compose.rememberLauncherForActivityResult

val launcher = rememberLauncherForActivityResult( contract = ActivityResultContracts.OpenDocument(), onResult = { fileField.focus = false fileField.uri =it } )


3. The moment you run `luncher` you will get the exception

Button(text = "Select file", onClick = { fileField.focus = true launcher.launch(arrayOf("application/pdf")) })


**Expected behavior**
Being able to have the date picker and file picker in the same page

**Affected Device(s):**
 - Xiaomi Redmi 13C

**Additional notes:**
Probably the issue came from `rememberSheetState` because when i remove only the date picker, the entire form works fine
Make sure that both of fields should be rendered

**Screenshots**
Here is the full exception

FATAL EXCEPTION: main Process: com.example.example, PID: 29163 android.os.BadParcelableException: Parcelable encountered IOException writing serializable object (name = com.maxkeppeker.sheets.core.models.base.SheetState$SheetStateData) at android.os.Parcel.writeSerializable(Parcel.java:2751) at android.os.Parcel.writeValue(Parcel.java:2517) at android.os.Parcel.writeValue(Parcel.java:2316) at android.os.Parcel.writeList(Parcel.java:1382) at android.os.Parcel.writeValue(Parcel.java:2460) at android.os.Parcel.writeValue(Parcel.java:2316) at android.os.Parcel.writeMapInternal(Parcel.java:1233) at android.os.Parcel.writeMap(Parcel.java:1215) at android.os.Parcel.writeValue(Parcel.java:2430) at android.os.Parcel.writeValue(Parcel.java:2316) at android.os.Parcel.writeMapInternal(Parcel.java:1233) at android.os.Parcel.writeMap(Parcel.java:1215) at android.os.Parcel.writeValue(Parcel.java:2430) at android.os.Parcel.writeValue(Parcel.java:2316) at android.os.Parcel.writeList(Parcel.java:1382) at android.os.Parcel.writeValue(Parcel.java:2460) at android.os.Parcel.writeValue(Parcel.java:2316) at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802) at android.os.Bundle.writeToParcel(Bundle.java:1362) at android.os.Parcel.writeBundle(Parcel.java:1334) at android.os.Parcel.writeValue(Parcel.java:2433) at android.os.Parcel.writeValue(Parcel.java:2323) at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802) at android.os.Bundle.writeToParcel(Bundle.java:1362) at android.os.Parcel.writeBundle(Parcel.java:1334) at android.os.Parcel.writeValue(Parcel.java:2433) at android.os.Parcel.writeValue(Parcel.java:2323) at android.os.BaseBundle.dumpStats(BaseBundle.java:1874) at android.os.BaseBundle.dumpStats(BaseBundle.java:1911) at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:150) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:211) at android.os.Looper.loop(Looper.java:300) at android.app.ActivityThread.main(ActivityThread.java:8324) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:581) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1028) Caused by: java.io.NotSerializableException: com.example.example.utils.forms.Field at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1240) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1620) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1581) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1490) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234) at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1620) at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1581) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1490) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1234) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:354) at android.os.Parcel.writeSerializable(Parcel.java:2746) at android.os.Parcel.writeValue(Parcel.java:2517)  at android.os.Parcel.writeValue(Parcel.java:2316)  at android.os.Parcel.writeList(Parcel.java:1382)  at android.os.Parcel.writeValue(Parcel.java:2460)  at android.os.Parcel.writeValue(Parcel.java:2316)  at android.os.Parcel.writeMapInternal(Parcel.java:1233)  at android.os.Parcel.writeMap(Parcel.java:1215)  at android.os.Parcel.writeValue(Parcel.java:2430)  at android.os.Parcel.writeValue(Parcel.java:2316)  at android.os.Parcel.writeMapInternal(Parcel.java:1233)  at android.os.Parcel.writeMap(Parcel.java:1215)  at android.os.Parcel.writeValue(Parcel.java:2430)  at android.os.Parcel.writeValue(Parcel.java:2316)  at android.os.Parcel.writeList(Parcel.java:1382)  at android.os.Parcel.writeValue(Parcel.java:2460)  at android.os.Parcel.writeValue(Parcel.java:2316)  at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265)  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802)  at android.os.Bundle.writeToParcel(Bundle.java:1362)  at android.os.Parcel.writeBundle(Parcel.java:1334)  at android.os.Parcel.writeValue(Parcel.java:2433)  at android.os.Parcel.writeValue(Parcel.java:2323)  at android.os.Parcel.writeArrayMapInternal(Parcel.java:1265)  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1802)  at android.os.Bundle.writeToParcel(Bundle.java:1362)  at android.os.Parcel.writeBundle(Parcel.java:1334)  at android.os.Parcel.writeValue(Parcel.java:2433)  at android.os.Parcel.writeValue(Parcel.java:2323)  at android.os.BaseBundle.dumpStats(BaseBundle.java:1874)  at android.os.BaseBundle.dumpStats(BaseBundle.java:1911)  at android.app.servertransaction.PendingTransactionActions$StopInfo.run(PendingTransactionActions.java:150)  at android.os.Handler.handleCallback(Handler.java:942)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loopOnce(Looper.java:211)  at android.os.Looper.loop(Looper.java:300)  at android.app.ActivityThread.main(ActivityThread.java:8324)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:581)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1028)