Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard is visible for a brief moment on request/send money page after getting back from currency search page #15205

Merged
merged 10 commits into from
Feb 24, 2023
19 changes: 18 additions & 1 deletion src/components/ScreenWrapper/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {View} from 'react-native';
import {Keyboard, View} from 'react-native';
import React from 'react';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
Expand All @@ -17,6 +17,7 @@ import ONYXKEYS from '../../ONYXKEYS';
import {withNetwork} from '../OnyxProvider';
import {propTypes, defaultProps} from './propTypes';
import SafeAreaConsumer from '../SafeAreaConsumer';
import withKeyboardState from '../withKeyboardState';

class ScreenWrapper extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -51,6 +52,18 @@ class ScreenWrapper extends React.Component {
this.setState({didScreenTransitionEnd: true});
this.props.onEntryTransitionEnd();
});
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved

// We need to have this prop to remove keyboard before going away from the screen, to avoid previous screen look weird for a brief moment,
// also we need to have generic control in future - to prevent closing keyboard for some rare cases in which beforeRemove has limitations
// described here https://reactnavigation.org/docs/preventing-going-back/#limitations
if (this.props.shouldDismissKeyboardBeforeClose) {
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
this.beforeRemoveSubscription = this.props.navigation.addListener('beforeRemove', () => {
if (!this.props.isKeyboardShown) {
return;
}
Keyboard.dismiss();
});
}
}

/**
Expand All @@ -75,6 +88,9 @@ class ScreenWrapper extends React.Component {
if (this.unsubscribeTransitionStart) {
this.unsubscribeTransitionStart();
}
if (this.beforeRemoveSubscription) {
this.beforeRemoveSubscription();
}
}

render() {
Expand Down Expand Up @@ -131,6 +147,7 @@ ScreenWrapper.defaultProps = defaultProps;
export default compose(
withNavigation,
withWindowDimensions,
withKeyboardState,
withOnyx({
modal: {
key: ONYXKEYS.MODAL,
Expand Down
4 changes: 4 additions & 0 deletions src/components/ScreenWrapper/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ const propTypes = {
/** Indicates when an Alert modal is about to be visible */
willAlertModalBecomeVisible: PropTypes.bool,
}),

/** Whether to dismiss keyboard before leave a screen */
narefyev91 marked this conversation as resolved.
Show resolved Hide resolved
shouldDismissKeyboardBeforeClose: PropTypes.bool,
};

const defaultProps = {
style: [],
includeSafeAreaPaddingBottom: true,
shouldDismissKeyboardBeforeClose: true,
includePaddingTop: true,
onEntryTransitionEnd: () => {},
modal: {},
Expand Down