Node: rework LoggedInFlowNode analytics pop
This commit is contained in:
parent
b72313bc84
commit
5c41f0188a
2 changed files with 17 additions and 24 deletions
|
|
@ -18,6 +18,7 @@ package io.element.android.appnav
|
||||||
|
|
||||||
import com.bumble.appyx.navmodel.backstack.BackStack
|
import com.bumble.appyx.navmodel.backstack.BackStack
|
||||||
import com.bumble.appyx.navmodel.backstack.operation.NewRoot
|
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.
|
* 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
|
if (containsRoot) return
|
||||||
accept(NewRoot(element))
|
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.bindings
|
||||||
import io.element.android.libraries.architecture.createNode
|
import io.element.android.libraries.architecture.createNode
|
||||||
import io.element.android.libraries.architecture.inputs
|
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.theme.components.Text
|
||||||
import io.element.android.libraries.designsystem.utils.SnackbarDispatcher
|
import io.element.android.libraries.designsystem.utils.SnackbarDispatcher
|
||||||
import io.element.android.libraries.di.AppScope
|
import io.element.android.libraries.di.AppScope
|
||||||
|
|
@ -92,7 +91,7 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
snackbarDispatcher: SnackbarDispatcher,
|
snackbarDispatcher: SnackbarDispatcher,
|
||||||
) : BackstackNode<LoggedInFlowNode.NavTarget>(
|
) : BackstackNode<LoggedInFlowNode.NavTarget>(
|
||||||
backstack = BackStack(
|
backstack = BackStack(
|
||||||
initialElement = NavTarget.SplashScreen,
|
initialElement = NavTarget.RoomList,
|
||||||
savedStateMap = buildContext.savedStateMap,
|
savedStateMap = buildContext.savedStateMap,
|
||||||
),
|
),
|
||||||
buildContext = buildContext,
|
buildContext = buildContext,
|
||||||
|
|
@ -104,22 +103,14 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.onEach { isConsentAsked ->
|
.onEach { isConsentAsked ->
|
||||||
if (isConsentAsked) {
|
if (isConsentAsked) {
|
||||||
switchToRoomList()
|
backstack.removeLast(NavTarget.AnalyticsOptIn)
|
||||||
} else {
|
} else {
|
||||||
switchToAnalytics()
|
backstack.push(NavTarget.AnalyticsOptIn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.launchIn(lifecycleScope)
|
.launchIn(lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun switchToRoomList() {
|
|
||||||
backstack.safeRoot(NavTarget.RoomList)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun switchToAnalytics() {
|
|
||||||
backstack.safeRoot(NavTarget.AnalyticsSettings)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Callback : Plugin {
|
interface Callback : Plugin {
|
||||||
fun onOpenBugReport() = Unit
|
fun onOpenBugReport() = Unit
|
||||||
}
|
}
|
||||||
|
|
@ -194,9 +185,6 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface NavTarget : Parcelable {
|
sealed interface NavTarget : Parcelable {
|
||||||
@Parcelize
|
|
||||||
object SplashScreen : NavTarget
|
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
object Permanent : NavTarget
|
object Permanent : NavTarget
|
||||||
|
|
||||||
|
|
@ -222,12 +210,11 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
object InviteList : NavTarget
|
object InviteList : NavTarget
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
object AnalyticsSettings : NavTarget
|
object AnalyticsOptIn : NavTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
||||||
return when (navTarget) {
|
return when (navTarget) {
|
||||||
NavTarget.SplashScreen -> splashNode(buildContext)
|
|
||||||
NavTarget.Permanent -> {
|
NavTarget.Permanent -> {
|
||||||
createNode<LoggedInNode>(buildContext)
|
createNode<LoggedInNode>(buildContext)
|
||||||
}
|
}
|
||||||
|
|
@ -330,7 +317,7 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
.callback(callback)
|
.callback(callback)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
NavTarget.AnalyticsSettings -> {
|
NavTarget.AnalyticsOptIn -> {
|
||||||
analyticsOptInEntryPoint.createNode(this, buildContext)
|
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
|
@Composable
|
||||||
override fun View(modifier: Modifier) {
|
override fun View(modifier: Modifier) {
|
||||||
Box(modifier = modifier) {
|
Box(modifier = modifier) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue