Node: rework LoggedInFlowNode analytics pop
This commit is contained in:
@@ -18,6 +18,7 @@ package io.element.android.appnav
|
||||
|
||||
import com.bumble.appyx.navmodel.backstack.BackStack
|
||||
import com.bumble.appyx.navmodel.backstack.operation.NewRoot
|
||||
import com.bumble.appyx.navmodel.backstack.operation.Remove
|
||||
|
||||
/**
|
||||
* Don't process NewRoot if the nav target already exists in the stack.
|
||||
@@ -29,3 +30,14 @@ fun <T : Any> BackStack<T>.safeRoot(element: T) {
|
||||
if (containsRoot) return
|
||||
accept(NewRoot(element))
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the last element on the backstack equals to the given one.
|
||||
*/
|
||||
fun <T : Any> BackStack<T>.removeLast(element: T) {
|
||||
val lastExpectedNavElement = elements.value.lastOrNull {
|
||||
it.key.navTarget == element
|
||||
} ?: return
|
||||
accept(Remove(lastExpectedNavElement.key))
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ import io.element.android.libraries.architecture.animation.rememberDefaultTransi
|
||||
import io.element.android.libraries.architecture.bindings
|
||||
import io.element.android.libraries.architecture.createNode
|
||||
import io.element.android.libraries.architecture.inputs
|
||||
import io.element.android.libraries.designsystem.theme.components.CircularProgressIndicator
|
||||
import io.element.android.libraries.designsystem.theme.components.Text
|
||||
import io.element.android.libraries.designsystem.utils.SnackbarDispatcher
|
||||
import io.element.android.libraries.di.AppScope
|
||||
@@ -92,7 +91,7 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||
snackbarDispatcher: SnackbarDispatcher,
|
||||
) : BackstackNode<LoggedInFlowNode.NavTarget>(
|
||||
backstack = BackStack(
|
||||
initialElement = NavTarget.SplashScreen,
|
||||
initialElement = NavTarget.RoomList,
|
||||
savedStateMap = buildContext.savedStateMap,
|
||||
),
|
||||
buildContext = buildContext,
|
||||
@@ -104,22 +103,14 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||
.distinctUntilChanged()
|
||||
.onEach { isConsentAsked ->
|
||||
if (isConsentAsked) {
|
||||
switchToRoomList()
|
||||
backstack.removeLast(NavTarget.AnalyticsOptIn)
|
||||
} else {
|
||||
switchToAnalytics()
|
||||
backstack.push(NavTarget.AnalyticsOptIn)
|
||||
}
|
||||
}
|
||||
.launchIn(lifecycleScope)
|
||||
}
|
||||
|
||||
private fun switchToRoomList() {
|
||||
backstack.safeRoot(NavTarget.RoomList)
|
||||
}
|
||||
|
||||
private fun switchToAnalytics() {
|
||||
backstack.safeRoot(NavTarget.AnalyticsSettings)
|
||||
}
|
||||
|
||||
interface Callback : Plugin {
|
||||
fun onOpenBugReport() = Unit
|
||||
}
|
||||
@@ -194,9 +185,6 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||
}
|
||||
|
||||
sealed interface NavTarget : Parcelable {
|
||||
@Parcelize
|
||||
object SplashScreen : NavTarget
|
||||
|
||||
@Parcelize
|
||||
object Permanent : NavTarget
|
||||
|
||||
@@ -222,12 +210,11 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||
object InviteList : NavTarget
|
||||
|
||||
@Parcelize
|
||||
object AnalyticsSettings : NavTarget
|
||||
object AnalyticsOptIn : NavTarget
|
||||
}
|
||||
|
||||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
||||
return when (navTarget) {
|
||||
NavTarget.SplashScreen -> splashNode(buildContext)
|
||||
NavTarget.Permanent -> {
|
||||
createNode<LoggedInNode>(buildContext)
|
||||
}
|
||||
@@ -330,7 +317,7 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||
.callback(callback)
|
||||
.build()
|
||||
}
|
||||
NavTarget.AnalyticsSettings -> {
|
||||
NavTarget.AnalyticsOptIn -> {
|
||||
analyticsOptInEntryPoint.createNode(this, buildContext)
|
||||
}
|
||||
}
|
||||
@@ -349,12 +336,6 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun splashNode(buildContext: BuildContext) = node(buildContext) {
|
||||
Box(modifier = it.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
Box(modifier = modifier) {
|
||||
|
||||
Reference in New Issue
Block a user