[#1206] Clear focus on Send Form

* [#1206] Clear focus on Send Form

- Closes #1206
This commit is contained in:
Honza Rychnovský 2024-01-28 01:28:27 +01:00 committed by GitHub
parent 3240c3baa8
commit b79739db0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import cash.z.ecc.android.sdk.model.WalletBalance
import cash.z.ecc.android.sdk.model.Zatoshi
@ -105,6 +106,7 @@ class SendViewTestSetup(
available = Zatoshi(Zatoshi.MAX_INCLUSIVE.div(100))
)
),
focusManager = LocalFocusManager.current,
sendStage = sendStage,
sendArgumentsWrapper = initialSendArgumentWrapper,
onSendStageChange = setSendStage,

View File

@ -1,5 +1,6 @@
package co.electriccoin.zcash.ui.screen.send.integration
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.StateRestorationTester
import androidx.compose.ui.test.junit4.createComposeRule
@ -61,6 +62,7 @@ class SendViewIntegrationTest {
restorationTester.setContent {
WrapSend(
sendArgumentsWrapper = null,
focusManager = LocalFocusManager.current,
synchronizer = synchronizer,
walletSnapshot = walletSnapshot,
spendingKey = spendingKey,

View File

@ -132,7 +132,7 @@ fun Home(
)
TabRow(
selectedTabIndex = pagerState.currentPage,
// Don't use the predefined divider, as it's fixed position is below the tabs bar
// Don't use the predefined divider, as its fixed position is below the tabs bar
divider = {},
indicator = { tabPositions ->
TabRowDefaults.Indicator(

View File

@ -11,6 +11,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.focus.FocusManager
import androidx.compose.ui.platform.LocalFocusManager
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.model.UnifiedSpendingKey
@ -18,8 +20,10 @@ import cash.z.ecc.android.sdk.model.ZecSend
import cash.z.ecc.sdk.extension.send
import co.electriccoin.zcash.spackle.Twig
import co.electriccoin.zcash.ui.common.model.WalletSnapshot
import co.electriccoin.zcash.ui.common.viewmodel.HomeViewModel
import co.electriccoin.zcash.ui.common.viewmodel.WalletViewModel
import co.electriccoin.zcash.ui.design.component.CircularScreenProgressIndicator
import co.electriccoin.zcash.ui.screen.home.HomeScreenIndex
import co.electriccoin.zcash.ui.screen.send.ext.Saver
import co.electriccoin.zcash.ui.screen.send.model.SendArgumentsWrapper
import co.electriccoin.zcash.ui.screen.send.model.SendStage
@ -46,11 +50,21 @@ internal fun WrapSend(
val spendingKey = walletViewModel.spendingKey.collectAsStateWithLifecycle().value
val homeViewModel by activity.viewModels<HomeViewModel>()
val focusManager = LocalFocusManager.current
if (homeViewModel.screenIndex.collectAsStateWithLifecycle().value != HomeScreenIndex.SEND) {
// Clear focus on Send Form text fields
focusManager.clearFocus(true)
}
WrapSend(
sendArgumentsWrapper,
synchronizer,
walletSnapshot,
spendingKey,
focusManager,
goToQrScanner,
goBack,
goBalances,
@ -67,6 +81,7 @@ internal fun WrapSend(
synchronizer: Synchronizer?,
walletSnapshot: WalletSnapshot?,
spendingKey: UnifiedSpendingKey?,
focusManager: FocusManager,
goToQrScanner: () -> Unit,
goBack: () -> Unit,
goBalances: () -> Unit,
@ -116,6 +131,7 @@ internal fun WrapSend(
onSendStageChange = setSendStage,
zecSend = zecSend,
onZecSendChange = setZecSend,
focusManager = focusManager,
onBack = onBackAction,
onSettings = goSettings,
onCreateAndSend = {

View File

@ -29,6 +29,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.FocusManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
@ -84,6 +85,7 @@ private fun PreviewSendForm() {
GradientSurface {
Send(
walletSnapshot = WalletSnapshotFixture.new(),
focusManager = LocalFocusManager.current,
sendArgumentsWrapper = null,
sendStage = SendStage.Form,
onSendStageChange = {},
@ -164,6 +166,7 @@ fun Send(
onSendStageChange: (SendStage) -> Unit,
zecSend: ZecSend?,
onZecSendChange: (ZecSend) -> Unit,
focusManager: FocusManager,
onBack: () -> Unit,
onSettings: () -> Unit,
onCreateAndSend: (ZecSend) -> Unit,
@ -182,6 +185,7 @@ fun Send(
walletSnapshot = walletSnapshot,
sendArgumentsWrapper = sendArgumentsWrapper,
onBack = onBack,
focusManager = focusManager,
sendStage = sendStage,
onSendStageChange = onSendStageChange,
zecSend = zecSend,
@ -236,6 +240,7 @@ private fun SendTopAppBar(
@Composable
private fun SendMainContent(
walletSnapshot: WalletSnapshot,
focusManager: FocusManager,
sendArgumentsWrapper: SendArgumentsWrapper?,
zecSend: ZecSend?,
onZecSendChange: (ZecSend) -> Unit,
@ -258,6 +263,7 @@ private fun SendMainContent(
onSendStageChange(SendStage.Confirmation)
onZecSendChange(it)
},
focusManager = focusManager,
onQrScannerOpen = onQrScannerOpen,
goBalances = goBalances,
hasCameraFeature = hasCameraFeature,
@ -306,6 +312,7 @@ private fun SendMainContent(
@Composable
private fun SendForm(
walletSnapshot: WalletSnapshot,
focusManager: FocusManager,
sendArgumentsWrapper: SendArgumentsWrapper?,
previousZecSend: ZecSend?,
onCreateZecSend: (ZecSend) -> Unit,
@ -319,7 +326,6 @@ private fun SendForm(
// TODO [#1171]: https://github.com/Electric-Coin-Company/zashi-android/issues/1171
val monetarySeparators = MonetarySeparators.current(Locale.US)
val allowedCharacters = ZecString.allowedCharacters(monetarySeparators)
val focusManager = LocalFocusManager.current
// TODO [#809]: Fix ZEC balance on Send screen
// TODO [#809]: https://github.com/Electric-Coin-Company/zashi-android/issues/809