Skip to content
Merged
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();
});
Comment thread
narefyev91 marked this conversation as 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) {
Comment thread
narefyev91 marked this conversation as 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 leaving a screen */
shouldDismissKeyboardBeforeClose: PropTypes.bool,
};

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