Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
fix: make DismissKeyboardView not to close on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyloi committed Feb 8, 2020
1 parent 7650c8e commit 85ac8d4
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/ulangi-mobile/src/views/common/DismissKeyboardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { boundMethod } from 'autobind-decorator';
import * as _ from 'lodash';
import * as React from 'react';
import {
GestureResponderEvent,
Expand All @@ -16,29 +15,34 @@ import {
} from 'react-native';

export class DismissKeyboardView extends React.Component<ViewProperties> {
// Dismiss keyboard on touch
@boundMethod
private onStartShouldSetResponder(): boolean {
return true;
}

// Do not dismiss keyboard on move (when scrolling)
@boundMethod
private onResponderGrant(event: GestureResponderEvent): void {
private onMoveShouldSetResponder(): boolean {
return false;
}

@boundMethod
private onResponderRelease(event: GestureResponderEvent): void {
Keyboard.dismiss();
if (typeof this.props.onResponderGrant !== 'undefined') {
this.props.onResponderGrant(event);
console.log(event.nativeEvent.touches);
if (typeof this.props.onResponderRelease !== 'undefined') {
this.props.onResponderRelease(event);
}
}

public render(): React.ReactElement<any> {
const rest = _.omitBy(this.props, [
'onStartShouldSetResponder',
'onResponderGrant',
]);
return (
<View
{...this.props}
onStartShouldSetResponder={this.onStartShouldSetResponder}
onResponderGrant={this.onResponderGrant}
{...rest}>
onMoveShouldSetResponder={this.onMoveShouldSetResponder}
onResponderRelease={this.onResponderRelease}>
{this.props.children}
</View>
);
Expand Down

0 comments on commit 85ac8d4

Please sign in to comment.