Skip to content

Commit 80788f1

Browse files
MaxLapFacebook Github Bot
authored andcommitted
Reworking keyboardShouldPersistTaps to have a middle ground
Summary: Right now, the ScrollView's keyboard hiding behavior is either all or nothing: Hide the keyboard on any tap, or do nothing ever. This PR introduces a third mode to keyboardShouldPersistTaps which is much closer to what I consider should be the default. In the new behavior, the tap responding is done in the bubbling phase (instead of the capture phase like =true). As a result, a child can handle the tap. If no child does, then the ScrollView will receive the tap and will hide the keyboard. As a result, changing TextInput focus works as a user expects, with a single tap and without keyboard hiding. But taping on Text or on the empty part of the ScrollView hides the keyboard and removes the focus. You can view the behavior in a monkey patched ScrollView demo on rnplay: https://rnplay.org/apps/E90UYw https://rnplay.org/apps/UGzhKA In order to have a uniform props set, i added 3 values to the keyboardShouldPersistTaps: 'never' and 'always' are the same as false and true. 'handled' is the new behavior. I don't Closes facebook/react-native#10628 Differential Revision: D4294945 Pulled By: ericvicenti fbshipit-source-id: 1a753014156cac1a23fabfa8e1faa9a768868ef2
1 parent 4fb3788 commit 80788f1

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

Movies/SearchScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ var SearchScreen = React.createClass({
299299
onEndReached={this.onEndReached}
300300
automaticallyAdjustContentInsets={false}
301301
keyboardDismissMode="on-drag"
302-
keyboardShouldPersistTaps={true}
302+
keyboardShouldPersistTaps="handled"
303303
showsVerticalScrollIndicator={false}
304304
/>;
305305

UIExplorer/js/UIExplorerExampleList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class UIExplorerExampleList extends React.Component {
8282
renderRow={this._renderExampleRow.bind(this)}
8383
renderSectionHeader={this._renderSectionHeader}
8484
enableEmptySections={true}
85-
keyboardShouldPersistTaps={true}
85+
keyboardShouldPersistTaps="handled"
8686
automaticallyAdjustContentInsets={false}
8787
keyboardDismissMode="on-drag"
8888
/>

UIExplorer/js/UIExplorerPage.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ var UIExplorerTitle = require('./UIExplorerTitle');
3535

3636
class UIExplorerPage extends React.Component {
3737
props: {
38-
keyboardShouldPersistTaps?: boolean,
3938
noScroll?: boolean,
4039
noSpacer?: boolean,
4140
};
4241

4342
static propTypes = {
44-
keyboardShouldPersistTaps: React.PropTypes.bool,
4543
noScroll: React.PropTypes.bool,
4644
noSpacer: React.PropTypes.bool,
4745
};
@@ -55,7 +53,7 @@ class UIExplorerPage extends React.Component {
5553
ContentWrapper = (ScrollView: ReactClass<any>);
5654
// $FlowFixMe found when converting React.createClass to ES6
5755
wrapperProps.automaticallyAdjustContentInsets = !this.props.title;
58-
wrapperProps.keyboardShouldPersistTaps = true;
56+
wrapperProps.keyboardShouldPersistTaps = 'handled';
5957
wrapperProps.keyboardDismissMode = 'interactive';
6058
}
6159
var title = this.props.title ?

0 commit comments

Comments
 (0)