Jason Ankers
01/30/2022, 2:56 PMAdam Powell
01/30/2022, 4:01 PMJason Ankers
01/30/2022, 4:49 PMRoute<ScreenA> {
SomeSharedUI()
Route<ScreenB> {
ScreenB()
}
Route<ScreenC> {
ScreenC()
}
}
This means the Route<T>() builder will need to run in a composable context.
I want the start destination to be the first route positionally, which would be ScreenB. To achieve this, Route<T>() runs an effect to push its first child route onto the backstack, which will render in the next composition. The problem is this effect will run after SomeSharedUI() has rendered causing a cascade of UI appearing. I want the entire route hierarchy to render in a single frameAdam Powell
01/30/2022, 4:57 PM@Composable
fun Thing(builder: FooBuilder.() -> Unit) {
val currentBuilder by rememberUpdatedState(builder)
val foo by remember { derivedStateOf { FooBuilder().apply(builder).build() } }
@Composable
content from building the object. You would need to wrap your SomeSharedUI()
call in something like
Route<ScreenA> {
Shared {
SomeSharedUI()
}
// ...
Jason Ankers
01/30/2022, 5:04 PMAdam Powell
01/30/2022, 5:08 PMRouteSharedContent<ScreenA> {
SomeSharedUI()
Routes {
Route<ScreenB> {
ScreenB()
}
Route<ScreenC> {
ScreenC()
}
}
}
Route<ScreenB> {
ScreenB()
}
the same as
Routes {
Route<ScreenB> {
ScreenB()
}
}
and probably still make it work in a single pass@Composable
fun MyContentScaffold(..., content: @Composable () -> Unit) {
// stuff
content()
}
// in your routing definitions
Route<ScreenB> {
MyContentScaffold(..) {
ScreenB()
}
}
Route<ScreenC> {
MyContentScaffold(..) {
ScreenC()
}
}
movableContentOf {}
is going to give you some more options there too.Jason Ankers
01/30/2022, 5:22 PMAdam Powell
01/30/2022, 5:23 PMval sharedContent = remember { movableContentOf { SomeSharedUI() } }
RoutingTable {
Route(...) {
sharedContent()
ScreenA()
}
Route(...) {
sharedContent()
ScreenB()
}
}
and that instance of SomeSharedUI()
would retain all of its remembered composition state as it moves between destinationsJason Ankers
01/30/2022, 5:29 PMAdam Powell
01/30/2022, 5:41 PMJason Ankers
01/30/2022, 6:05 PMremember(backStackIsEmpty) {
if (backStackIsEmpty) backStack.push(route)
null
}
lhwdev
02/06/2022, 3:54 AM