When we navigate from screen “A” to screen “B”. Sc...
# compose
m
When we navigate from screen “A” to screen “B”. Screen “B” has some default background Color. How do make this screen B partially transparent so that I can see screen A . Thanks in advance 🙏
c
Whatever the root layout is on screen B (let's say a Column) just set the background via a modifier and set the color to
Color(0x80FF0000)
. or just take whatever color you're already setting (lets say it's Color.Black), you should be able to do Color.Red.(alpha = .5F) to set the alpha that way.
m
That's not working, this solution works under same composable under nav host
If it's different composable setting Color alpha to .5f don't work
c
Hm. I might have spoke too soon. I think when you use compose-nav then when you navigate to different destinations, the destinations aren't actually stacked on top of each other.
i
Assuming you are using Navigation Compose, only one screen is visible at a time (that's how
Crossfade
(which is what
NavHost
uses) and
AnimatedContent
(which is what
AnimatedNavHost
uses) works). You could make your own
Navigator
like BottomSheetNavigator that has the destination implement
FloatingWindow
, which would keep the previous destination visible underneath, but then you'd need to handle displaying that overlay destination yourself
Maybe what you're actually looking for is a dialog destination (which uses that same technique)?
m
Want to have a standard bottomsheet where even after navigating from that bottomsheet that bottom sheet should persist, using floating window will not persist the state when clicked back from new destination
c
You can just use a bottom sheet that's built into the screen instead of using a bottom sheet destination. use
ModalBottomSheetLayout
https://developer.android.com/reference/kotlin/androidx/compose/material/package-summary#ModalBottomSheetLayout(kotli[…]hics.Color,kotlin.Function0)
m
With this I won't be able to treat it like a destination. Accompanist material lib has a solution where I can treat bottomsheet as destination but that bottomsheet disappears when navigated to different destination. I need a similar solution but bottomsheet should persist.
i
A persisted element outside of the NavHost that continues to be on screen even after you navigate...shouldn't be part of the NavHost. It should just be something separate that you show/hide independently from the NavHost