File tree 4 files changed +30
-11
lines changed
4 files changed +30
-11
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @use-gesture/core ' : patch
3
+ ---
4
+
5
+ fix: rolls back wheel-based pinch movement to bounds (thanks [ @Andarist ] ( https://github.com/Andarist ) !)
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Engine } from './Engine'
2
2
import { touchDistanceAngle , distanceAngle , wheelValues } from '../utils/events'
3
3
import { V } from '../utils/maths'
4
4
import { Vector2 , WebKitGestureEvent } from '../types'
5
+ import { clampStateInternalMovementToBounds } from '../utils/state'
5
6
6
7
const SCALE_ANGLE_RATIO_INTENT_DEG = 30
7
8
const PINCH_WHEEL_RATIO = 100
@@ -265,6 +266,9 @@ export class PinchEngine extends Engine<'pinch'> {
265
266
state . _delta = [ ( - wheelValues ( event ) [ 1 ] / PINCH_WHEEL_RATIO ) * state . offset [ 0 ] , 0 ]
266
267
V . addTo ( state . _movement , state . _delta )
267
268
269
+ // _movement rolls back to when it passed the bounds.
270
+ clampStateInternalMovementToBounds ( state )
271
+
268
272
this . state . origin = [ event . clientX , event . clientY ]
269
273
270
274
this . compute ( event )
Original file line number Diff line number Diff line change 1
1
import { CoordinatesEngine } from './CoordinatesEngine'
2
2
import { wheelValues } from '../utils/events'
3
3
import { V } from '../utils/maths'
4
+ import { clampStateInternalMovementToBounds } from '../utils/state'
4
5
5
6
export interface WheelEngine extends CoordinatesEngine < 'wheel' > {
6
7
wheel ( this : WheelEngine , event : WheelEvent ) : void
@@ -23,17 +24,7 @@ export class WheelEngine extends CoordinatesEngine<'wheel'> {
23
24
V . addTo ( state . _movement , state . _delta )
24
25
25
26
// _movement rolls back to when it passed the bounds.
26
- const [ ox , oy ] = state . overflow
27
- const [ dx , dy ] = state . _delta
28
- const [ dirx , diry ] = state . _direction
29
-
30
- if ( ( ox < 0 && dx > 0 && dirx < 0 ) || ( ox > 0 && dx < 0 && dirx > 0 ) ) {
31
- state . _movement [ 0 ] = state . _movementBound [ 0 ] as number
32
- }
33
-
34
- if ( ( oy < 0 && dy > 0 && diry < 0 ) || ( oy > 0 && dy < 0 && diry > 0 ) ) {
35
- state . _movement [ 1 ] = state . _movementBound [ 1 ] as number
36
- }
27
+ clampStateInternalMovementToBounds ( state )
37
28
38
29
this . compute ( event )
39
30
this . emit ( )
Original file line number Diff line number Diff line change
1
+ import { CommonGestureState } from '../types'
2
+
3
+ // _movement rolls back to when it passed the bounds.
4
+ /**
5
+ * @note code is currently used in WheelEngine and PinchEngine.
6
+ */
7
+ export function clampStateInternalMovementToBounds ( state : CommonGestureState ) {
8
+ const [ ox , oy ] = state . overflow
9
+ const [ dx , dy ] = state . _delta
10
+ const [ dirx , diry ] = state . _direction
11
+
12
+ if ( ( ox < 0 && dx > 0 && dirx < 0 ) || ( ox > 0 && dx < 0 && dirx > 0 ) ) {
13
+ state . _movement [ 0 ] = state . _movementBound [ 0 ] as number
14
+ }
15
+
16
+ if ( ( oy < 0 && dy > 0 && diry < 0 ) || ( oy > 0 && dy < 0 && diry > 0 ) ) {
17
+ state . _movement [ 1 ] = state . _movementBound [ 1 ] as number
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments