Hello, everyone! :blush: Im having some questions...
# compose
e
Hello, everyone! 😊 Im having some questions about my implementation. Could you help me please? Basically I’m trying to create a new
State
wrapping the default
ModalBottomSheetState
and one
State
I created to handle which content should be shown for the user. The implementation is on the comments and I need help to understand if I’m correctly saving the
State
in order to use
rememberSaveable
with it. (It is working as expected, but I’m a little afraid of my ā€œinner rememberā€ inside the
Saver
😬) Thanks a lot in advance! ā¤ļø
Implementation:
Copy code
@Stable
internal class AlkaaBottomSheetState(
    modalState: ModalBottomSheetState,
    contentState: BottomSheetContentState
) {
    var modalState by mutableStateOf(modalState)
    var contentState by mutableStateOf(contentState)

    companion object {
        fun Saver(modalState: ModalBottomSheetState): Saver<AlkaaBottomSheetState, *> = Saver(
            save = { it.contentState },
            restore = { AlkaaBottomSheetState(modalState = modalState, contentState = it) }
        )
    }
}

@OptIn(ExperimentalMaterialApi::class)
@Composable
internal fun rememberBottomSheetState(
    modalState: ModalBottomSheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden),
    contentState: BottomSheetContentState = BottomSheetContentState.EmptyContentState
): AlkaaBottomSheetState =
    rememberSaveable(saver = AlkaaBottomSheetState.Saver(modalState)) {
        AlkaaBottomSheetState(modalState = modalState, contentState = contentState)
    }

internal sealed class BottomSheetContentState {

    @Parcelize
    object EmptyContentState : BottomSheetContentState(), Parcelable

    @Parcelize
    object TaskListContentState : BottomSheetContentState(), Parcelable

    @Parcelize
    data class CategoryContentState(val category: Category) : BottomSheetContentState(), Parcelable
}
Usage:
Copy code
val sheetState = rememberBottomSheetState()