Skip to content

Commit

Permalink
Pressability: Remove Default Press Delay
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yungsters authored and facebook-github-bot committed Sep 11, 2020
1 parent c7ec600 commit 86ffb9c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 36 deletions.
12 changes: 3 additions & 9 deletions Libraries/Pressability/Pressability.js
Expand Up @@ -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,
Expand Down Expand Up @@ -472,12 +471,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);
Expand All @@ -489,7 +483,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);
Expand Down
54 changes: 27 additions & 27 deletions Libraries/Pressability/__tests__/Pressability-test.js
Expand Up @@ -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,
});
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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',
Expand All @@ -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({
Expand Down Expand Up @@ -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,
});
Expand All @@ -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();
});

Expand Down Expand Up @@ -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'));
Expand All @@ -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'));
Expand All @@ -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'));
Expand Down

0 comments on commit 86ffb9c

Please sign in to comment.