Skip to content

Commit 86ffb9c

Browse files
yungstersfacebook-github-bot
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 c7ec600 commit 86ffb9c

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed

Libraries/Pressability/Pressability.js

+3-9
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,
@@ -472,12 +471,7 @@ export default class Pressability {
472471
this._touchState = 'NOT_RESPONDER';
473472
this._receiveSignal('RESPONDER_GRANT', event);
474473

475-
const delayPressIn = normalizeDelay(
476-
this._config.delayPressIn,
477-
0,
478-
DEFAULT_PRESS_DELAY_MS,
479-
);
480-
474+
const delayPressIn = normalizeDelay(this._config.delayPressIn);
481475
if (delayPressIn > 0) {
482476
this._pressDelayTimeout = setTimeout(() => {
483477
this._receiveSignal('DELAY', event);
@@ -489,7 +483,7 @@ export default class Pressability {
489483
const delayLongPress = normalizeDelay(
490484
this._config.delayLongPress,
491485
10,
492-
DEFAULT_LONG_PRESS_DELAY_MS,
486+
DEFAULT_LONG_PRESS_DELAY_MS - delayPressIn,
493487
);
494488
this._longPressDelayTimeout = setTimeout(() => {
495489
this._handleLongPress(event);

Libraries/Pressability/__tests__/Pressability-test.js

+27-27
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)