Skip to content

feat: enable 'handled' mode of ScrollView['keyboardShouldPersistTaps'] #1141

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

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all 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 docs/docs/components/scrollview.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ keyboardDismissMode: 'none' | 'interactive' | 'on-drag'; // Native only

// Should the on-screen keyboard remain visible when the user taps
// the scroll view?
keyboardShouldPersistTaps: boolean = false; // Native only
keyboardShouldPersistTaps: boolean | 'always' | 'never' | 'handled' = 'never'; // Native only

// Invoked when the contents of the scroll view change
onContentSizeChange: (width: number, height: number) => void = undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/common/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ export interface ScrollViewProps extends CommonStyledProps<ScrollViewStyleRuleSe
// The following props are valid only on native platforms and
// have no meaning on the web implementation.
keyboardDismissMode?: 'none' | 'interactive' | 'on-drag';
keyboardShouldPersistTaps?: boolean;
keyboardShouldPersistTaps?: boolean | 'always' | 'never' | 'handled';

// This controls how often the scroll event will be fired while scrolling
// (in milliseconds between events). A lower number yields better accuracy for code
Expand Down
14 changes: 13 additions & 1 deletion src/native-common/ScrollView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as React from 'react';
import * as RN from 'react-native';

import * as RX from '../common/Interfaces';
import { ScrollViewProps } from '../common/Types';

import ViewBase from './ViewBase';

Expand Down Expand Up @@ -82,7 +83,18 @@ export class ScrollView extends ViewBase<RX.Types.ScrollViewProps, RX.Types.Stat
scrollHandler = undefined;
}

const keyboardShouldPersistTaps = (overrideKeyboardShouldPersistTaps || this.props.keyboardShouldPersistTaps ? 'always' : 'never');
// 1) keyboardShouldPersistTaps may be overridden, superceding all other settings
// 2) in the absence of any other setting, 'never' is the default
// 3) if a boolean is seen, translate to 'always' or 'never' as the boolean is deprecated
// 4) it is also possible to see a string value of 'handled'
let keyboardShouldPersistTaps: ScrollViewProps['keyboardShouldPersistTaps'] = 'never';
if (overrideKeyboardShouldPersistTaps || this.props.keyboardShouldPersistTaps === true) {
// If there is an override or a boolean true, translate it to 'always'
keyboardShouldPersistTaps = 'always';
} else if (typeof this.props.keyboardShouldPersistTaps === 'string') {
// If there is no override, and a string && non-boolean was provided, use it without translation
keyboardShouldPersistTaps = this.props.keyboardShouldPersistTaps;
}

// NOTE: We are setting `automaticallyAdjustContentInsets` to false
// (http://facebook.github.io/react-native/docs/scrollview.html#automaticallyadjustcontentinsets). The
Expand Down