use saveable state holder
This commit is contained in:
parent
4077733421
commit
c289a70d9a
|
@ -77,7 +77,7 @@ class MainActivity : ComponentActivity() {
|
|||
ManagerNavigator(
|
||||
navigationController = navController
|
||||
) {
|
||||
it.last().content()
|
||||
it.content()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,16 @@ package com.vanced.manager.ui.navigation
|
|||
import androidx.compose.animation.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
|
||||
import com.vanced.manager.ui.util.Screen
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
fun <T> ManagerNavigator(
|
||||
fun <T : Screen> ManagerNavigator(
|
||||
navigationController: NavigationController<T>,
|
||||
content: @Composable (targetContent: List<T>) -> Unit
|
||||
content: @Composable (targetContent: T) -> Unit
|
||||
) {
|
||||
val saveableStateHolder = rememberSaveableStateHolder()
|
||||
val screens = remember { navigationController.screens }
|
||||
|
||||
//TODO Animation is not working for some weird reasons
|
||||
|
@ -25,6 +28,9 @@ fun <T> ManagerNavigator(
|
|||
},
|
||||
targetState = screens
|
||||
) { targetContents ->
|
||||
content(targetContents)
|
||||
val targetContent = targetContents.last()
|
||||
saveableStateHolder.SaveableStateProvider(key = targetContent.route) {
|
||||
content(targetContent)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue