@@ -14,6 +14,7 @@ import androidx.lifecycle.viewModelScope
14
14
import androidx.lifecycle.viewmodel.initializer
15
15
import androidx.lifecycle.viewmodel.viewModelFactory
16
16
import androidx.navigation.NavBackStackEntry
17
+ import androidx.navigation.compose.NavHost
17
18
import com.stripe.android.link.LinkActivity.Companion.getArgs
18
19
import com.stripe.android.link.account.LinkAccountHolder
19
20
import com.stripe.android.link.account.LinkAccountManager
@@ -84,8 +85,7 @@ internal class LinkActivityViewModel @Inject constructor(
84
85
85
86
fun onVerificationSucceeded () {
86
87
viewModelScope.launch {
87
- val initialDestination = getInitialDestination()
88
- _linkScreenState .value = ScreenState .FullScreen (initialDestination)
88
+ _linkScreenState .value = buildFullScreenState()
89
89
}
90
90
}
91
91
@@ -138,16 +138,16 @@ internal class LinkActivityViewModel @Inject constructor(
138
138
}
139
139
}
140
140
141
- private fun handleBackPressed () {
142
- // navController?.let { navController ->
143
- // if (!navController.popBackStack()) {
144
- // dismissWithResult?.invoke(
145
- // LinkActivityResult.Canceled(
146
- // linkAccountUpdate = linkAccountManager.linkAccountUpdate
147
- // )
148
- // )
149
- // }
150
- // }
141
+ /* *
142
+ * [NavHost] handles back presses except for when backstack is empty, where it delegates
143
+ * to the container activity. [onBackPressed] will be triggered on these empty backstack cases.
144
+ */
145
+ fun handleBackPressed () {
146
+ dismissWithResult?.invoke(
147
+ LinkActivityResult . Canceled (
148
+ linkAccountUpdate = linkAccountManager.linkAccountUpdate
149
+ )
150
+ )
151
151
}
152
152
153
153
fun registerActivityForConfirmation (
@@ -158,8 +158,7 @@ internal class LinkActivityViewModel @Inject constructor(
158
158
}
159
159
160
160
fun navigate (screen : LinkScreen , clearStack : Boolean , launchSingleTop : Boolean = false) {
161
- Log .d(" LinkActivityViewModel" , " navigate: $screen , clearStack: $clearStack , launchSingleTop: $launchSingleTop " )
162
- val popupTo = if (clearStack) { // TODO if clear stack
161
+ val popupTo = if (clearStack) {
163
162
PopUpToBehavior .Current (
164
163
inclusive = true
165
164
)
@@ -172,13 +171,7 @@ internal class LinkActivityViewModel @Inject constructor(
172
171
}
173
172
174
173
fun goBack () {
175
- // if (navController?.popBackStack() == false) {
176
- // dismissWithResult?.invoke(
177
- // LinkActivityResult.Canceled(
178
- // linkAccountUpdate = linkAccountManager.linkAccountUpdate
179
- // )
180
- // )
181
- // }
174
+ navigationManager.tryNavigateBack()
182
175
}
183
176
184
177
fun changeEmail () {
@@ -218,38 +211,34 @@ internal class LinkActivityViewModel @Inject constructor(
218
211
AccountStatus .Verified ,
219
212
AccountStatus .SignedOut ,
220
213
AccountStatus .Error -> {
221
- _linkScreenState .value = ScreenState .FullScreen (
222
- getInitialDestination()
223
- )
214
+ _linkScreenState .value = buildFullScreenState()
224
215
}
225
216
AccountStatus .NeedsVerification ,
226
217
AccountStatus .VerificationStarted -> {
227
218
if (linkAccount != null && startWithVerificationDialog) {
228
219
_linkScreenState .value = ScreenState .VerificationDialog (linkAccount)
229
220
} else {
230
- _linkScreenState .value = ScreenState .FullScreen (
231
- getInitialDestination()
232
- )
221
+ _linkScreenState .value = buildFullScreenState()
233
222
}
234
223
}
235
224
}
236
225
}
237
226
238
-
239
- private suspend fun getInitialDestination (): LinkScreen {
227
+ private suspend fun buildFullScreenState (): ScreenState .FullScreen {
240
228
val accountStatus = linkAccountManager.accountStatus.first()
241
- val screen = when (accountStatus) {
242
- AccountStatus .Verified -> {
243
- LinkScreen .Wallet
244
- }
245
- AccountStatus .NeedsVerification , AccountStatus .VerificationStarted -> {
246
- LinkScreen .Verification
247
- }
248
- AccountStatus .SignedOut , AccountStatus .Error -> {
249
- LinkScreen .SignUp
229
+ return ScreenState .FullScreen (
230
+ initialDestination = when (accountStatus) {
231
+ AccountStatus .Verified -> {
232
+ LinkScreen .Wallet
233
+ }
234
+ AccountStatus .NeedsVerification , AccountStatus .VerificationStarted -> {
235
+ LinkScreen .Verification
236
+ }
237
+ AccountStatus .SignedOut , AccountStatus .Error -> {
238
+ LinkScreen .SignUp
239
+ }
250
240
}
251
- }
252
- return screen
241
+ )
253
242
}
254
243
255
244
private suspend fun handleAccountError () {
0 commit comments