Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.flipcash.app.android.BuildConfig
import com.flipcash.app.bill.customization.BillPlaygroundScaffold
import com.flipcash.app.core.AppRoute
import com.flipcash.app.core.LocalUserManager
import com.flipcash.app.core.extensions.navigateTo
import com.flipcash.app.core.extensions.navigateAll
import com.flipcash.app.core.navigation.DeeplinkAction
import com.flipcash.app.core.verification.email.LocalEmailCodeChannel
import com.flipcash.app.featureflags.FeatureFlag
Expand Down Expand Up @@ -258,7 +258,7 @@ internal fun App(
} else false

if (!delivered) {
codeNavigator.navigateTo(action.routes)
codeNavigator.navigateAll(action.routes)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.flipcash.app.currency.RegionSelectionScreen
import com.flipcash.app.deposit.DepositDestinationScreen
import com.flipcash.app.deposit.DepositFlowScreen
import com.flipcash.app.discovery.TokenDiscoveryScreen
import com.flipcash.app.discovery.TokenDiscoverySheet
import com.flipcash.app.internal.ui.navigation.decorators.rememberNavMessagingEntryDecorator
import com.flipcash.app.lab.LabsScreen
import com.flipcash.app.lab.StandaloneLabsScreen
Expand Down Expand Up @@ -100,7 +99,7 @@ fun appEntryProvider(
annotatedEntry<AppRoute.Sheets.ShareApp> { ShareAppScreen() }
annotatedEntry<AppRoute.Sheets.Menu> { MenuScreen() }
annotatedEntry<AppRoute.Sheets.Lab> { StandaloneLabsScreen() }
annotatedEntry<AppRoute.Sheets.TokenDiscovery> { TokenDiscoverySheet() }


// Tokens
annotatedEntry<AppRoute.Token.Info> { key ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.flipcash.app.android.R
import com.flipcash.app.core.LocalUserManager
import com.flipcash.app.core.AppRoute
import com.flipcash.app.core.navigation.DeeplinkAction
import com.flipcash.app.core.extensions.navigateTo
import com.flipcash.app.core.extensions.navigateAll
import com.flipcash.app.core.extensions.resolveRoutes
import com.flipcash.app.router.LocalRouter
import com.flipcash.app.router.Router
Expand Down Expand Up @@ -128,7 +128,7 @@ internal fun MainRoot(deepLink: () -> DeepLink?) {
if (!current.startsWith(target)) {
navigator.replaceAll(launch.baseRoutes)
if (launch.deeplinkRoutes.isNotEmpty()) {
navigator.navigateTo(launch.deeplinkRoutes)
navigator.navigateAll(launch.deeplinkRoutes)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ sealed interface AppRoute : NavKey, Parcelable {
@Serializable
@Parcelize
data class Sheet(
val initialRoute: Sheets,
val initialRoute: AppRoute,
val innerRoutes: List<AppRoute> = emptyList(),
) : Main, com.getcode.navigation.Sheet
}
Expand Down Expand Up @@ -114,9 +114,6 @@ sealed interface AppRoute : NavKey, Parcelable {
@Serializable
data object Lab : Sheets

@Serializable
data object TokenDiscovery: Sheets

@Serializable
data object ShareApp : Sheets
}
Expand Down Expand Up @@ -196,8 +193,6 @@ sealed interface AppRoute : NavKey, Parcelable {
@Serializable
data object MyAccount : Menu
@Serializable
data class Deposit(val mint: Mint) : Menu
@Serializable
data object BackupKey : Menu
@Serializable
data object AppSettings : Menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,24 @@ import com.getcode.navigation.core.CodeNavigator
import com.getcode.navigation.core.NavOptions

/**
* Navigate to a route, wrapping [AppRoute.Sheets] in [AppRoute.Main.Sheet]
* so the [ModalBottomSheetSceneStrategy] renders them in a bottom sheet.
* Open any [AppRoute] as a modal bottom sheet.
*
* Wraps [route] in [AppRoute.Main.Sheet] and navigates to it. If a sheet is already
* open, the current sheet is animated closed before the new one opens.
*/
fun CodeNavigator.navigateTo(route: NavKey, options: NavOptions = NavOptions()) {
val destination = if (route is AppRoute.Sheets) {
AppRoute.Main.Sheet(route)
} else {
route
}
val needsSheet = destination is AppRoute.Main.Sheet
fun CodeNavigator.openAsSheet(route: AppRoute, innerRoutes: List<AppRoute> = emptyList()) {
val destination = AppRoute.Main.Sheet(route, innerRoutes)
val hasSheet = backStack.any { it is AppRoute.Main.Sheet }

if (hasSheet && needsSheet) {
if (hasSheet) {
pendingSheetDismiss = {
Snapshot.withMutableSnapshot {
sheetGeneration++
navigate(destination, options)
navigate(destination)
}
}
} else {
navigate(destination, options)
navigate(destination)
}
}

Expand All @@ -37,20 +34,16 @@ fun CodeNavigator.navigateTo(route: NavKey, options: NavOptions = NavOptions())
* so they appear inside the sheet rather than on the root backstack.
*
* If a sheet is already open and the new routes include a sheet, the current sheet
* is animated closed before the new one opens. For direct navigation without
* dismiss handling, use [navigate] directly.
* is animated closed before the new one opens.
*/
fun CodeNavigator.navigateTo(routes: List<NavKey>, options: NavOptions = NavOptions()) {
fun CodeNavigator.navigateAll(routes: List<NavKey>, options: NavOptions = NavOptions()) {
if (routes.isEmpty()) return

val resolved = resolveRoutes(routes)
val needsSheet = resolved.any { it is AppRoute.Main.Sheet }
val hasSheet = backStack.any { it is AppRoute.Main.Sheet }

if (hasSheet && needsSheet) {
// Animate the current sheet down, then open the new one.
// The callback is invoked by ModalBottomSheetScene after the dismiss
// animation completes and the old entry is removed from the backstack.
pendingSheetDismiss = {
Snapshot.withMutableSnapshot {
sheetGeneration++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun VerificationFlowScreen(
FlowHost(
initialStack = initialStack,
resultStateRegistry = resultStateRegistry,
onExit = { reason ->
onExit = { reason, _ ->
val result: VerificationResult = when (reason) {
is FlowExitReason.Completed -> reason.result
FlowExitReason.Canceled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fun CurrencyCreatorFlowScreen(
FlowHost(
initialStack = initialStack,
resultStateRegistry = resultStateRegistry,
onExit = { reason ->
onExit = { reason, _ ->
val result: CurrencyCreatorResult = when (reason) {
is FlowExitReason.Completed -> reason.result
FlowExitReason.Canceled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,26 @@ fun DepositFlowScreen(
FlowHost(
initialStack = initialStack,
resultStateRegistry = resultStateRegistry,
onExit = { reason ->
onExit = { reason, isSheetRoot ->
val result: DepositResult = when (reason) {
is FlowExitReason.Completed -> reason.result
FlowExitReason.Canceled,
FlowExitReason.BackedOutOfRoot -> DepositResult.Canceled
}
outerNavigator.deliverFlowResult(
route = route,
value = NavResultOrCanceled.ReturnValue(result),
)
when (result) {
DepositResult.Success -> {
outerNavigator.popUntil { it == AppRoute.Sheets.Menu }
}
DepositResult.Canceled -> {
outerNavigator.pop()
if (isSheetRoot) {
outerNavigator.pop()
} else {
outerNavigator.deliverFlowResult(
route = route,
value = NavResultOrCanceled.ReturnValue(result),
)
when (result) {
DepositResult.Success -> {
outerNavigator.popUntil { it == AppRoute.Sheets.Menu }
}
DepositResult.Canceled -> {
outerNavigator.pop()
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand All @@ -22,46 +23,34 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach


@Composable
fun TokenDiscoverySheet() {
val navigator = LocalCodeNavigator.current
val viewModel = hiltViewModel<TokenDiscoveryViewModel>()

Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
AppBarWithTitle(
title = stringResource(R.string.title_discoverCurrencies),
isInModal = true,
titleAlignment = Alignment.CenterHorizontally,
endContent = {
AppBarDefaults.Close { navigator.hide() }
},
)
TokenDiscoveryScreen(viewModel)
}

TokenDiscoveryEventHandler(viewModel, navigator)
}

@Composable
fun TokenDiscoveryScreen() {
val navigator = LocalCodeNavigator.current
val viewModel = hiltViewModel<TokenDiscoveryViewModel>()
val isSheetRoot = remember { navigator.backStack.size <= 1 }

Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
AppBarWithTitle(
title = stringResource(R.string.title_discoverCurrencies),
isInModal = true,
titleAlignment = Alignment.CenterHorizontally,
backButton = true,
onBackIconClicked = { navigator.pop() },
)
if (isSheetRoot) {
AppBarWithTitle(
title = stringResource(R.string.title_discoverCurrencies),
isInModal = true,
titleAlignment = Alignment.CenterHorizontally,
endContent = {
AppBarDefaults.Close { navigator.hide() }
},
)
} else {
AppBarWithTitle(
title = stringResource(R.string.title_discoverCurrencies),
isInModal = true,
titleAlignment = Alignment.CenterHorizontally,
backButton = true,
onBackIconClicked = { navigator.pop() },
)
}
TokenDiscoveryScreen(viewModel)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.flipcash.app.core.AppRoute
import com.flipcash.app.core.extensions.navigateTo
import com.flipcash.app.featureflags.FlagOption
import com.flipcash.app.featureflags.LocalFeatureFlags
import com.flipcash.app.featureflags.message
Expand Down Expand Up @@ -122,7 +121,7 @@ internal fun LabsScreenContent(viewModel: LabsScreenViewModel) {
headline = stringResource(R.string.subtitle_settingsUserFlags),
icon = rememberVectorPainter(Icons.Default.Token),
) {
navigator.navigateTo(AppRoute.UserFlags)
navigator.navigate(AppRoute.UserFlags)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.hilt.navigation.compose.hiltViewModel
import com.flipcash.app.core.AppRoute
import com.flipcash.app.core.extensions.navigateTo
import com.flipcash.app.core.extensions.openAsSheet
import com.flipcash.app.login.internal.LoginRouterScreenContent
import com.getcode.navigation.core.LocalCodeNavigator
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -83,7 +83,7 @@ fun LoginRouter(
login = { navigator.push(AppRoute.Onboarding.SeedInput) },
isLabsOpen = state.betaOptionsVisible,
onLogoTapped = { vm.dispatchEvent(LoginViewModel.Event.OnLogoTapped) },
openBetaFlags = { navigator.navigateTo(AppRoute.Sheets.Lab) }
openBetaFlags = { navigator.openAsSheet(AppRoute.Sheets.Lab) }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import com.getcode.utils.ErrorUtils
import com.kik.kikx.kikcodes.implementation.KikCodeResult
import dev.theolm.rinku.DeepLink
import timber.log.Timber
import com.flipcash.app.core.extensions.navigateTo
import com.flipcash.app.core.extensions.navigateAll
import com.flipcash.app.core.extensions.openAsSheet
import com.flipcash.app.core.navigation.DeeplinkType
import com.getcode.manager.BottomBarAction

Expand Down Expand Up @@ -95,17 +96,17 @@ internal fun Scanner() {
BottomBarAction(
text = context.getString(R.string.action_discoverCurrencies)
) {
navigator.navigateTo(AppRoute.Sheets.TokenDiscovery)
navigator.openAsSheet(AppRoute.Token.Discovery)
},
),
showCancel = true,
)
return@BillContainer
return@BillContainer
}
}
else -> Unit
}
navigator.navigateTo(it.screen)
navigator.openAsSheet(it.screen)
},
scannerView = {
CodeScanner(
Expand Down Expand Up @@ -143,7 +144,7 @@ internal fun Scanner() {
else -> emptyList()
}
if (routes.isNotEmpty()) {
navigator.navigateTo(routes)
navigator.navigateAll(routes)
}
}
is DeeplinkType.Login -> Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ sealed class ScannerDecorItem(val screen: AppRoute) {
data object Wallet : ScannerDecorItem(AppRoute.Sheets.Wallet)
data object Menu : ScannerDecorItem(AppRoute.Sheets.Menu)
data object Logo: ScannerDecorItem(AppRoute.Sheets.ShareApp)
data object Discover: ScannerDecorItem(AppRoute.Sheets.TokenDiscovery)
data object Discover: ScannerDecorItem(AppRoute.Token.Discovery)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun SwapFlowScreen(
FlowHost<SwapStep, SwapResult>(
initialStack = initialStack,
resultStateRegistry = resultStateRegistry,
onExit = { reason ->
onExit = { reason, _ ->
val result = when (reason) {
is FlowExitReason.Completed -> reason.result
FlowExitReason.Canceled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun WithdrawalFlowScreen(
FlowHost(
initialStack = initialStack,
resultStateRegistry = resultStateRegistry,
onExit = { reason ->
onExit = { reason, _ ->
val result: WithdrawalResult = when (reason) {
is FlowExitReason.Completed -> reason.result
FlowExitReason.Canceled,
Expand Down
Loading
Loading