Drop boolean support for ScrollView keyboardShouldPersistTaps (#57386)

Summary:
Removes support for the deprecated boolean values of `ScrollView`'s `keyboardShouldPersistTaps` prop. `true`/`false` have long been deprecated in favor of the string values `'always'`/`'never'` (with `'handled'` as a third option), and a runtime warning was already emitted when a boolean was passed. This drops the boolean from the type and removes the now-unused boolean handling.

Migration:
- `keyboardShouldPersistTaps={true}` → `keyboardShouldPersistTaps="always"`
- `keyboardShouldPersistTaps={false}` → `keyboardShouldPersistTaps="never"`

See https://github.com/react/react-native/issues/57384

## Changelog:

[GENERAL] [BREAKING] - Remove deprecated boolean values support for `ScrollView` `keyboardShouldPersistTaps`

Pull Request resolved: https://github.com/react/react-native/pull/57386

Test Plan:
- `yarn flow` passes (the previously-needed `$FlowFixMe[sketchy-null-bool]` suppressions are gone).
- `yarn build-types` regenerates `ReactNativeApi.d.ts` with `keyboardShouldPersistTaps?: "always" | "handled" | "never"`.
- RNTester ScrollView "Keyboard" example still toggles between `never`/`always`/`handled`.

Reviewed By: cortinico, rozele

Differential Revision: D110218873

Pulled By: Abbondanzo

fbshipit-source-id: 2cb86fe8b058432795cddc3f4f2c2cb1b1fd1fdf
This commit is contained in:
Mathieu Acthernoene authored and meta-codesync[bot] committed 2026-07-01 08:33:11 -07:00
1 parent 0fae86d0c7
commit 5bf3e38db2
4 files changed
+16 -49

No files matched your search

@@ -671,15 +671,8 @@ export interface ScrollViewProps
* - 'never' (the default), tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When this happens, children won't receive the tap.
* - 'always', the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps.
* - 'handled', the keyboard will not dismiss automatically when the tap was handled by a children, (or captured by an ancestor).
* - false, deprecated, use 'never' instead
* - true, deprecated, use 'always' instead
*/
keyboardShouldPersistTaps?:
| boolean
| 'always'
| 'never'
| 'handled'
| undefined;
keyboardShouldPersistTaps?: 'always' | 'never' | 'handled' | undefined;
/**
* Called when scrollable content view of the ScrollView changes.
@@ -581,12 +581,10 @@ type ScrollViewBaseProps = Readonly<{
* catch taps, but children of the scroll view can catch taps.
* - `'handled'`, the keyboard will not dismiss automatically when the tap was handled by
* children, (or captured by an ancestor).
* - `false`, deprecated, use `'never'` instead.
* - `true`, deprecated, use `'always'` instead.
*
* @default `'never'`
*/
keyboardShouldPersistTaps?: ?('always' | 'never' | 'handled' | true | false),
keyboardShouldPersistTaps?: ?('always' | 'never' | 'handled'),
/**
* When set, the scroll view will adjust the scroll position so that the first child that is
* partially or fully visible and at or beyond `minIndexForVisible` will not change position.
@@ -888,17 +886,6 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
};
componentDidMount() {
if (typeof this.props.keyboardShouldPersistTaps === 'boolean') {
console.warn(
`'keyboardShouldPersistTaps={${
this.props.keyboardShouldPersistTaps === true ? 'true' : 'false'
}}' is deprecated. ` +
`Use 'keyboardShouldPersistTaps="${
this.props.keyboardShouldPersistTaps ? 'always' : 'never'
}"' instead`,
);
}
this._keyboardMetrics = Keyboard.metrics();
this._additionalScrollOffset = 0;
@@ -1483,7 +1470,6 @@ class ScrollView extends React.Component<ScrollViewProps, ScrollViewState> {
const currentlyFocusedTextInput = TextInputState.currentlyFocusedInput();
if (
currentlyFocusedTextInput != null &&
this.props.keyboardShouldPersistTaps !== true &&
this.props.keyboardShouldPersistTaps !== 'always' &&
this._keyboardIsDismissible() &&
e.target !== currentlyFocusedTextInput &&
+1 -8
View File
@@ -29,15 +29,8 @@ export interface FlatListProps<ItemT> extends VirtualizedListProps<ItemT> {
* - 'never' (the default), tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When this happens, children won't receive the tap.
* - 'always', the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps.
* - 'handled', the keyboard will not dismiss automatically when the tap was handled by a children, (or captured by an ancestor).
* - false, deprecated, use 'never' instead
* - true, deprecated, use 'always' instead
*/
keyboardShouldPersistTaps?:
| boolean
| 'always'
| 'never'
| 'handled'
| undefined;
keyboardShouldPersistTaps?: 'always' | 'never' | 'handled' | undefined;
/**
* An array (or array-like list) of items to render. Other data types can be
+13 -18
View File
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<10889ead2857238c3286b036b73f9945>>
* @generated SignedSource<<cd9e044d46b56e7d426d264274dc8533>>
*
* This file was generated by scripts/js-api/build-types/index.js.
*/
@@ -4369,12 +4369,7 @@ declare type ScrollViewBaseProps = {
readonly innerViewRef?: React.Ref<InnerViewInstance>
readonly invertStickyHeaders?: boolean
readonly keyboardDismissMode?: "interactive" | "none" | "on-drag"
readonly keyboardShouldPersistTaps?:
| "always"
| "handled"
| "never"
| false
| true
readonly keyboardShouldPersistTaps?: "always" | "handled" | "never"
readonly maintainVisibleContentPosition?: {
readonly autoscrollToTopThreshold?: number
readonly minIndexForVisible: number
@@ -5926,7 +5921,7 @@ export {
AlertOptions, // a0cdac0f
AlertType, // 5ab91217
AndroidKeyboardEvent, // e03becc8
Animated, // 8d5b3c35
Animated, // 91a7b171
AppConfig, // 35c0ca70
AppRegistry, // 7ef8e53a
AppState, // 12012be5
@@ -5976,9 +5971,9 @@ export {
EventSubscription, // b8d084aa
ExtendedExceptionData, // 5a6ccf5a
FilterFunction, // bf24c0e3
FlatList, // b5cfde24
FlatListInstance, // 8f76f3b2
FlatListProps, // 3725656d
FlatList, // 0f2531c9
FlatListInstance, // f31d4744
FlatListProps, // b8b5adf2
FocusEvent, // 850f1517
FontVariant, // 7c7558bb
GestureResponderEvent, // 14d3e77a
@@ -6118,18 +6113,18 @@ export {
ScrollEvent, // d7abdd0a
ScrollResponderType, // 079145bb
ScrollToLocationParamsType, // d7ecdad1
ScrollView, // 9c14c51c
ScrollView, // d7defbe2
ScrollViewImperativeMethods, // d3ff1532
ScrollViewInstance, // 1ba64600
ScrollViewProps, // c92ac7be
ScrollViewProps, // 9207390b
ScrollViewPropsAndroid, // 44210553
ScrollViewPropsIOS, // da991b9a
ScrollViewScrollToOptions, // 3313411e
SectionBase, // dca83594
SectionList, // 626263b4
SectionList, // f483c886
SectionListData, // e0d79987
SectionListInstance, // 019cdaef
SectionListProps, // 4cb9dfa9
SectionListInstance, // 1b255509
SectionListProps, // e06b9868
SectionListRenderItem, // 466e3e87
SectionListRenderItemInfo, // d809238e
Separators, // 6a45f7e3
@@ -6203,10 +6198,10 @@ export {
VirtualViewMode, // 6be59722
VirtualizedList, // 68c7345e
VirtualizedListInstance, // 423ee7c0
VirtualizedListProps, // 29367911
VirtualizedListProps, // cc8bc4c9
VirtualizedSectionList, // 9fd9cd61
VirtualizedSectionListInstance, // 12b706d5
VirtualizedSectionListProps, // 6b9d9c05
VirtualizedSectionListProps, // 12a58a4f
WrapperComponentProvider, // 4b8c7962
codegenNativeCommands, // 628a7c0a
codegenNativeComponent, // 32a1bca6