From 0a66898cd2ac732069401fdeddc6021d30916345 Mon Sep 17 00:00:00 2001 From: huixing Date: Tue, 22 Mar 2022 20:16:55 +0800 Subject: [PATCH 1/2] fix continuous navigation jitter --- .../maskbook/wallet/route/WalletsRoute.kt | 9 ++- .../common/WalletIntroHostLegalDispatcher.kt | 81 +++++++++++++++++++ .../scenes/wallets/intro/WalletIntroHost.kt | 10 ++- 3 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/ui/scenes/wallets/common/WalletIntroHostLegalDispatcher.kt diff --git a/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/route/WalletsRoute.kt b/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/route/WalletsRoute.kt index 3484f63d..6678da2e 100644 --- a/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/route/WalletsRoute.kt +++ b/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/route/WalletsRoute.kt @@ -29,7 +29,9 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.platform.LocalContext @@ -66,6 +68,7 @@ import com.dimension.maskbook.wallet.ui.scenes.wallets.UnlockWalletDialog import com.dimension.maskbook.wallet.ui.scenes.wallets.WalletQrcodeScene import com.dimension.maskbook.wallet.ui.scenes.wallets.collectible.CollectibleDetailScene import com.dimension.maskbook.wallet.ui.scenes.wallets.common.MultiChainWalletDialog +import com.dimension.maskbook.wallet.ui.scenes.wallets.common.WalletIntroHostLegalDispatcher import com.dimension.maskbook.wallet.ui.scenes.wallets.create.CreateOrImportWalletScene import com.dimension.maskbook.wallet.ui.scenes.wallets.create.CreateType import com.dimension.maskbook.wallet.ui.scenes.wallets.intro.LegalScene @@ -214,12 +217,14 @@ fun TokenDetail( fun SwitchWalletAdd( navController: NavController, ) { + var type by remember { mutableStateOf(null) } + WalletIntroHostLegalDispatcher(navController, type) WalletSwitchAddModal( onCreate = { - navController.navigate(WalletRoute.WalletIntroHostLegal(CreateType.CREATE.name)) + type = CreateType.CREATE.name }, onImport = { - navController.navigate(WalletRoute.WalletIntroHostLegal(CreateType.IMPORT.name)) + type = CreateType.IMPORT.name }, ) } diff --git a/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/ui/scenes/wallets/common/WalletIntroHostLegalDispatcher.kt b/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/ui/scenes/wallets/common/WalletIntroHostLegalDispatcher.kt new file mode 100644 index 00000000..aa8ee3d5 --- /dev/null +++ b/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/ui/scenes/wallets/common/WalletIntroHostLegalDispatcher.kt @@ -0,0 +1,81 @@ +/* + * Mask-Android + * + * Copyright (C) 2022 DimensionDev and Contributors + * + * This file is part of Mask-Android. + * + * Mask-Android is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Mask-Android is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Mask-Android. If not, see . + */ +package com.dimension.maskbook.wallet.ui.scenes.wallets.common + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.platform.LocalContext +import androidx.navigation.NavController +import com.dimension.maskbook.common.ext.observeAsState +import com.dimension.maskbook.common.viewmodel.BiometricEnableViewModel +import com.dimension.maskbook.setting.export.SettingServices +import com.dimension.maskbook.wallet.route.WalletRoute +import kotlinx.coroutines.delay +import org.koin.androidx.compose.get +import org.koin.androidx.compose.getViewModel + +@Composable +fun WalletIntroHostLegalDispatcher( + navController: NavController, + originType: String?, +) { + if (originType.isNullOrBlank()) { + return + } + var enabled by remember { + mutableStateOf(false) + } + LaunchedEffect(originType) { + delay(10) + enabled = true + } + val type = originType.split(" ").first() + val repo = get() + val password by repo.paymentPassword.observeAsState(initial = null) + val enableBiometric by repo.biometricEnabled.observeAsState(initial = false) + val shouldShowLegalScene by repo.shouldShowLegalScene.observeAsState(initial = true) + val biometricEnableViewModel: BiometricEnableViewModel = getViewModel() + val context = LocalContext.current + + val next: () -> Unit = { + val route = if (password.isNullOrEmpty()) { + WalletRoute.WalletIntroHostPassword(type) + } else if (!enableBiometric && biometricEnableViewModel.isSupported(context)) { + WalletRoute.WalletIntroHostFaceId(type) + } else { + WalletRoute.CreateOrImportWallet(type) + } + navController.navigate(route) + } + + if (enabled) { + enabled = false + if (!shouldShowLegalScene) { + next() + } else { + navController.navigate(WalletRoute.WalletIntroHostLegal(type)) + } + } +} diff --git a/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/ui/scenes/wallets/intro/WalletIntroHost.kt b/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/ui/scenes/wallets/intro/WalletIntroHost.kt index 59fe053f..3cbf11e2 100644 --- a/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/ui/scenes/wallets/intro/WalletIntroHost.kt +++ b/wallet/src/androidMain/kotlin/com/dimension/maskbook/wallet/ui/scenes/wallets/intro/WalletIntroHost.kt @@ -22,12 +22,16 @@ package com.dimension.maskbook.wallet.ui.scenes.wallets.intro import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.platform.LocalClipboardManager import androidx.compose.ui.text.buildAnnotatedString import androidx.navigation.NavController import androidx.paging.compose.collectAsLazyPagingItems import com.dimension.maskbook.common.ext.observeAsState import com.dimension.maskbook.wallet.route.WalletRoute +import com.dimension.maskbook.wallet.ui.scenes.wallets.common.WalletIntroHostLegalDispatcher import com.dimension.maskbook.wallet.ui.scenes.wallets.create.CreateType import com.dimension.maskbook.wallet.ui.scenes.wallets.management.WalletBalancesScene import com.dimension.maskbook.wallet.viewmodel.wallets.WalletBalancesViewModel @@ -54,12 +58,14 @@ fun WalletIntroHost(navController: NavController) { val currentDWebData = dWebData if (currentWallet == null) { + var type by remember { mutableStateOf(null) } + WalletIntroHostLegalDispatcher(navController, type) WalletIntroScene( onCreate = { - navController.navigate(WalletRoute.WalletIntroHostLegal(CreateType.CREATE.name)) + type = "${CreateType.CREATE.name} ${System.currentTimeMillis()}" }, onImport = { - navController.navigate(WalletRoute.WalletIntroHostLegal(CreateType.IMPORT.name)) + type = "${CreateType.IMPORT.name} ${System.currentTimeMillis()}" }, onConnect = { navController.navigate(WalletRoute.SwitchWalletAddWalletConnect) From 88f6b36315ecda981a4cbf9ba1d7ceb35b666b93 Mon Sep 17 00:00:00 2001 From: huixing Date: Tue, 22 Mar 2022 20:31:14 +0800 Subject: [PATCH 2/2] fix start button invisible on dark mode --- .../kotlin/com/dimension/maskbook/entry/ui/scene/IntroScene.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/entry/src/androidMain/kotlin/com/dimension/maskbook/entry/ui/scene/IntroScene.kt b/entry/src/androidMain/kotlin/com/dimension/maskbook/entry/ui/scene/IntroScene.kt index cf1fbfa3..8f38e13f 100644 --- a/entry/src/androidMain/kotlin/com/dimension/maskbook/entry/ui/scene/IntroScene.kt +++ b/entry/src/androidMain/kotlin/com/dimension/maskbook/entry/ui/scene/IntroScene.kt @@ -202,6 +202,7 @@ fun IntroScene( fontWeight = FontWeight.W600, fontSize = 18.sp, lineHeight = 21.6.sp, + color = Color.Black.copy(alpha = 0.5f) ) } } else {