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

Close Keyboard on iOS/Android using Swipeable View #2074

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -696,4 +696,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 41b806c7f131f87b716be1f1f9377532d6c9e43a

COCOAPODS: 1.10.0
COCOAPODS: 1.10.0
barun1997 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions src/components/SwipeableView/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default ({children}) => children;

// Swipeable View is available just on Android/iOS for now.
40 changes: 40 additions & 0 deletions src/components/SwipeableView/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, {PureComponent} from 'react';
import {PanResponder, View} from 'react-native';
import PropTypes from 'prop-types';

const propTypes = {
children: PropTypes.element.isRequired,

// Callback to fire when the user swipes down on the child content
onSwipeDown: PropTypes.func.isRequired,
};

class SwipeableView extends PureComponent {
constructor(props) {
super(props);

const minimumPixelDistance = 3;
this.panResponder = PanResponder.create({

// The PanResponder gets focus only when the y-axis movement is over minimumPixelDistance
onMoveShouldSetPanResponderCapture:
(_event, gestureState) => gestureState.dy > minimumPixelDistance,

// Calls the callback when the swipe down is released; after the completion of the gesture
onPanResponderRelease: this.props.onSwipeDown,
});
}

render() {
return (
// eslint-disable-next-line react/jsx-props-no-spreading
<View {...this.panResponder.panHandlers}>
{this.props.children}
</View>
);
}
}

SwipeableView.propTypes = propTypes;
SwipeableView.displayName = 'SwipeableView';
export default SwipeableView;
1 change: 1 addition & 0 deletions src/components/TextInputFocusable/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TextInputFocusable extends React.Component {
<TextInput
ref={el => this.textInput = el}
maxHeight={116}
rejectResponderTermination={false}
/* eslint-disable-next-line react/jsx-props-no-spreading */
{...this.props}
/>
Expand Down
13 changes: 8 additions & 5 deletions src/pages/home/report/ReportView.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import {View} from 'react-native';
import {Keyboard, View} from 'react-native';
import PropTypes from 'prop-types';
import ReportActionsView from './ReportActionsView';
import ReportActionCompose from './ReportActionCompose';
import {addAction} from '../../../libs/actions/Report';
import KeyboardSpacer from '../../../components/KeyboardSpacer';
import styles from '../../../styles/styles';
import SwipeableView from '../../../components/SwipeableView';

const propTypes = {
// The ID of the report actions will be created for
Expand All @@ -25,10 +26,12 @@ class ReportView extends React.Component {
<ReportActionsView
reportID={this.props.reportID}
/>
<ReportActionCompose
onSubmit={text => addAction(this.props.reportID, text)}
reportID={this.props.reportID}
/>
<SwipeableView onSwipeDown={() => Keyboard.dismiss()}>
<ReportActionCompose
onSubmit={text => addAction(this.props.reportID, text)}
reportID={this.props.reportID}
/>
</SwipeableView>
<KeyboardSpacer />
</View>
);
Expand Down