Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saadaoui-3 opened this issue Jun 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@saadaoui-3
Copy link

saadaoui-3 commented Jun 17, 2024

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()
	})
  1. Use rememberLauncherForActivityResult() API to select files
import androidx.activity.compose.rememberLauncherForActivityResult

val launcher = rememberLauncherForActivityResult(
	contract = ActivityResultContracts.OpenDocument(),
	onResult = {
		fileField.focus = false
		fileField.uri =it
	}
)
  1. 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)
@saadaoui-3 saadaoui-3 added the bug Something isn't working label Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant