Skip to content

Commit

Permalink
fix(suite-native): send form scroll so the whole amount input is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
PeKne committed Oct 1, 2024
1 parent 8656b3c commit 56abb30
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
12 changes: 11 additions & 1 deletion suite-native/module-send/src/components/AmountInputs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSharedValue, withTiming } from 'react-native-reanimated';
import { useRef, useState } from 'react';
import { TextInput } from 'react-native';
import { NativeSyntheticEvent, TextInput, TextInputFocusEventData } from 'react-native';
import { useSelector } from 'react-redux';

import { VStack, HStack, Box, Text } from '@suite-native/atoms';
Expand All @@ -13,6 +13,7 @@ import {
import { Translation } from '@suite-native/intl';
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';
import { analytics, EventType } from '@suite-native/analytics';
import { useScrollView } from '@suite-native/navigation';

import { CryptoAmountInput } from './CryptoAmountInput';
import { FiatAmountInput } from './FiatAmountInput';
Expand Down Expand Up @@ -55,6 +56,7 @@ export const AmountInputs = ({ index, accountKey }: AmountInputProps) => {
);

const [isCryptoSelected, setIsCryptoSelected] = useState(true);
const scrollView = useScrollView();

const cryptoRef = useRef<TextInput>(null);
const cryptoScale = useSharedValue(SCALE_FOCUSED);
Expand Down Expand Up @@ -89,6 +91,12 @@ export const AmountInputs = ({ index, accountKey }: AmountInputProps) => {
setIsCryptoSelected(!isCryptoSelected);
};

const handleInputFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
e.target?.measureInWindow((_, y) => {
scrollView?.scrollTo({ x: 0, y, animated: true });
});
};

if (!networkSymbol) return null;

return (
Expand All @@ -110,6 +118,7 @@ export const AmountInputs = ({ index, accountKey }: AmountInputProps) => {
inputRef={cryptoRef}
isDisabled={!isCryptoSelected}
networkSymbol={networkSymbol}
onFocus={handleInputFocus}
/>
{isFiatDisplayed && (
<>
Expand All @@ -121,6 +130,7 @@ export const AmountInputs = ({ index, accountKey }: AmountInputProps) => {
inputRef={fiatRef}
isDisabled={isCryptoSelected}
networkSymbol={networkSymbol}
onFocus={handleInputFocus}
/>
</>
)}
Expand Down
2 changes: 2 additions & 0 deletions suite-native/module-send/src/components/CryptoAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const CryptoAmountInput = ({
scaleValue,
translateValue,
networkSymbol,
onFocus,
isDisabled = false,
}: SendAmountInputProps) => {
const { applyStyle } = useNativeStyles();
Expand Down Expand Up @@ -92,6 +93,7 @@ export const CryptoAmountInput = ({
editable={!isDisabled}
onChangeText={handleChangeValue}
onBlur={handleBlur}
onFocus={onFocus}
hasError={!isDisabled && hasError}
rightIcon={
<SendAmountCurrencyLabelWrapper isDisabled={isDisabled}>
Expand Down
2 changes: 2 additions & 0 deletions suite-native/module-send/src/components/FiatAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const FiatAmountInput = ({
translateValue,
inputRef,
networkSymbol,
onFocus,
isDisabled = false,
}: SendAmountInputProps) => {
const { applyStyle } = useNativeStyles();
Expand Down Expand Up @@ -70,6 +71,7 @@ export const FiatAmountInput = ({
editable={!isDisabled}
onChangeText={handleChangeValue}
onBlur={onBlur}
onFocus={onFocus}
hasError={!isDisabled && hasError}
rightIcon={
<SendAmountCurrencyLabelWrapper isDisabled={isDisabled}>
Expand Down
3 changes: 2 additions & 1 deletion suite-native/module-send/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RefObject } from 'react';
import { TextInput } from 'react-native';
import { TextInput, TextInputProps } from 'react-native';
import { SharedValue } from 'react-native-reanimated';

import { FeeLevelLabel, ReviewOutput, ReviewOutputState } from '@suite-common/wallet-types';
Expand All @@ -17,4 +17,5 @@ export type SendAmountInputProps = {
scaleValue: SharedValue<number>;
translateValue: SharedValue<number>;
isDisabled?: boolean;
onFocus?: TextInputProps['onFocus'];
};

0 comments on commit 56abb30

Please sign in to comment.