Scroll to Send button (#1386)

This commit is contained in:
Honza Rychnovský 2024-04-23 13:29:12 +02:00 committed by GitHub
parent 1ffbaf986f
commit 66ba050719
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 43 additions and 9 deletions

View File

@ -11,6 +11,7 @@ directly impact users rather than highlighting other key architectural updates.*
### Changed
- The Scan QR code screen has been reworked to align with the rest of the screens
- The Send Form screen scrolls to the Send button on very small devices after the memo is typed
### Fixed
- Sending zero funds is allowed only for shielded recipient address type

View File

@ -4,6 +4,7 @@ package co.electriccoin.zcash.ui.screen.send.view
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
@ -24,11 +25,16 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
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.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.testTag
@ -75,6 +81,7 @@ import co.electriccoin.zcash.ui.screen.send.model.AmountState
import co.electriccoin.zcash.ui.screen.send.model.MemoState
import co.electriccoin.zcash.ui.screen.send.model.RecipientAddressState
import co.electriccoin.zcash.ui.screen.send.model.SendStage
import kotlinx.coroutines.launch
import java.util.Locale
@Composable
@ -270,6 +277,8 @@ private fun SendForm(
val scrollState = rememberScrollState()
val (scrollToFeePixels, setScrollToFeePixels) = rememberSaveable { mutableIntStateOf(0) }
Column(
modifier =
Modifier
@ -330,6 +339,8 @@ private fun SendForm(
recipientAddressState.type !is AddressType.Transparent
)
),
scrollState = scrollState,
scrollTo = scrollToFeePixels
)
Spacer(
@ -341,7 +352,15 @@ private fun SendForm(
Spacer(modifier = Modifier.height(ZcashTheme.dimens.spacingDefault))
SendButton(amountState, memoState, monetarySeparators, onCreateZecSend, recipientAddressState, walletSnapshot)
SendButton(
amountState = amountState,
memoState = memoState,
monetarySeparators = monetarySeparators,
onCreateZecSend = onCreateZecSend,
recipientAddressState = recipientAddressState,
walletSnapshot = walletSnapshot,
setScrollToFeePixels = setScrollToFeePixels
)
}
}
@ -353,6 +372,7 @@ fun SendButton(
monetarySeparators: MonetarySeparators,
onCreateZecSend: (ZecSend) -> Unit,
recipientAddressState: RecipientAddressState,
setScrollToFeePixels: (Int) -> Unit,
walletSnapshot: WalletSnapshot,
) {
val context = LocalContext.current
@ -416,7 +436,11 @@ fun SendButton(
// TODO [#1047]: https://github.com/Electric-Coin-Company/zashi-android/issues/1047
Zatoshi(DEFAULT_LESS_THAN_FEE).toZecString()
),
textFontWeight = FontWeight.SemiBold
textFontWeight = FontWeight.SemiBold,
modifier =
Modifier.onGloballyPositioned {
setScrollToFeePixels(it.positionInRoot().y.toInt())
}
)
}
}
@ -584,12 +608,11 @@ fun SendFormAmountTextField(
),
keyboardActions =
KeyboardActions(
onDone = {
focusManager.clearFocus(true)
},
onNext = {
if (imeAction == ImeAction.Done) {
focusManager.clearFocus(true)
} else {
focusManager.moveFocus(FocusDirection.Down)
}
focusManager.moveFocus(FocusDirection.Down)
}
),
bringIntoViewRequester = bringIntoViewRequester,
@ -600,14 +623,18 @@ fun SendFormAmountTextField(
// TODO [#1259]: Send.Form screen Memo field stroke bubble style
// TODO [#1259]: https://github.com/Electric-Coin-Company/zashi-android/issues/1259
@OptIn(ExperimentalFoundationApi::class)
@Suppress("LongMethod")
@Suppress("LongMethod", "LongParameterList")
@Composable
fun SendFormMemoTextField(
focusManager: FocusManager,
isMemoFieldAvailable: Boolean,
memoState: MemoState,
setMemoState: (MemoState) -> Unit,
scrollState: ScrollState,
scrollTo: Int
) {
val scope = rememberCoroutineScope()
val bringIntoViewRequester = remember { BringIntoViewRequester() }
Column(
@ -664,8 +691,14 @@ fun SendFormMemoTextField(
),
keyboardActions =
KeyboardActions(
onNext = {
onDone = {
focusManager.clearFocus(true)
// Scroll down to make sure the Send button is visible on small screens
if (scrollTo > 0) {
scope.launch {
scrollState.animateScrollTo(scrollTo)
}
}
}
),
placeholder = {