Skip to content

Commit 29e1775

Browse files
yungsterskelset
authored andcommitted
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
1 parent e62b57e commit 29e1775

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

Libraries/Pressability/Pressability.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ const isPressInSignal = signal =>
276276
const isTerminalSignal = signal =>
277277
signal === 'RESPONDER_TERMINATED' || signal === 'RESPONDER_RELEASE';
278278

279-
const DEFAULT_LONG_PRESS_DELAY_MS = 370; // 500 - 130
280-
const DEFAULT_PRESS_DELAY_MS = 130;
279+
const DEFAULT_LONG_PRESS_DELAY_MS = 500;
281280
const DEFAULT_PRESS_RECT_OFFSETS = {
282281
bottom: 30,
283282
left: 20,
@@ -468,12 +467,7 @@ export default class Pressability {
468467
this._touchState = 'NOT_RESPONDER';
469468
this._receiveSignal('RESPONDER_GRANT', event);
470469

471-
const delayPressIn = normalizeDelay(
472-
this._config.delayPressIn,
473-
0,
474-
DEFAULT_PRESS_DELAY_MS,
475-
);
476-
470+
const delayPressIn = normalizeDelay(this._config.delayPressIn);
477471
if (delayPressIn > 0) {
478472
this._pressDelayTimeout = setTimeout(() => {
479473
this._receiveSignal('DELAY', event);
@@ -485,7 +479,7 @@ export default class Pressability {
485479
const delayLongPress = normalizeDelay(
486480
this._config.delayLongPress,
487481
10,
488-
DEFAULT_LONG_PRESS_DELAY_MS,
482+
DEFAULT_LONG_PRESS_DELAY_MS - delayPressIn,
489483
);
490484
this._longPressDelayTimeout = setTimeout(() => {
491485
this._handleLongPress(event);

Libraries/Pressability/__tests__/Pressability-test.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ describe('Pressability', () => {
355355
expect(config.onLongPress).toBeCalled();
356356
});
357357

358-
it('is called if pressed for 370ms after the press delay', () => {
358+
it('is called if pressed for 500ms after press started', () => {
359359
const {config, handlers} = createMockPressability({
360360
delayPressIn: 100,
361361
});
@@ -364,7 +364,7 @@ describe('Pressability', () => {
364364
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
365365
handlers.onResponderMove(createMockPressEvent('onResponderMove'));
366366

367-
jest.advanceTimersByTime(469);
367+
jest.advanceTimersByTime(499);
368368
expect(config.onLongPress).not.toBeCalled();
369369
jest.advanceTimersByTime(1);
370370
expect(config.onLongPress).toBeCalled();
@@ -393,7 +393,7 @@ describe('Pressability', () => {
393393
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
394394
handlers.onResponderMove(createMockPressEvent('onResponderMove'));
395395

396-
jest.advanceTimersByTime(139);
396+
jest.advanceTimersByTime(9);
397397
expect(config.onLongPress).not.toBeCalled();
398398
jest.advanceTimersByTime(1);
399399
expect(config.onLongPress).toBeCalled();
@@ -460,7 +460,13 @@ describe('Pressability', () => {
460460
const {config, handlers} = createMockPressability();
461461

462462
handlers.onStartShouldSetResponder();
463-
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
463+
handlers.onResponderGrant(
464+
createMockPressEvent({
465+
registrationName: 'onResponderGrant',
466+
pageX: 0,
467+
pageY: 0,
468+
}),
469+
);
464470
handlers.onResponderMove(
465471
createMockPressEvent({
466472
registrationName: 'onResponderMove',
@@ -475,7 +481,13 @@ describe('Pressability', () => {
475481

476482
// Subsequent long touch gesture should not carry over previous state.
477483
handlers.onStartShouldSetResponder();
478-
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
484+
handlers.onResponderGrant(
485+
createMockPressEvent({
486+
registrationName: 'onResponderGrant',
487+
pageX: 7,
488+
pageY: 8,
489+
}),
490+
);
479491
handlers.onResponderMove(
480492
// NOTE: Delta from (0, 0) is ~10.6 > 10, but should not matter.
481493
createMockPressEvent({
@@ -522,7 +534,7 @@ describe('Pressability', () => {
522534
expect(config.onPressIn).toBeCalled();
523535
});
524536

525-
it('is called after the default delay by default', () => {
537+
it('is called immediately by default', () => {
526538
const {config, handlers} = createMockPressability({
527539
delayPressIn: null,
528540
});
@@ -531,24 +543,6 @@ describe('Pressability', () => {
531543
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
532544
handlers.onResponderMove(createMockPressEvent('onResponderMove'));
533545

534-
jest.advanceTimersByTime(129);
535-
expect(config.onPressIn).not.toBeCalled();
536-
jest.advanceTimersByTime(1);
537-
expect(config.onPressIn).toBeCalled();
538-
});
539-
540-
it('falls back to the default delay if `delayPressIn` is omitted', () => {
541-
const {config, handlers} = createMockPressability({
542-
delayPressIn: null,
543-
});
544-
545-
handlers.onStartShouldSetResponder();
546-
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
547-
handlers.onResponderMove(createMockPressEvent('onResponderMove'));
548-
549-
jest.advanceTimersByTime(129);
550-
expect(config.onPressIn).not.toBeCalled();
551-
jest.advanceTimersByTime(1);
552546
expect(config.onPressIn).toBeCalled();
553547
});
554548

@@ -582,7 +576,9 @@ describe('Pressability', () => {
582576

583577
describe('onPressOut', () => {
584578
it('is called after `onResponderRelease` before `delayPressIn`', () => {
585-
const {config, handlers} = createMockPressability();
579+
const {config, handlers} = createMockPressability({
580+
delayPressIn: Number.EPSILON,
581+
});
586582

587583
handlers.onStartShouldSetResponder();
588584
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
@@ -596,7 +592,9 @@ describe('Pressability', () => {
596592
});
597593

598594
it('is called after `onResponderRelease` after `delayPressIn`', () => {
599-
const {config, handlers} = createMockPressability();
595+
const {config, handlers} = createMockPressability({
596+
delayPressIn: Number.EPSILON,
597+
});
600598

601599
handlers.onStartShouldSetResponder();
602600
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));
@@ -611,7 +609,9 @@ describe('Pressability', () => {
611609
});
612610

613611
it('is not called after `onResponderTerminate` before `delayPressIn`', () => {
614-
const {config, handlers} = createMockPressability();
612+
const {config, handlers} = createMockPressability({
613+
delayPressIn: Number.EPSILON,
614+
});
615615

616616
handlers.onStartShouldSetResponder();
617617
handlers.onResponderGrant(createMockPressEvent('onResponderGrant'));

0 commit comments

Comments
 (0)