Skip to content

Commit e4f3338

Browse files
javachefacebook-github-bot
authored andcommitted
Remove deprecated Pressability methods (#43328)
Summary: Pull Request resolved: #43328 These have been deprecated since 2019 (D18742620), probably time we remove them. Changelog: [General][Removed] Removed deprecated methods from Pressability. Reviewed By: NickGerleman Differential Revision: D54535029 fbshipit-source-id: 45f85fb002824c94363c839fee2f831c01ad4dbd
1 parent 396475a commit e4f3338

5 files changed

Lines changed: 19 additions & 96 deletions

File tree

packages/react-native/Libraries/Pressability/Pressability.js

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -136,33 +136,6 @@ export type PressabilityConfig = $ReadOnly<{|
136136
* while this pressable is responder.
137137
*/
138138
blockNativeResponder?: ?boolean,
139-
140-
/**
141-
* Returns whether a long press gesture should cancel the press gesture.
142-
* Defaults to true.
143-
*
144-
* @deprecated
145-
*/
146-
onLongPressShouldCancelPress_DEPRECATED?: ?() => boolean,
147-
148-
/**
149-
* If `cancelable` is set, this will be ignored.
150-
*
151-
* Returns whether to yield to a lock termination request (e.g. if a native
152-
* scroll gesture attempts to steal the responder lock).
153-
*
154-
* @deprecated
155-
*/
156-
onResponderTerminationRequest_DEPRECATED?: ?() => boolean,
157-
158-
/**
159-
* If `disabled` is set, this will be ignored.
160-
*
161-
* Returns whether to start a press gesture.
162-
*
163-
* @deprecated
164-
*/
165-
onStartShouldSetResponder_DEPRECATED?: ?() => boolean,
166139
|}>;
167140

168141
export type EventHandlers = $ReadOnly<{|
@@ -475,13 +448,7 @@ export default class Pressability {
475448
const responderEventHandlers = {
476449
onStartShouldSetResponder: (): boolean => {
477450
const {disabled} = this._config;
478-
if (disabled == null) {
479-
const {onStartShouldSetResponder_DEPRECATED} = this._config;
480-
return onStartShouldSetResponder_DEPRECATED == null
481-
? true
482-
: onStartShouldSetResponder_DEPRECATED();
483-
}
484-
return !disabled;
451+
return !disabled ?? true;
485452
},
486453

487454
onResponderGrant: (event: PressEvent): void | boolean => {
@@ -559,13 +526,7 @@ export default class Pressability {
559526

560527
onResponderTerminationRequest: (): boolean => {
561528
const {cancelable} = this._config;
562-
if (cancelable == null) {
563-
const {onResponderTerminationRequest_DEPRECATED} = this._config;
564-
return onResponderTerminationRequest_DEPRECATED == null
565-
? true
566-
: onResponderTerminationRequest_DEPRECATED();
567-
}
568-
return cancelable;
529+
return cancelable ?? true;
569530
},
570531

571532
onClick: (event: PressEvent): void => {
@@ -789,9 +750,7 @@ export default class Pressability {
789750
const {onLongPress, onPress, android_disableSound} = this._config;
790751
if (onPress != null) {
791752
const isPressCanceledByLongPress =
792-
onLongPress != null &&
793-
prevState === 'RESPONDER_ACTIVE_LONG_PRESS_IN' &&
794-
this._shouldLongPressCancelPress();
753+
onLongPress != null && prevState === 'RESPONDER_ACTIVE_LONG_PRESS_IN';
795754
if (!isPressCanceledByLongPress) {
796755
if (Platform.OS === 'android' && android_disableSound !== true) {
797756
SoundManager.playTouchSound();
@@ -925,13 +884,6 @@ export default class Pressability {
925884
}
926885
}
927886

928-
_shouldLongPressCancelPress(): boolean {
929-
return (
930-
this._config.onLongPressShouldCancelPress_DEPRECATED == null ||
931-
this._config.onLongPressShouldCancelPress_DEPRECATED()
932-
);
933-
}
934-
935887
_cancelHoverInDelayTimeout(): void {
936888
if (this._hoverInDelayTimeout != null) {
937889
clearTimeout(this._hoverInDelayTimeout);

packages/react-native/Libraries/Pressability/__tests__/Pressability-test.js

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
jest.useFakeTimers({legacyFakeTimers: true});
1414

1515
import type {PressEvent} from '../../Types/CoreEventTypes';
16+
import type {PressabilityConfig} from '../Pressability';
1617

1718
const UIManager = require('../../ReactNative/UIManager');
1819
const Platform = require('../../Utilities/Platform');
1920
const HoverState = require('../HoverState');
2021
const Pressability = require('../Pressability').default;
2122
const invariant = require('invariant');
22-
const nullthrows = require('nullthrows');
2323

2424
const isWindows = process.platform === 'win32';
2525
const itif = (condition: boolean) => {
@@ -36,9 +36,7 @@ function getMock<TArguments: $ReadOnlyArray<mixed>, TReturn>(
3636
return (fn: $FlowFixMe);
3737
}
3838

39-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
40-
* LTI update could not be added via codemod */
41-
const createMockPressability = overrides => {
39+
const createMockPressability = (overrides: ?Partial<PressabilityConfig>) => {
4240
const config = {
4341
cancelable: null,
4442
disabled: null,
@@ -57,9 +55,6 @@ const createMockPressability = overrides => {
5755
onPress: jest.fn(),
5856
onPressIn: jest.fn(),
5957
onPressOut: jest.fn(),
60-
onLongPressShouldCancelPress_DEPRECATED: jest.fn(),
61-
onResponderTerminationRequest_DEPRECATED: jest.fn(() => true),
62-
onStartShouldSetResponder_DEPRECATED: jest.fn(() => true),
6358
...overrides,
6459
};
6560
const touchable = new Pressability(config);
@@ -514,7 +509,11 @@ describe('Pressability', () => {
514509

515510
describe('onPress', () => {
516511
it('is called even when `measure` does not finish', () => {
517-
const {config, handlers} = createMockPressability();
512+
// Disable onLongPress. Since we run all timers, we otherwise end up
513+
// interpreting these events as a long press.
514+
const {config, handlers} = createMockPressability({
515+
onLongPress: undefined,
516+
});
518517

519518
handlers.onStartShouldSetResponder();
520519
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
@@ -877,29 +876,4 @@ describe('Pressability', () => {
877876
});
878877
});
879878
});
880-
881-
describe('onStartShouldSetResponder', () => {
882-
it('if omitted the responder is set by default', () => {
883-
const {handlers} = createMockPressability({
884-
onStartShouldSetResponder_DEPRECATED: null,
885-
});
886-
887-
expect(handlers.onStartShouldSetResponder()).toBe(true);
888-
});
889-
890-
it('if supplied it is called', () => {
891-
const {config, handlers} = createMockPressability();
892-
const onStartShouldSetResponder_DEPRECATED = nullthrows(
893-
config.onStartShouldSetResponder_DEPRECATED,
894-
);
895-
896-
// $FlowFixMe[prop-missing]
897-
onStartShouldSetResponder_DEPRECATED.mockReturnValue(false);
898-
expect(handlers.onStartShouldSetResponder()).toBe(false);
899-
900-
// $FlowFixMe[prop-missing]
901-
onStartShouldSetResponder_DEPRECATED.mockReturnValue(true);
902-
expect(handlers.onStartShouldSetResponder()).toBe(true);
903-
});
904-
});
905879
});

packages/react-native/Libraries/Text/Text.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ const Text: React.AbstractComponent<
118118
setHighlighted(false);
119119
onPressOut?.(event);
120120
},
121-
onResponderTerminationRequest_DEPRECATED:
122-
onResponderTerminationRequest,
123-
onStartShouldSetResponder_DEPRECATED: onStartShouldSetResponder,
124121
}
125122
: null,
126123
[
@@ -131,8 +128,6 @@ const Text: React.AbstractComponent<
131128
onPress,
132129
onPressIn,
133130
onPressOut,
134-
onResponderTerminationRequest,
135-
onStartShouldSetResponder,
136131
suppressHighlighting,
137132
],
138133
);
@@ -169,15 +164,22 @@ const Text: React.AbstractComponent<
169164
},
170165
onClick: eventHandlers.onClick,
171166
onResponderTerminationRequest:
172-
eventHandlers.onResponderTerminationRequest,
173-
onStartShouldSetResponder: eventHandlers.onStartShouldSetResponder,
167+
onResponderTerminationRequest != null
168+
? onResponderTerminationRequest
169+
: eventHandlers.onResponderTerminationRequest,
170+
onStartShouldSetResponder:
171+
onStartShouldSetResponder != null
172+
? onStartShouldSetResponder
173+
: eventHandlers.onStartShouldSetResponder,
174174
},
175175
[
176176
eventHandlers,
177177
onResponderGrant,
178178
onResponderMove,
179179
onResponderRelease,
180180
onResponderTerminate,
181+
onResponderTerminationRequest,
182+
onStartShouldSetResponder,
181183
],
182184
);
183185

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6192,9 +6192,6 @@ exports[`public API should not change unintentionally Libraries/Pressability/Pre
61926192
onPressMove?: ?(event: PressEvent) => mixed,
61936193
onPressOut?: ?(event: PressEvent) => mixed,
61946194
blockNativeResponder?: ?boolean,
6195-
onLongPressShouldCancelPress_DEPRECATED?: ?() => boolean,
6196-
onResponderTerminationRequest_DEPRECATED?: ?() => boolean,
6197-
onStartShouldSetResponder_DEPRECATED?: ?() => boolean,
61986195
|}>;
61996196
export type EventHandlers = $ReadOnly<{|
62006197
onBlur: (event: BlurEvent) => void,
@@ -6269,7 +6266,6 @@ declare export default class Pressability {
62696266
|}>
62706267
): boolean;
62716268
_handleLongPress(event: PressEvent): void;
6272-
_shouldLongPressCancelPress(): boolean;
62736269
_cancelHoverInDelayTimeout(): void;
62746270
_cancelHoverOutDelayTimeout(): void;
62756271
_cancelLongPressDelayTimeout(): void;

packages/react-native/Libraries/__tests__/public-api-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const FILES_WITH_KNOWN_ERRORS = new Set([
3636
'Libraries/Components/RefreshControl/RefreshControl.js',
3737
'Libraries/Components/ScrollView/ScrollView.js',
3838
'Libraries/Components/StatusBar/StatusBar.js',
39-
'Libraries/Components/TextInput/InputAccessoryView.js',
4039
'Libraries/Components/StaticRenderer.js',
4140
'Libraries/Components/Touchable/TouchableNativeFeedback.js',
4241
'Libraries/Components/Touchable/TouchableWithoutFeedback.js',

0 commit comments

Comments
 (0)