@@ -2,6 +2,7 @@ package com.flipcash.app.messenger
22
33import android.os.Parcelable
44import androidx.compose.runtime.Composable
5+ import androidx.compose.runtime.CompositionLocalProvider
56import androidx.compose.runtime.LaunchedEffect
67import androidx.compose.runtime.getValue
78import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -10,17 +11,21 @@ import androidx.navigation3.runtime.NavKey
1011import androidx.navigation3.runtime.entryProvider
1112import com.flipcash.app.core.AppRoute
1213import com.flipcash.app.core.chat.ChatIdentifier
14+ import com.flipcash.app.core.chat.ChatSendResult
1315import com.flipcash.app.core.chat.ChatStep
1416import com.flipcash.app.messenger.internal.ChatViewModel
1517import com.flipcash.app.messenger.internal.screens.MessengerScreen
1618import com.getcode.navigation.annotatedEntry
17- import com.getcode.navigation.flowAnnotatedEntry
1819import com.getcode.navigation.core.LocalCodeNavigator
1920import com.getcode.navigation.flow.FlowHost
21+ import com.getcode.navigation.flow.LocalOuterCodeNavigator
2022import com.getcode.navigation.flow.flowSharedViewModel
2123import com.getcode.navigation.flow.rememberFlowNavigator
2224import com.getcode.navigation.flow.rememberInitialStack
25+ import com.getcode.navigation.results.NavResultOrCanceled
2326import com.getcode.navigation.results.NavResultStateRegistry
27+ import com.getcode.navigation.results.navigateForResult
28+ import com.getcode.navigation.results.resultBackNavigator
2429import kotlinx.coroutines.flow.filterIsInstance
2530import kotlinx.coroutines.flow.map
2631
@@ -46,7 +51,7 @@ private fun chatEntryProvider(
4651 annotatedEntry<ChatStep .Conversation > {
4752 FlowConversationScreen (identifier)
4853 }
49- flowAnnotatedEntry <ChatStep .AmountEntry > {
54+ annotatedEntry <ChatStep .AmountEntry > {
5055 FlowAmountEntryScreen ()
5156 }
5257}
@@ -55,6 +60,7 @@ private fun chatEntryProvider(
5560private fun FlowConversationScreen (identifier : ChatIdentifier ) {
5661 val viewModel = flowSharedViewModel<ChatViewModel >()
5762 val flowNavigator = rememberFlowNavigator<ChatStep , Parcelable >()
63+ val navigator = LocalCodeNavigator .current
5864
5965 LaunchedEffect (viewModel, identifier) {
6066 viewModel.dispatchEvent(ChatViewModel .Event .OnChatOpened (identifier))
@@ -64,7 +70,11 @@ private fun FlowConversationScreen(identifier: ChatIdentifier) {
6470 viewModel.eventFlow
6571 .filterIsInstance<ChatViewModel .Event .NavigateToAmountEntry >()
6672 .collect {
67- flowNavigator.navigateTo(ChatStep .AmountEntry )
73+ navigator.navigateForResult<ChatSendResult >(ChatStep .AmountEntry ) { result ->
74+ if (result is NavResultOrCanceled .ReturnValue ) {
75+ viewModel.dispatchEvent(ChatViewModel .Event .OnStartMessageInput )
76+ }
77+ }
6878 }
6979 }
7080
@@ -85,14 +95,20 @@ private fun FlowAmountEntryScreen() {
8595 val viewModel = flowSharedViewModel<ChatViewModel >()
8696 val state by viewModel.stateFlow.collectAsStateWithLifecycle()
8797 val flowNavigator = rememberFlowNavigator<ChatStep , Parcelable >()
98+ val resultBack = resultBackNavigator<ChatSendResult >()
8899
89- ChatAmountEntryContent (
90- amountDelegate = viewModel.amountDelegate,
91- resolveState = state.resolveState,
92- token = state.token,
93- eventFlow = viewModel.eventFlow,
94- onConfirm = { viewModel.dispatchEvent(ChatViewModel .Event .OnConfirmRequested ) },
95- onSendComplete = { flowNavigator.back() },
96- onExit = { flowNavigator.back() }
97- )
100+ // Re-provide the outer navigator so ChatAmountEntryContent can push
101+ // app-level routes (RegionSelection, TokenSelection, etc.)
102+ val outerNavigator = LocalOuterCodeNavigator .current
103+ CompositionLocalProvider (LocalCodeNavigator provides outerNavigator) {
104+ ChatAmountEntryContent (
105+ amountDelegate = viewModel.amountDelegate,
106+ resolveState = state.resolveState,
107+ token = state.token,
108+ eventFlow = viewModel.eventFlow,
109+ onConfirm = { viewModel.dispatchEvent(ChatViewModel .Event .OnConfirmRequested ) },
110+ onSendComplete = { resultBack.returnValue(ChatSendResult ) },
111+ onExit = { flowNavigator.back() },
112+ )
113+ }
98114}
0 commit comments