mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Pressability: Remove Default Press Delay
Summary: Removes the default press delay from `Pressability`, which was introduced in 0.63 and affected `Pressable`. Fixes #29376. In a subsequent commit, I will bring it back as an `unstable_pressDelay` prop. Changelog: [General][Changed] - Removed default 130ms delay from Pressability and Pressable. Reviewed By: lunaleaps Differential Revision: D23604582 fbshipit-source-id: c21c72bf8b59fed028f5905ca4f805bb3fa79399
This commit is contained in:
committed by
Lorenzo Sciandra
parent
e62b57e525
commit
29e17754b3
@@ -276,8 +276,7 @@ const isPressInSignal = signal =>
|
||||
const isTerminalSignal = signal =>
|
||||
signal === 'RESPONDER_TERMINATED' || signal === 'RESPONDER_RELEASE';
|
||||
|
||||
const DEFAULT_LONG_PRESS_DELAY_MS = 370; // 500 - 130
|
||||
const DEFAULT_PRESS_DELAY_MS = 130;
|
||||
const DEFAULT_LONG_PRESS_DELAY_MS = 500;
|
||||
const DEFAULT_PRESS_RECT_OFFSETS = {
|
||||
bottom: 30,
|
||||
left: 20,
|
||||
@@ -468,12 +467,7 @@ export default class Pressability {
|
||||
this._touchState = 'NOT_RESPONDER';
|
||||
this._receiveSignal('RESPONDER_GRANT', event);
|
||||
|
||||
const delayPressIn = normalizeDelay(
|
||||
this._config.delayPressIn,
|
||||
0,
|
||||
DEFAULT_PRESS_DELAY_MS,
|
||||
);
|
||||
|
||||
const delayPressIn = normalizeDelay(this._config.delayPressIn);
|
||||
if (delayPressIn > 0) {
|
||||
this._pressDelayTimeout = setTimeout(() => {
|
||||
this._receiveSignal('DELAY', event);
|
||||
@@ -485,7 +479,7 @@ export default class Pressability {
|
||||
const delayLongPress = normalizeDelay(
|
||||
this._config.delayLongPress,
|
||||
10,
|
||||
DEFAULT_LONG_PRESS_DELAY_MS,
|
||||
DEFAULT_LONG_PRESS_DELAY_MS - delayPressIn,
|
||||
);
|
||||
this._longPressDelayTimeout = setTimeout(() => {
|
||||
this._handleLongPress(event);
|
||||
|
||||
@@ -355,7 +355,7 @@ describe('Pressability', () => {
|
||||
expect(config.onLongPress).toBeCalled();
|
||||
});
|
||||
|
||||
it('is called if pressed for 370ms after the press delay', () => {
|
||||
it('is called if pressed for 500ms after press started', () => {
|
||||
const {config, handlers} = createMockPressability({
|
||||
delayPressIn: 100,
|
||||
});
|
||||
@@ -364,7 +364,7 @@ describe('Pressability', () => {
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
handlers.onResponderMove(createMockPressEvent('onResponderMove'));
|
||||
|
||||
jest.advanceTimersByTime(469);
|
||||
jest.advanceTimersByTime(499);
|
||||
expect(config.onLongPress).not.toBeCalled();
|
||||
jest.advanceTimersByTime(1);
|
||||
expect(config.onLongPress).toBeCalled();
|
||||
@@ -393,7 +393,7 @@ describe('Pressability', () => {
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
handlers.onResponderMove(createMockPressEvent('onResponderMove'));
|
||||
|
||||
jest.advanceTimersByTime(139);
|
||||
jest.advanceTimersByTime(9);
|
||||
expect(config.onLongPress).not.toBeCalled();
|
||||
jest.advanceTimersByTime(1);
|
||||
expect(config.onLongPress).toBeCalled();
|
||||
@@ -460,7 +460,13 @@ describe('Pressability', () => {
|
||||
const {config, handlers} = createMockPressability();
|
||||
|
||||
handlers.onStartShouldSetResponder();
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
handlers.onResponderGrant(
|
||||
createMockPressEvent({
|
||||
registrationName: 'onResponderGrant',
|
||||
pageX: 0,
|
||||
pageY: 0,
|
||||
}),
|
||||
);
|
||||
handlers.onResponderMove(
|
||||
createMockPressEvent({
|
||||
registrationName: 'onResponderMove',
|
||||
@@ -475,7 +481,13 @@ describe('Pressability', () => {
|
||||
|
||||
// Subsequent long touch gesture should not carry over previous state.
|
||||
handlers.onStartShouldSetResponder();
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
handlers.onResponderGrant(
|
||||
createMockPressEvent({
|
||||
registrationName: 'onResponderGrant',
|
||||
pageX: 7,
|
||||
pageY: 8,
|
||||
}),
|
||||
);
|
||||
handlers.onResponderMove(
|
||||
// NOTE: Delta from (0, 0) is ~10.6 > 10, but should not matter.
|
||||
createMockPressEvent({
|
||||
@@ -522,7 +534,7 @@ describe('Pressability', () => {
|
||||
expect(config.onPressIn).toBeCalled();
|
||||
});
|
||||
|
||||
it('is called after the default delay by default', () => {
|
||||
it('is called immediately by default', () => {
|
||||
const {config, handlers} = createMockPressability({
|
||||
delayPressIn: null,
|
||||
});
|
||||
@@ -531,24 +543,6 @@ describe('Pressability', () => {
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
handlers.onResponderMove(createMockPressEvent('onResponderMove'));
|
||||
|
||||
jest.advanceTimersByTime(129);
|
||||
expect(config.onPressIn).not.toBeCalled();
|
||||
jest.advanceTimersByTime(1);
|
||||
expect(config.onPressIn).toBeCalled();
|
||||
});
|
||||
|
||||
it('falls back to the default delay if `delayPressIn` is omitted', () => {
|
||||
const {config, handlers} = createMockPressability({
|
||||
delayPressIn: null,
|
||||
});
|
||||
|
||||
handlers.onStartShouldSetResponder();
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
handlers.onResponderMove(createMockPressEvent('onResponderMove'));
|
||||
|
||||
jest.advanceTimersByTime(129);
|
||||
expect(config.onPressIn).not.toBeCalled();
|
||||
jest.advanceTimersByTime(1);
|
||||
expect(config.onPressIn).toBeCalled();
|
||||
});
|
||||
|
||||
@@ -582,7 +576,9 @@ describe('Pressability', () => {
|
||||
|
||||
describe('onPressOut', () => {
|
||||
it('is called after `onResponderRelease` before `delayPressIn`', () => {
|
||||
const {config, handlers} = createMockPressability();
|
||||
const {config, handlers} = createMockPressability({
|
||||
delayPressIn: Number.EPSILON,
|
||||
});
|
||||
|
||||
handlers.onStartShouldSetResponder();
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
@@ -596,7 +592,9 @@ describe('Pressability', () => {
|
||||
});
|
||||
|
||||
it('is called after `onResponderRelease` after `delayPressIn`', () => {
|
||||
const {config, handlers} = createMockPressability();
|
||||
const {config, handlers} = createMockPressability({
|
||||
delayPressIn: Number.EPSILON,
|
||||
});
|
||||
|
||||
handlers.onStartShouldSetResponder();
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
@@ -611,7 +609,9 @@ describe('Pressability', () => {
|
||||
});
|
||||
|
||||
it('is not called after `onResponderTerminate` before `delayPressIn`', () => {
|
||||
const {config, handlers} = createMockPressability();
|
||||
const {config, handlers} = createMockPressability({
|
||||
delayPressIn: Number.EPSILON,
|
||||
});
|
||||
|
||||
handlers.onStartShouldSetResponder();
|
||||
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
|
||||
|
||||
Reference in New Issue
Block a user