Shivam Kanodia
06/13/2023, 10:04 AM@Composable
internal fun RootContent(component: RootComponent) {
Children(
stack = component.childStack,
animation = stackAnimation(fade()),
) {
println("child stack ===== ${component.childStack.value}")
when (val child = it.instance) {
is RootComponent.Child.EnterMobileNumber -> LoginComponent(child.component)
is RootComponent.Child.EnterOtp -> OtpComponent(child.component)
is RootComponent.Child.ProjectListing -> ProjectListingMainScreen(child.component)
is RootComponent.Child.ProjectDetails -> ProjectDetailsScreen(child.component)
is RootComponent.Child.Notifications -> NotificationScreen(child.component)
is RootComponent.Child.ImagePreviewFullScreen -> ImagePreviewFullScreen(child.component)
}
}
}
THis is my root content , after logging in i am on ProjectListing Child, how do i pop when i logout the user to move the stack to EnterMobileNumber.
Stack EnterMobileNumber->EnterOtp->ProjectListing , on ProjectListing i press logout how do i pop stack? trying pop() but its not working correctly for this case.Jan
06/13/2023, 10:16 AMShivam Kanodia
06/13/2023, 10:25 AMJan
06/13/2023, 10:26 AMJan
06/13/2023, 10:26 AMJan
06/13/2023, 10:27 AMclass DefaultRootComponent(
componentContext: ComponentContext
) : RootComponent, ComponentContext by componentContext {
private val navigation = StackNavigation<Config>()
....
}
Shivam Kanodia
06/13/2023, 10:27 AM2.0.0-compose-experimental-alpha-02"
using this version unable to access popToShivam Kanodia
06/13/2023, 10:27 AMwhile (childStack.backStack.isNotEmpty()) {
navigation.pop()
}
Shivam Kanodia
06/13/2023, 10:28 AMShivam Kanodia
06/13/2023, 10:35 AMShivam Kanodia
06/13/2023, 10:35 AMShivam Kanodia
06/13/2023, 10:37 AMJan
06/13/2023, 10:38 AMShivam Kanodia
06/13/2023, 10:43 AMArkadii Ivanov
06/13/2023, 10:45 AMpopTo
method was introduced in version 2.0.0-beta-01. However, in your case you would be better using popWhile.
navigation.popWhile { it !is Config.EnterMobileNumber }
But actually, it would be better to remove unneeded components from the stack, so they could be destroyed and resources released. E.g. after successful login you could just call navigation.replaceAll(Config.ProjectListing(...)
. Then when you need to login again, you can call navigation.replaceAll(Config.EnterMobileNumber(...))
.Shivam Kanodia
06/13/2023, 10:46 AMArkadii Ivanov
06/13/2023, 11:02 AMfade
, and push/pop with slide
), then I suggest to decompose your root component by two. E.g. extract the login flow (the login related components) to a LoginComponent
, and the rest into MainComponent
. In this case you can utilize nested navigation, and have Children
on the root level with fade
animation, and Children
on inner levels with slide
.Shivam Kanodia
06/13/2023, 11:18 AMprivate sealed class Configuration : Parcelable {
@Parcelize
object EnterMobileNumber : Configuration()
@Parcelize
data class EnterOtp(var mobile: String, val verificationId: String) : Configuration()
@Parcelize
object ProjectListing : Configuration()
@Parcelize
data class ProjectDetails(val projectId: String) : Configuration()
@Parcelize
data class ImagePreviewFullScreen(
val imagesList: List<PreviewFile>, val initialImageIndex: Int = 0
) : Configuration()
}
Arkadii Ivanov
06/13/2023, 11:25 AMShivam Kanodia
06/13/2023, 11:44 AMArkadii Ivanov
06/13/2023, 12:01 PM