@@ -10,11 +10,10 @@ export interface Interaction {
10
10
// Check if an event was triggered by touch
11
11
const isTouch = ( event : MouseEvent | TouchEvent ) : event is TouchEvent => "touches" in event ;
12
12
13
- const getPoint = ( touches : TouchList , touchId : null | number ) : Touch => {
13
+ // Finds a proper touch point by its identifier
14
+ const getTouchPoint = ( touches : TouchList , touchId : null | number ) : Touch => {
14
15
for ( let i = 0 ; i < touches . length ; i ++ ) {
15
- if ( touches [ i ] . identifier === touchId ) {
16
- return touches [ i ] ;
17
- }
16
+ if ( touches [ i ] . identifier === touchId ) return touches [ i ] ;
18
17
}
19
18
return touches [ 0 ] ;
20
19
} ;
@@ -28,7 +27,7 @@ const getRelativePosition = (
28
27
const rect = node . getBoundingClientRect ( ) ;
29
28
30
29
// Get user's pointer position from `touches` array if it's a `TouchEvent`
31
- const pointer = isTouch ( event ) ? getPoint ( event . touches , touchId ) : ( event as MouseEvent ) ;
30
+ const pointer = isTouch ( event ) ? getTouchPoint ( event . touches , touchId ) : ( event as MouseEvent ) ;
32
31
33
32
return {
34
33
left : clamp ( ( pointer . pageX - ( rect . left + window . pageXOffset ) ) / rect . width ) ,
@@ -71,13 +70,12 @@ const InteractiveBase = ({ onMove, onKey, ...rest }: Props) => {
71
70
preventDefaultMove ( nativeEvent ) ;
72
71
73
72
if ( isInvalid ( nativeEvent , hasTouch . current ) || ! el ) return ;
73
+
74
74
if ( isTouch ( nativeEvent ) ) {
75
75
hasTouch . current = true ;
76
76
touchId . current = nativeEvent . changedTouches [ 0 ] . identifier ;
77
77
}
78
78
79
- // The node/ref must actually exist when user start an interaction.
80
- // We won't suppress the ESLint warning though, as it should probably be something to be aware of.
81
79
el . focus ( ) ;
82
80
onMoveCallback ( getRelativePosition ( el , nativeEvent , touchId . current ) ) ;
83
81
toggleDocumentEvents ( true ) ;
0 commit comments