Skip to content

Commit

Permalink
fix(suite-native): use react-native-keyboard-controller for keyboard …
Browse files Browse the repository at this point in the history
…handling
  • Loading branch information
yanascz committed Feb 6, 2025
1 parent 0a1177d commit e733289
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 42 deletions.
1 change: 1 addition & 0 deletions suite-native/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"react-native-edge-to-edge": "^1.3.1",
"react-native-gesture-handler": "^2.21.0",
"react-native-keyboard-aware-scroll-view": "0.9.5",
"react-native-keyboard-controller": "1.16.2",
"react-native-mmkv": "2.12.2",
"react-native-quick-crypto": "^0.7.6",
"react-native-reanimated": "^3.16.7",
Expand Down
17 changes: 10 additions & 7 deletions suite-native/app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect } from 'react';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { KeyboardProvider } from 'react-native-keyboard-controller';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { useDispatch, useSelector } from 'react-redux';

Expand Down Expand Up @@ -80,13 +81,15 @@ const PureApp = () => (
<IntlProvider>
<StoreProvider>
<SentryProvider>
<SafeAreaProvider>
<StylesProvider>
<NavigationContainerWithAnalytics>
<AppComponent />
</NavigationContainerWithAnalytics>
</StylesProvider>
</SafeAreaProvider>
<KeyboardProvider>
<SafeAreaProvider>
<StylesProvider>
<NavigationContainerWithAnalytics>
<AppComponent />
</NavigationContainerWithAnalytics>
</StylesProvider>
</SafeAreaProvider>
</KeyboardProvider>
</SentryProvider>
</StoreProvider>
</IntlProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ReactNode } from 'react';
import { KeyboardAvoidingView, Platform } from 'react-native';

