Hello! :wave: I have a question regarding delegati...
# compose
e
Hello! 👋 I have a question regarding delegating Composables to inner nodes. Could someone help me? I have a
ModalBottomSheetLayout
that I want to appear on top of my
Scaffold
. The
Scaffold
has 4 tabs and I want each one to have a different content for this Modal. The solution I made is:
Copy code
val (sheetContent, setSheetContent) = remember { mutableStateOf<@Composable () -> Unit>({}) }
AlkaaBottomSheetLayout(bottomSheetContent = currentSection) {
    Scaffold {
        when (tab) {
            HomeSection.Tasks -> TaskListSection(bottomSheetContent = setCurrentSection)
            HomeSection.Search -> SearchSection(bottomSheetContent = setCurrentSection)
            HomeSection.Categories -> CategoriesSection(bottomSheetContent = setCurrentSection)
            HomeSection.Settings -> SettingSection(bottomSheetContent = setCurrentSection)
Is it the correct way to delegate the composable function? Thanks a lot in advance! ❤️
j
Looks reasonable to me. If it does what you want, what's the issue? Do you have a specific concern/question?
e
Thanks for your help, Jim. No, nothing in particular. I’m new to declarative UI and just wanted second opinions before going ahead. 😊
Actually, how do I use
rememberSaveable
with this approach? Is it possible to write a custom
Saver
to a lambda?
j
I'm not sure that
rememberSaveable
will do what you want here, as it helps with process restarts but not with things being added/removed AFAIK. I think you would want to hoist the state of your composables up into your app, so you can retain the state when switching tabs. Take a look at the discussion of state hoisting in https://developer.android.com/jetpack/compose/state#stateless-composables
e
That makes a lot of sense, Jim. Thanks, I will investigate it better.