Skip to content

Commit 36cc8a6

Browse files
authored
Fix Touchables typescript errors (#4067)
## Description After #4014 I've noticed some ts errors with old deprecated Touchables. This PR fixes them. ## Test plan `yarn ts-check`
1 parent ae91e3a commit 36cc8a6

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

packages/react-native-gesture-handler/src/components/touchables/GenericTouchable.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ interface InternalProps {
3131
onStateChange?: (oldState: TouchableState, newState: TouchableState) => void;
3232
}
3333

34-
// TODO: maybe can be better
35-
// TODO: all clearTimeout have ! added, maybe they shouldn't ?
36-
type Timeout = ReturnType<typeof setTimeout> | null | undefined;
34+
type Timeout = ReturnType<typeof setTimeout> | undefined;
3735

3836
/**
3937
* GenericTouchable is not intented to be used as it is.
@@ -70,7 +68,7 @@ export default class GenericTouchable extends Component<
7068
if (this.props.delayPressIn) {
7169
this.pressInTimeout = setTimeout(() => {
7270
this.moveToState(TOUCHABLE_STATE.BEGAN);
73-
this.pressInTimeout = null;
71+
this.pressInTimeout = undefined;
7472
}, this.props.delayPressIn);
7573
} else {
7674
this.moveToState(TOUCHABLE_STATE.BEGAN);
@@ -89,7 +87,7 @@ export default class GenericTouchable extends Component<
8987
this.pressOutTimeout ||
9088
setTimeout(() => {
9189
this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);
92-
this.pressOutTimeout = null;
90+
this.pressOutTimeout = undefined;
9391
}, this.props.delayPressOut);
9492
} else {
9593
this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);
@@ -105,7 +103,7 @@ export default class GenericTouchable extends Component<
105103
this.moveToState(TOUCHABLE_STATE.BEGAN);
106104
}
107105
this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
108-
this.pressOutTimeout = null;
106+
this.pressOutTimeout = undefined;
109107
}, this.props.delayPressOut);
110108
} else {
111109
if (this.STATE === TOUCHABLE_STATE.UNDETERMINED) {
@@ -125,9 +123,9 @@ export default class GenericTouchable extends Component<
125123
clearTimeout(this.pressInTimeout);
126124
clearTimeout(this.pressOutTimeout);
127125
clearTimeout(this.longPressTimeout);
128-
this.pressOutTimeout = null;
129-
this.longPressTimeout = null;
130-
this.pressInTimeout = null;
126+
this.pressOutTimeout = undefined;
127+
this.longPressTimeout = undefined;
128+
this.pressInTimeout = undefined;
131129
}
132130

133131
// All states' transitions are defined here.
@@ -189,7 +187,7 @@ export default class GenericTouchable extends Component<
189187
const shouldCallOnPress =
190188
!this.longPressDetected &&
191189
this.STATE !== TOUCHABLE_STATE.MOVED_OUTSIDE &&
192-
this.pressOutTimeout === null;
190+
this.pressOutTimeout === undefined;
193191
this.handleGoToUndetermined();
194192
if (shouldCallOnPress) {
195193
// Calls only inside component whether no long press was called previously
@@ -219,7 +217,7 @@ export default class GenericTouchable extends Component<
219217
onMoveOut() {
220218
// Long press should no longer be detected
221219
clearTimeout(this.longPressTimeout);
222-
this.longPressTimeout = null;
220+
this.longPressTimeout = undefined;
223221
if (this.STATE === TOUCHABLE_STATE.BEGAN) {
224222
this.handleMoveOutside();
225223
}

0 commit comments

Comments
 (0)