import { Box, PictogramTitleHeader, VStack } from '@suite-native/atoms';
import { Screen, ScreenFooterGradient } from '@suite-native/navigation';
Expand All @@ -24,10 +23,10 @@ export const AccountImportSummaryScreen = ({
<Screen
header={<AccountImportScreenHeader />}
footer={
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
<>
<ScreenFooterGradient />
<Box marginHorizontal="sp16">{footer}</Box>
</KeyboardAvoidingView>
</>
}
>
<VStack spacing="sp32" flex={1}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { KeyboardAvoidingView } from 'react-native-keyboard-controller';

Check failure on line 1 in suite-native/module-accounts-import/src/screens/AccountImportSummaryScreen.tsx

View workflow job for this annotation

GitHub Actions / Linting and formatting

'react-native-keyboard-controller' should be listed in the project's dependencies. Run 'npm i -S react-native-keyboard-controller' to add it
import { useSelector } from 'react-redux';

import {
Expand Down Expand Up @@ -59,5 +60,9 @@ export const AccountImportSummaryScreen = ({
return <AccountAlreadyImportedScreen account={account} />;
}

return <AccountImportConfirmFormScreen symbol={networkSymbol} accountInfo={accountInfo} />;
return (
<KeyboardAvoidingView style={{ flex: 1 }} behavior="height">
<AccountImportConfirmFormScreen symbol={networkSymbol} accountInfo={accountInfo} />
</KeyboardAvoidingView>
);
};
38 changes: 19 additions & 19 deletions suite-native/module-send/src/components/AmountInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const AmountInputs = ({ index }: AmountInputProps) => {
);

const [isCryptoSelected, setIsCryptoSelected] = useState(true);
const scrollView = useScrollView();
// const scrollView = useScrollView();
const amountInputsWrapperRef = useRef<View>(null);

const cryptoRef = useRef<TextInput>(null);
Expand Down Expand Up @@ -102,22 +102,22 @@ export const AmountInputs = ({ index }: AmountInputProps) => {
setIsCryptoSelected(!isCryptoSelected);
};

const handleInputFocus = () => {
const amountInputsWrapper = amountInputsWrapperRef.current;
const scrollViewNodeHandle = findNodeHandle(scrollView);

if (!amountInputsWrapper || !scrollViewNodeHandle) return;

// Timeout is needed so the position is calculated after keyboard and footer animations are finished.
setTimeout(
() =>
// Scroll so the whole amount inputs section is visible.
amountInputsWrapper.measureLayout(scrollViewNodeHandle, (_, y) => {
scrollView?.scrollTo({ y, animated: true });
}),
400,
);
};
// const handleInputFocus = () => {
// const amountInputsWrapper = amountInputsWrapperRef.current;
// const scrollViewNodeHandle = findNodeHandle(scrollView);
//
// if (!amountInputsWrapper || !scrollViewNodeHandle) return;
//
// // Timeout is needed so the position is calculated after keyboard and footer animations are finished.
// setTimeout(
// () =>
// // Scroll so the whole amount inputs section is visible.
// amountInputsWrapper.measureLayout(scrollViewNodeHandle, (_, y) => {
// scrollView?.scrollTo({ y, animated: true });
// }),
// 400,
// );
// };

if (!symbol) return null;

Expand Down Expand Up @@ -149,7 +149,7 @@ export const AmountInputs = ({ index }: AmountInputProps) => {
isDisabled={!isCryptoSelected}
symbol={symbol}
onPress={!isCryptoSelected ? handleSwitchInputs : undefined}
onFocus={handleInputFocus}
// onFocus={handleInputFocus}
tokenContract={tokenContract}
/>
{isFiatDisplayed && (
Expand All @@ -164,7 +164,7 @@ export const AmountInputs = ({ index }: AmountInputProps) => {
symbol={symbol}
tokenContract={tokenContract}
onPress={isCryptoSelected ? handleSwitchInputs : undefined}
onFocus={handleInputFocus}
// onFocus={handleInputFocus}
/>
</>
)}
Expand Down
9 changes: 6 additions & 3 deletions suite-native/module-send/src/components/SendScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReactNode } from 'react';
import { KeyboardAvoidingView } from 'react-native-keyboard-controller';

Check failure on line 2 in suite-native/module-send/src/components/SendScreen.tsx

View workflow job for this annotation

GitHub Actions / Linting and formatting

'react-native-keyboard-controller' should be listed in the project's dependencies. Run 'npm i -S react-native-keyboard-controller' to add it

import { Screen } from '@suite-native/navigation';

Expand All @@ -9,7 +10,9 @@ type SendScreenProps = {
};

export const SendScreen = ({ children, footer, screenHeader }: SendScreenProps) => (
<Screen header={screenHeader} footer={footer} keyboardDismissMode="on-drag">
{children}
</Screen>
<KeyboardAvoidingView style={{ flex: 1 }} behavior="height">
<Screen header={screenHeader} footer={footer} keyboardDismissMode="on-drag">
{children}
</Screen>
</KeyboardAvoidingView>
);
1 change: 1 addition & 0 deletions suite-native/navigation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"react-native": "0.76.1",
"react-native-edge-to-edge": "^1.3.1",
"react-native-keyboard-aware-scroll-view": "0.9.5",
"react-native-keyboard-controller": "1.16.2",
"react-native-reanimated": "^3.16.7",
"react-native-safe-area-context": "^4.14.0",
"react-redux": "8.0.7"
Expand Down
19 changes: 10 additions & 9 deletions suite-native/navigation/src/components/ScreenContentWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ReactNode, useRef } from 'react';
import { ScrollView, ScrollViewProps } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import { KeyboardAwareScrollView } from 'react-native-keyboard-controller';

import { prepareNativeStyle, useNativeStyles } from '@trezor/styles';

Expand Down Expand Up @@ -35,14 +35,15 @@ export const ScreenContentWrapper = ({
<>
{scrollDivider}
<KeyboardAwareScrollView
innerRef={ref => {
// Assign the ref of inner ScrollView.
scrollViewRef.current = ref as unknown as ScrollView;
}}
keyboardDismissMode={keyboardDismissMode}
keyboardShouldPersistTaps="handled"
contentInsetAdjustmentBehavior="automatic"
extraHeight={extraKeyboardAvoidingViewHeight}
// innerRef={scrollViewRef as any}
// innerRef={ref => {
// // Assign the ref of inner ScrollView.
// scrollViewRef.current = ref as unknown as ScrollView;
// }}
// keyboardDismissMode={keyboardDismissMode}
// keyboardShouldPersistTaps="handled"
// contentInsetAdjustmentBehavior="automatic"
// extraHeight={extraKeyboardAvoidingViewHeight}
contentContainerStyle={applyStyle(screenContentWrapperStyle)}
refreshControl={refreshControl}
testID="@screen/mainScrollView"
Expand Down
25 changes: 25 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10064,6 +10064,7 @@ __metadata:
react-native-edge-to-edge: "npm:^1.3.1"
react-native-gesture-handler: "npm:^2.21.0"
react-native-keyboard-aware-scroll-view: "npm:0.9.5"
react-native-keyboard-controller: "npm:1.16.2"
react-native-mmkv: "npm:2.12.2"
react-native-quick-crypto: "npm:^0.7.6"
react-native-reanimated: "npm:^3.16.7"
Expand Down Expand Up @@ -10997,6 +10998,7 @@ __metadata:
react-native: "npm:0.76.1"
react-native-edge-to-edge: "npm:^1.3.1"
react-native-keyboard-aware-scroll-view: "npm:0.9.5"
react-native-keyboard-controller: "npm:1.16.2"
react-native-reanimated: "npm:^3.16.7"
react-native-safe-area-context: "npm:^4.14.0"
react-redux: "npm:8.0.7"
Expand Down Expand Up @@ -36153,6 +36155,16 @@ __metadata:
languageName: node
linkType: hard

"react-native-is-edge-to-edge@npm:^1.1.6":
version: 1.1.6
resolution: "react-native-is-edge-to-edge@npm:1.1.6"
peerDependencies:
react: ">=18.2.0"
react-native: ">=0.73.0"
checksum: 10/4e07c1e34c01c8d50fd7c1d0460db06f6f0515197405230386a8ffb950cb724b10743af032310d1384df0a90059bfb8992ba2d93344ce86315315f0493feccc2
languageName: node
linkType: hard

"react-native-keyboard-aware-scroll-view@npm:0.9.5":
version: 0.9.5
resolution: "react-native-keyboard-aware-scroll-view@npm:0.9.5"
Expand All @@ -36165,6 +36177,19 @@ __metadata:
languageName: node
linkType: hard

"react-native-keyboard-controller@npm:1.16.2":
version: 1.16.2
resolution: "react-native-keyboard-controller@npm:1.16.2"
dependencies:
react-native-is-edge-to-edge: "npm:^1.1.6"
peerDependencies:
react: "*"
react-native: "*"
react-native-reanimated: ">=3.0.0"
checksum: 10/8e017d079755c098e2960e63f5d077060aaa40b31f979ef043483af143c51897f3fe9ff1a1ca7f04a6ebedc9b29a0cd3b76d635b26c865e0056f626893e0739a
languageName: node
linkType: hard

"react-native-mmkv@npm:2.12.2":
version: 2.12.2
resolution: "react-native-mmkv@npm:2.12.2"
Expand Down

0 comments on commit e733289

Please sign in to comment.