Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ interface InternalProps {
onStateChange?: (oldState: TouchableState, newState: TouchableState) => void;
}

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

/**
* GenericTouchable is not intented to be used as it is.
Expand Down Expand Up @@ -70,7 +68,7 @@ export default class GenericTouchable extends Component<
if (this.props.delayPressIn) {
this.pressInTimeout = setTimeout(() => {
this.moveToState(TOUCHABLE_STATE.BEGAN);
this.pressInTimeout = null;
this.pressInTimeout = undefined;
}, this.props.delayPressIn);
} else {
this.moveToState(TOUCHABLE_STATE.BEGAN);
Expand All @@ -89,7 +87,7 @@ export default class GenericTouchable extends Component<
this.pressOutTimeout ||
setTimeout(() => {
this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);
this.pressOutTimeout = null;
this.pressOutTimeout = undefined;
}, this.props.delayPressOut);
} else {
this.moveToState(TOUCHABLE_STATE.MOVED_OUTSIDE);
Expand All @@ -105,7 +103,7 @@ export default class GenericTouchable extends Component<
this.moveToState(TOUCHABLE_STATE.BEGAN);
}
this.moveToState(TOUCHABLE_STATE.UNDETERMINED);
this.pressOutTimeout = null;
this.pressOutTimeout = undefined;
}, this.props.delayPressOut);
} else {
if (this.STATE === TOUCHABLE_STATE.UNDETERMINED) {
Expand All @@ -125,9 +123,9 @@ export default class GenericTouchable extends Component<
clearTimeout(this.pressInTimeout);
clearTimeout(this.pressOutTimeout);
clearTimeout(this.longPressTimeout);
this.pressOutTimeout = null;
this.longPressTimeout = null;
this.pressInTimeout = null;
this.pressOutTimeout = undefined;
this.longPressTimeout = undefined;
this.pressInTimeout = undefined;
}

// All states' transitions are defined here.
Expand Down Expand Up @@ -189,7 +187,7 @@ export default class GenericTouchable extends Component<
const shouldCallOnPress =
!this.longPressDetected &&
this.STATE !== TOUCHABLE_STATE.MOVED_OUTSIDE &&
this.pressOutTimeout === null;
this.pressOutTimeout === undefined;
this.handleGoToUndetermined();
if (shouldCallOnPress) {
// Calls only inside component whether no long press was called previously
Expand Down Expand Up @@ -219,7 +217,7 @@ export default class GenericTouchable extends Component<
onMoveOut() {
// Long press should no longer be detected
clearTimeout(this.longPressTimeout);
this.longPressTimeout = null;
this.longPressTimeout = undefined;
if (this.STATE === TOUCHABLE_STATE.BEGAN) {
this.handleMoveOutside();
}
Expand Down
Loading