Merge pull request #3984 from element-hq/feature/fga/navigation_from_notification_2
navigation : clear backstack when opening room from outer node
This commit is contained in:
commit
de4c291037
2 changed files with 48 additions and 10 deletions
|
|
@ -20,11 +20,20 @@ import androidx.lifecycle.repeatOnLifecycle
|
||||||
import com.bumble.appyx.core.composable.PermanentChild
|
import com.bumble.appyx.core.composable.PermanentChild
|
||||||
import com.bumble.appyx.core.lifecycle.subscribe
|
import com.bumble.appyx.core.lifecycle.subscribe
|
||||||
import com.bumble.appyx.core.modality.BuildContext
|
import com.bumble.appyx.core.modality.BuildContext
|
||||||
|
import com.bumble.appyx.core.navigation.NavElements
|
||||||
|
import com.bumble.appyx.core.navigation.NavKey
|
||||||
import com.bumble.appyx.core.navigation.model.permanent.PermanentNavModel
|
import com.bumble.appyx.core.navigation.model.permanent.PermanentNavModel
|
||||||
import com.bumble.appyx.core.node.Node
|
import com.bumble.appyx.core.node.Node
|
||||||
import com.bumble.appyx.core.plugin.Plugin
|
import com.bumble.appyx.core.plugin.Plugin
|
||||||
import com.bumble.appyx.core.plugin.plugins
|
import com.bumble.appyx.core.plugin.plugins
|
||||||
import com.bumble.appyx.navmodel.backstack.BackStack
|
import com.bumble.appyx.navmodel.backstack.BackStack
|
||||||
|
import com.bumble.appyx.navmodel.backstack.BackStack.State.ACTIVE
|
||||||
|
import com.bumble.appyx.navmodel.backstack.BackStack.State.CREATED
|
||||||
|
import com.bumble.appyx.navmodel.backstack.BackStack.State.STASHED
|
||||||
|
import com.bumble.appyx.navmodel.backstack.BackStackElement
|
||||||
|
import com.bumble.appyx.navmodel.backstack.BackStackElements
|
||||||
|
import com.bumble.appyx.navmodel.backstack.operation.BackStackOperation
|
||||||
|
import com.bumble.appyx.navmodel.backstack.operation.Push
|
||||||
import com.bumble.appyx.navmodel.backstack.operation.pop
|
import com.bumble.appyx.navmodel.backstack.operation.pop
|
||||||
import com.bumble.appyx.navmodel.backstack.operation.push
|
import com.bumble.appyx.navmodel.backstack.operation.push
|
||||||
import com.bumble.appyx.navmodel.backstack.operation.replace
|
import com.bumble.appyx.navmodel.backstack.operation.replace
|
||||||
|
|
@ -312,7 +321,7 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onForwardedToSingleRoom(roomId: RoomId) {
|
override fun onForwardedToSingleRoom(roomId: RoomId) {
|
||||||
coroutineScope.launch { attachRoom(roomId.toRoomIdOrAlias()) }
|
coroutineScope.launch { attachRoom(roomId.toRoomIdOrAlias(), clearBackstack = false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPermalinkClick(data: PermalinkData, pushToBackstack: Boolean) {
|
override fun onPermalinkClick(data: PermalinkData, pushToBackstack: Boolean) {
|
||||||
|
|
@ -472,21 +481,21 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
serverNames: List<String> = emptyList(),
|
serverNames: List<String> = emptyList(),
|
||||||
trigger: JoinedRoom.Trigger? = null,
|
trigger: JoinedRoom.Trigger? = null,
|
||||||
eventId: EventId? = null,
|
eventId: EventId? = null,
|
||||||
|
clearBackstack: Boolean,
|
||||||
) {
|
) {
|
||||||
waitForNavTargetAttached { navTarget ->
|
waitForNavTargetAttached { navTarget ->
|
||||||
navTarget is NavTarget.RoomList
|
navTarget is NavTarget.RoomList
|
||||||
}
|
}
|
||||||
attachChild<RoomFlowNode> {
|
attachChild<RoomFlowNode> {
|
||||||
backstack.push(
|
val roomNavTarget = NavTarget.Room(
|
||||||
NavTarget.Room(
|
roomIdOrAlias = roomIdOrAlias,
|
||||||
roomIdOrAlias = roomIdOrAlias,
|
serverNames = serverNames,
|
||||||
serverNames = serverNames,
|
trigger = trigger,
|
||||||
trigger = trigger,
|
initialElement = RoomNavigationTarget.Messages(
|
||||||
initialElement = RoomNavigationTarget.Messages(
|
focusedEventId = eventId
|
||||||
focusedEventId = eventId
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
backstack.accept(AttachRoomOperation(roomNavTarget, clearBackstack))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -531,3 +540,31 @@ class LoggedInFlowNode @AssistedInject constructor(
|
||||||
@Assisted plugins: List<Plugin>,
|
@Assisted plugins: List<Plugin>,
|
||||||
) : Node(buildContext, plugins = plugins)
|
) : Node(buildContext, plugins = plugins)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
private class AttachRoomOperation(
|
||||||
|
val roomTarget: LoggedInFlowNode.NavTarget.Room,
|
||||||
|
val clearBackstack: Boolean,
|
||||||
|
) : BackStackOperation<LoggedInFlowNode.NavTarget> {
|
||||||
|
override fun isApplicable(elements: NavElements<LoggedInFlowNode.NavTarget, BackStack.State>) = true
|
||||||
|
|
||||||
|
override fun invoke(elements: BackStackElements<LoggedInFlowNode.NavTarget>): BackStackElements<LoggedInFlowNode.NavTarget> {
|
||||||
|
return if (clearBackstack) {
|
||||||
|
// Makes sure the room list target is alone in the backstack and stashed
|
||||||
|
elements.mapNotNull { element ->
|
||||||
|
if (element.key.navTarget == LoggedInFlowNode.NavTarget.RoomList) {
|
||||||
|
element.transitionTo(STASHED, this)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} + BackStackElement(
|
||||||
|
key = NavKey(roomTarget),
|
||||||
|
fromState = CREATED,
|
||||||
|
targetState = ACTIVE,
|
||||||
|
operation = this
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Push<LoggedInFlowNode.NavTarget>(roomTarget).invoke(elements)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,7 @@ class RootFlowNode @AssistedInject constructor(
|
||||||
trigger = JoinedRoom.Trigger.MobilePermalink,
|
trigger = JoinedRoom.Trigger.MobilePermalink,
|
||||||
serverNames = permalinkData.viaParameters,
|
serverNames = permalinkData.viaParameters,
|
||||||
eventId = permalinkData.eventId,
|
eventId = permalinkData.eventId,
|
||||||
|
clearBackstack = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is PermalinkData.UserLink -> {
|
is PermalinkData.UserLink -> {
|
||||||
|
|
@ -318,7 +319,7 @@ class RootFlowNode @AssistedInject constructor(
|
||||||
.apply {
|
.apply {
|
||||||
when (deeplinkData) {
|
when (deeplinkData) {
|
||||||
is DeeplinkData.Root -> Unit // The room list will always be shown, observing FtueState
|
is DeeplinkData.Root -> Unit // The room list will always be shown, observing FtueState
|
||||||
is DeeplinkData.Room -> attachRoom(deeplinkData.roomId.toRoomIdOrAlias())
|
is DeeplinkData.Room -> attachRoom(deeplinkData.roomId.toRoomIdOrAlias(), clearBackstack = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue