https://kotlinlang.org logo
#compose
Title
# compose
m

Mohan manu

08/12/2022, 4:18 AM
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

Colton Idle

08/12/2022, 5:32 AM
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

Mohan manu

08/12/2022, 5:33 AM
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

Colton Idle

08/12/2022, 5:41 AM
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

Ian Lake

08/12/2022, 5:42 AM
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

Mohan manu

08/12/2022, 5:45 AM
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

Colton Idle

08/12/2022, 5:46 AM
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

Mohan manu

08/12/2022, 5:54 AM
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

Ian Lake

08/12/2022, 2:59 PM
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
3 Views