diff --git a/Libraries/Components/ScrollResponder.js b/Libraries/Components/ScrollResponder.js index 920b56478..b0f132075 100644 --- a/Libraries/Components/ScrollResponder.js +++ b/Libraries/Components/ScrollResponder.js @@ -181,7 +181,7 @@ var ScrollResponderMixin = { scrollResponderHandleStartShouldSetResponderCapture: function(e: Event): boolean { // First see if we want to eat taps while the keyboard is up var currentlyFocusedTextInput = TextInputState.currentlyFocusedField(); - if (!this.props.keyboardShouldPersistTaps && + if (this.props.keyboardShouldPersistTaps === false && currentlyFocusedTextInput != null && e.target !== currentlyFocusedTextInput) { return true; @@ -242,7 +242,7 @@ var ScrollResponderMixin = { // By default scroll views will unfocus a textField // if another touch occurs outside of it var currentlyFocusedTextInput = TextInputState.currentlyFocusedField(); - if (!this.props.keyboardShouldPersistTaps && + if (this.props.keyboardShouldPersistTaps === false && currentlyFocusedTextInput != null && e.target !== currentlyFocusedTextInput && !this.state.observedScrollSinceBecomingResponder && diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 765934bfc..1ee37a84f 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -15,7 +15,6 @@ var EdgeInsetsPropType = require('EdgeInsetsPropType'); var Platform = require('Platform'); var PointPropType = require('PointPropType'); var RCTScrollView = require('NativeModules').UIManager.RCTScrollView; -var RCTScrollViewConsts = RCTScrollView.Constants; var React = require('React'); var ReactNativeViewAttributes = require('ReactNativeViewAttributes'); var RCTUIManager = require('NativeModules').UIManager; @@ -27,6 +26,7 @@ var ViewStylePropTypes = require('ViewStylePropTypes'); var createReactNativeComponentClass = require('createReactNativeComponentClass'); var deepDiffer = require('deepDiffer'); +var dismissKeyboard = require('dismissKeyboard'); var flattenStyle = require('flattenStyle'); var insetsDiffer = require('insetsDiffer'); var invariant = require('invariant'); @@ -156,9 +156,9 @@ var ScrollView = React.createClass({ * Determines whether the keyboard gets dismissed in response to a drag. * - 'none' (the default), drags do not dismiss the keyboard. * - 'on-drag', the keyboard is dismissed when a drag begins. - * - 'interactive', the keyboard is dismissed interactively with the drag - * and moves in synchrony with the touch; dragging upwards cancels the - * dismissal. + * - 'interactive', the keyboard is dismissed interactively with the drag and moves in + * synchrony with the touch; dragging upwards cancels the dismissal. + * On android this is not supported and it will have the same behavior as 'none'. */ keyboardDismissMode: PropTypes.oneOf([ 'none', // default @@ -170,7 +170,6 @@ var ScrollView = React.createClass({ * is up dismisses the keyboard. When true, the scroll view will not catch * taps, and the keyboard will not dismiss automatically. The default value * is false. - * @platform ios */ keyboardShouldPersistTaps: PropTypes.bool, /** @@ -310,6 +309,11 @@ var ScrollView = React.createClass({ ); } } + if (Platform.OS === 'android') { + if (this.props.keyboardDismissMode === 'on-drag') { + dismissKeyboard(); + } + } this.scrollResponderHandleScroll(e); }, @@ -380,13 +384,6 @@ var ScrollView = React.createClass({ } else { ScrollViewClass = AndroidScrollView; } - var keyboardDismissModeConstants = { - 'none': RCTScrollViewConsts.KeyboardDismissMode.None, // default - 'interactive': RCTScrollViewConsts.KeyboardDismissMode.Interactive, - 'on-drag': RCTScrollViewConsts.KeyboardDismissMode.OnDrag, - }; - props.keyboardDismissMode = props.keyboardDismissMode ? - keyboardDismissModeConstants[props.keyboardDismissMode] : undefined; } invariant( ScrollViewClass !== undefined, diff --git a/Libraries/Utilities/dismissKeyboard.js b/Libraries/Utilities/dismissKeyboard.js new file mode 100644 index 000000000..d8949e8b3 --- /dev/null +++ b/Libraries/Utilities/dismissKeyboard.js @@ -0,0 +1,16 @@ +/** + * Copyright 2004-present Facebook. All Rights Reserved. + * + * @providesModule dismissKeyboard + * + * This function dismisses the currently-open keyboard, if any + */ +'use strict'; + +var TextInputState = require('TextInputState'); + +function dismissKeyboard() { + TextInputState.blurTextInput(TextInputState.currentlyFocusedField()); +} + +module.exports = dismissKeyboard;