From ff9ccc6ac116fad6a6bb26810bd20ff1c900a9fb Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 5 Mar 2024 06:37:11 -0800 Subject: [PATCH] Remove deprecated Pressability methods Summary: These have been deprecated since 2019 (D18742620), probably time we remove them. Changelog: [General][Removed] Removed deprecated methods from Pressability. Differential Revision: D54535029 --- .../Libraries/Pressability/Pressability.js | 54 ++----------------- .../__tests__/Pressability-test.js | 40 +++----------- packages/react-native/Libraries/Text/Text.js | 16 +++--- .../__snapshots__/public-api-test.js.snap | 4 -- .../Libraries/__tests__/public-api-test.js | 1 - 5 files changed, 19 insertions(+), 96 deletions(-) diff --git a/packages/react-native/Libraries/Pressability/Pressability.js b/packages/react-native/Libraries/Pressability/Pressability.js index 940249af9a8d..1bd6853b4202 100644 --- a/packages/react-native/Libraries/Pressability/Pressability.js +++ b/packages/react-native/Libraries/Pressability/Pressability.js @@ -136,33 +136,6 @@ export type PressabilityConfig = $ReadOnly<{| * while this pressable is responder. */ blockNativeResponder?: ?boolean, - - /** - * Returns whether a long press gesture should cancel the press gesture. - * Defaults to true. - * - * @deprecated - */ - onLongPressShouldCancelPress_DEPRECATED?: ?() => boolean, - - /** - * If `cancelable` is set, this will be ignored. - * - * Returns whether to yield to a lock termination request (e.g. if a native - * scroll gesture attempts to steal the responder lock). - * - * @deprecated - */ - onResponderTerminationRequest_DEPRECATED?: ?() => boolean, - - /** - * If `disabled` is set, this will be ignored. - * - * Returns whether to start a press gesture. - * - * @deprecated - */ - onStartShouldSetResponder_DEPRECATED?: ?() => boolean, |}>; export type EventHandlers = $ReadOnly<{| @@ -475,13 +448,7 @@ export default class Pressability { const responderEventHandlers = { onStartShouldSetResponder: (): boolean => { const {disabled} = this._config; - if (disabled == null) { - const {onStartShouldSetResponder_DEPRECATED} = this._config; - return onStartShouldSetResponder_DEPRECATED == null - ? true - : onStartShouldSetResponder_DEPRECATED(); - } - return !disabled; + return !disabled ?? true; }, onResponderGrant: (event: PressEvent): void | boolean => { @@ -559,13 +526,7 @@ export default class Pressability { onResponderTerminationRequest: (): boolean => { const {cancelable} = this._config; - if (cancelable == null) { - const {onResponderTerminationRequest_DEPRECATED} = this._config; - return onResponderTerminationRequest_DEPRECATED == null - ? true - : onResponderTerminationRequest_DEPRECATED(); - } - return cancelable; + return cancelable ?? true; }, onClick: (event: PressEvent): void => { @@ -789,9 +750,7 @@ export default class Pressability { const {onLongPress, onPress, android_disableSound} = this._config; if (onPress != null) { const isPressCanceledByLongPress = - onLongPress != null && - prevState === 'RESPONDER_ACTIVE_LONG_PRESS_IN' && - this._shouldLongPressCancelPress(); + onLongPress != null && prevState === 'RESPONDER_ACTIVE_LONG_PRESS_IN'; if (!isPressCanceledByLongPress) { if (Platform.OS === 'android' && android_disableSound !== true) { SoundManager.playTouchSound(); @@ -925,13 +884,6 @@ export default class Pressability { } } - _shouldLongPressCancelPress(): boolean { - return ( - this._config.onLongPressShouldCancelPress_DEPRECATED == null || - this._config.onLongPressShouldCancelPress_DEPRECATED() - ); - } - _cancelHoverInDelayTimeout(): void { if (this._hoverInDelayTimeout != null) { clearTimeout(this._hoverInDelayTimeout); diff --git a/packages/react-native/Libraries/Pressability/__tests__/Pressability-test.js b/packages/react-native/Libraries/Pressability/__tests__/Pressability-test.js index 5581db9787fa..08d770d0f70f 100644 --- a/packages/react-native/Libraries/Pressability/__tests__/Pressability-test.js +++ b/packages/react-native/Libraries/Pressability/__tests__/Pressability-test.js @@ -13,13 +13,13 @@ jest.useFakeTimers({legacyFakeTimers: true}); import type {PressEvent} from '../../Types/CoreEventTypes'; +import type {PressabilityConfig} from '../Pressability'; const UIManager = require('../../ReactNative/UIManager'); const Platform = require('../../Utilities/Platform'); const HoverState = require('../HoverState'); const Pressability = require('../Pressability').default; const invariant = require('invariant'); -const nullthrows = require('nullthrows'); const isWindows = process.platform === 'win32'; const itif = (condition: boolean) => { @@ -36,9 +36,7 @@ function getMock, TReturn>( return (fn: $FlowFixMe); } -/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's - * LTI update could not be added via codemod */ -const createMockPressability = overrides => { +const createMockPressability = (overrides: ?Partial) => { const config = { cancelable: null, disabled: null, @@ -57,9 +55,6 @@ const createMockPressability = overrides => { onPress: jest.fn(), onPressIn: jest.fn(), onPressOut: jest.fn(), - onLongPressShouldCancelPress_DEPRECATED: jest.fn(), - onResponderTerminationRequest_DEPRECATED: jest.fn(() => true), - onStartShouldSetResponder_DEPRECATED: jest.fn(() => true), ...overrides, }; const touchable = new Pressability(config); @@ -514,7 +509,11 @@ describe('Pressability', () => { describe('onPress', () => { it('is called even when `measure` does not finish', () => { - const {config, handlers} = createMockPressability(); + // Disable onLongPress. Since we run all timers, we otherwise end up + // interpreting these events as a long press. + const {config, handlers} = createMockPressability({ + onLongPress: undefined, + }); handlers.onStartShouldSetResponder(); handlers.onResponderGrant(createMockPressEvent('onResponderGrant')); @@ -877,29 +876,4 @@ describe('Pressability', () => { }); }); }); - - describe('onStartShouldSetResponder', () => { - it('if omitted the responder is set by default', () => { - const {handlers} = createMockPressability({ - onStartShouldSetResponder_DEPRECATED: null, - }); - - expect(handlers.onStartShouldSetResponder()).toBe(true); - }); - - it('if supplied it is called', () => { - const {config, handlers} = createMockPressability(); - const onStartShouldSetResponder_DEPRECATED = nullthrows( - config.onStartShouldSetResponder_DEPRECATED, - ); - - // $FlowFixMe[prop-missing] - onStartShouldSetResponder_DEPRECATED.mockReturnValue(false); - expect(handlers.onStartShouldSetResponder()).toBe(false); - - // $FlowFixMe[prop-missing] - onStartShouldSetResponder_DEPRECATED.mockReturnValue(true); - expect(handlers.onStartShouldSetResponder()).toBe(true); - }); - }); }); diff --git a/packages/react-native/Libraries/Text/Text.js b/packages/react-native/Libraries/Text/Text.js index 5ccceefc346e..19d697c99a27 100644 --- a/packages/react-native/Libraries/Text/Text.js +++ b/packages/react-native/Libraries/Text/Text.js @@ -118,9 +118,6 @@ const Text: React.AbstractComponent< setHighlighted(false); onPressOut?.(event); }, - onResponderTerminationRequest_DEPRECATED: - onResponderTerminationRequest, - onStartShouldSetResponder_DEPRECATED: onStartShouldSetResponder, } : null, [ @@ -131,8 +128,6 @@ const Text: React.AbstractComponent< onPress, onPressIn, onPressOut, - onResponderTerminationRequest, - onStartShouldSetResponder, suppressHighlighting, ], ); @@ -169,8 +164,13 @@ const Text: React.AbstractComponent< }, onClick: eventHandlers.onClick, onResponderTerminationRequest: - eventHandlers.onResponderTerminationRequest, - onStartShouldSetResponder: eventHandlers.onStartShouldSetResponder, + onResponderTerminationRequest != null + ? onResponderTerminationRequest + : eventHandlers.onResponderTerminationRequest, + onStartShouldSetResponder: + onStartShouldSetResponder != null + ? onStartShouldSetResponder + : eventHandlers.onStartShouldSetResponder, }, [ eventHandlers, @@ -178,6 +178,8 @@ const Text: React.AbstractComponent< onResponderMove, onResponderRelease, onResponderTerminate, + onResponderTerminationRequest, + onStartShouldSetResponder, ], ); diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index edf3153cfa18..4dcde7ead1a1 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -6192,9 +6192,6 @@ exports[`public API should not change unintentionally Libraries/Pressability/Pre onPressMove?: ?(event: PressEvent) => mixed, onPressOut?: ?(event: PressEvent) => mixed, blockNativeResponder?: ?boolean, - onLongPressShouldCancelPress_DEPRECATED?: ?() => boolean, - onResponderTerminationRequest_DEPRECATED?: ?() => boolean, - onStartShouldSetResponder_DEPRECATED?: ?() => boolean, |}>; export type EventHandlers = $ReadOnly<{| onBlur: (event: BlurEvent) => void, @@ -6269,7 +6266,6 @@ declare export default class Pressability { |}> ): boolean; _handleLongPress(event: PressEvent): void; - _shouldLongPressCancelPress(): boolean; _cancelHoverInDelayTimeout(): void; _cancelHoverOutDelayTimeout(): void; _cancelLongPressDelayTimeout(): void; diff --git a/packages/react-native/Libraries/__tests__/public-api-test.js b/packages/react-native/Libraries/__tests__/public-api-test.js index 2d098e84d4a7..6fcd7671d763 100644 --- a/packages/react-native/Libraries/__tests__/public-api-test.js +++ b/packages/react-native/Libraries/__tests__/public-api-test.js @@ -36,7 +36,6 @@ const FILES_WITH_KNOWN_ERRORS = new Set([ 'Libraries/Components/RefreshControl/RefreshControl.js', 'Libraries/Components/ScrollView/ScrollView.js', 'Libraries/Components/StatusBar/StatusBar.js', - 'Libraries/Components/TextInput/InputAccessoryView.js', 'Libraries/Components/StaticRenderer.js', 'Libraries/Components/Touchable/TouchableNativeFeedback.js', 'Libraries/Components/Touchable/TouchableWithoutFeedback.js',