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

View File

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

View File

@ -132,7 +132,7 @@ fun Home(
) )
TabRow( TabRow(
selectedTabIndex = pagerState.currentPage, 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 = {}, divider = {},
indicator = { tabPositions -> indicator = { tabPositions ->
TabRowDefaults.Indicator( TabRowDefaults.Indicator(

View File

@ -11,6 +11,8 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.focus.FocusManager
import androidx.compose.ui.platform.LocalFocusManager
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
import cash.z.ecc.android.sdk.Synchronizer import cash.z.ecc.android.sdk.Synchronizer
import cash.z.ecc.android.sdk.model.UnifiedSpendingKey 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 cash.z.ecc.sdk.extension.send
import co.electriccoin.zcash.spackle.Twig import co.electriccoin.zcash.spackle.Twig
import co.electriccoin.zcash.ui.common.model.WalletSnapshot 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.common.viewmodel.WalletViewModel
import co.electriccoin.zcash.ui.design.component.CircularScreenProgressIndicator 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.ext.Saver
import co.electriccoin.zcash.ui.screen.send.model.SendArgumentsWrapper import co.electriccoin.zcash.ui.screen.send.model.SendArgumentsWrapper
import co.electriccoin.zcash.ui.screen.send.model.SendStage import co.electriccoin.zcash.ui.screen.send.model.SendStage
@ -46,11 +50,21 @@ internal fun WrapSend(
val spendingKey = walletViewModel.spendingKey.collectAsStateWithLifecycle().value 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( WrapSend(
sendArgumentsWrapper, sendArgumentsWrapper,
synchronizer, synchronizer,
walletSnapshot, walletSnapshot,
spendingKey, spendingKey,
focusManager,
goToQrScanner, goToQrScanner,
goBack, goBack,
goBalances, goBalances,
@ -67,6 +81,7 @@ internal fun WrapSend(
synchronizer: Synchronizer?, synchronizer: Synchronizer?,
walletSnapshot: WalletSnapshot?, walletSnapshot: WalletSnapshot?,
spendingKey: UnifiedSpendingKey?, spendingKey: UnifiedSpendingKey?,
focusManager: FocusManager,
goToQrScanner: () -> Unit, goToQrScanner: () -> Unit,
goBack: () -> Unit, goBack: () -> Unit,
goBalances: () -> Unit, goBalances: () -> Unit,
@ -116,6 +131,7 @@ internal fun WrapSend(
onSendStageChange = setSendStage, onSendStageChange = setSendStage,
zecSend = zecSend, zecSend = zecSend,
onZecSendChange = setZecSend, onZecSendChange = setZecSend,
focusManager = focusManager,
onBack = onBackAction, onBack = onBackAction,
onSettings = goSettings, onSettings = goSettings,
onCreateAndSend = { onCreateAndSend = {

View File

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