mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove deprecated Pressability methods (#43328)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
396475a26d
commit
e4f3338069
@@ -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);
|
||||
|
||||
+7
-33
@@ -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<TArguments: $ReadOnlyArray<mixed>, 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<PressabilityConfig>) => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+9
-7
@@ -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,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user