Skip to content
Closed
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
54 changes: 3 additions & 51 deletions packages/react-native/Libraries/Pressability/Pressability.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<{|
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
});
});
});
16 changes: 9 additions & 7 deletions packages/react-native/Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ const Text: React.AbstractComponent<
setHighlighted(false);
onPressOut?.(event);
},
onResponderTerminationRequest_DEPRECATED:
onResponderTerminationRequest,
onStartShouldSetResponder_DEPRECATED: onStartShouldSetResponder,
}
: null,
[
Expand All @@ -131,8 +128,6 @@ const Text: React.AbstractComponent<
onPress,
onPressIn,
onPressOut,
onResponderTerminationRequest,
onStartShouldSetResponder,
suppressHighlighting,
],
);
Expand Down Expand Up @@ -169,15 +164,22 @@ 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,
onResponderGrant,
onResponderMove,
onResponderRelease,
onResponderTerminate,
onResponderTerminationRequest,
onStartShouldSetResponder,
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -6269,7 +6266,6 @@ declare export default class Pressability {
|}>
): boolean;
_handleLongPress(event: PressEvent): void;
_shouldLongPressCancelPress(): boolean;
_cancelHoverInDelayTimeout(): void;
_cancelHoverOutDelayTimeout(): void;
_cancelLongPressDelayTimeout(): void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down