Skip to content

Commit

Permalink
Moving pointer filtering to helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Dec 21, 2022
1 parent 117d3cc commit f58fea8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/framer-motion/package.json
Expand Up @@ -96,8 +96,8 @@
},
{
"path": "./dist/size-webpack-dom-max.js",
"maxSize": "30.23kB"
"maxSize": "30.24kB"
}
],
"gitHead": "b0267f01c58c549a282ff3c97f0fb32ac1450668"
"gitHead": "117d3ccbed58a0e2b9cc7d2cf2585ea22643fce4"
}
19 changes: 2 additions & 17 deletions packages/framer-motion/src/events/event-info.ts
@@ -1,20 +1,5 @@
import { EventInfo } from "./types"

/**
* Filters out events not attached to the primary pointer (currently left mouse button)
* @param eventHandler
*/
function filterPrimaryPointer(eventHandler: EventListener): EventListener {
return (event: PointerEvent) => {
/**
* Specifically match against false here as incomplete versions of
* PointerEvents in very old browser might have it set as undefined.
*/
if (event.isPrimary !== false) {
eventHandler(event)
}
}
}
import { isPrimaryPointer } from "./utils/is-primary-pointer"

export type EventListenerWithPointInfo = (
e: PointerEvent,
Expand Down Expand Up @@ -45,6 +30,6 @@ export const wrapHandler = (
handler(event, extractEventInfo(event))

return shouldFilterPrimaryPointer
? filterPrimaryPointer(listener)
? (event: PointerEvent) => isPrimaryPointer(event) && listener(event)
: listener
}
6 changes: 6 additions & 0 deletions packages/framer-motion/src/events/utils/is-primary-pointer.ts
@@ -0,0 +1,6 @@
/**
* Specifically match against false here as incomplete versions of
* PointerEvents in very old browser might have it set as undefined.
*/
export const isPrimaryPointer = (event: PointerEvent) =>
event.isPrimary !== false
3 changes: 2 additions & 1 deletion packages/framer-motion/src/gestures/PanSession.ts
Expand Up @@ -7,6 +7,7 @@ import { Point, TransformPoint } from "../projection/geometry/types"
import { pipe } from "../utils/pipe"
import { distance2D } from "../utils/distance"
import { frameData } from "../frameloop/data"
import { isPrimaryPointer } from "../events/utils/is-primary-pointer"

/**
* Passed in to pan event handlers like `onPan` the `PanInfo` object contains
Expand Down Expand Up @@ -145,7 +146,7 @@ export class PanSession {
{ transformPagePoint }: PanSessionOptions = {}
) {
// If we have more than one touch, don't start detecting this gesture
if (!event.isPrimary) return
if (!isPrimaryPointer(event)) return

this.handlers = handlers
this.transformPagePoint = transformPagePoint
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -7909,8 +7909,8 @@ __metadata:
cache-loader: ^1.2.5
convert-tsconfig-paths-to-webpack-aliases: ^0.9.2
fork-ts-checker-webpack-plugin: ^6.2.0
framer-motion: ^7.10.3
framer-motion-3d: ^7.10.3
framer-motion: ^8.0.0
framer-motion-3d: ^8.0.0
path-browserify: ^1.0.1
react: ^18.2.0
react-dom: ^18.2.0
Expand Down Expand Up @@ -7976,14 +7976,14 @@ __metadata:
languageName: unknown
linkType: soft

"framer-motion-3d@^7.10.3, framer-motion-3d@workspace:packages/framer-motion-3d":
"framer-motion-3d@^8.0.0, framer-motion-3d@workspace:packages/framer-motion-3d":
version: 0.0.0-use.local
resolution: "framer-motion-3d@workspace:packages/framer-motion-3d"
dependencies:
"@react-three/fiber": ^8.2.2
"@react-three/test-renderer": ^9.0.0
"@rollup/plugin-commonjs": ^22.0.1
framer-motion: ^7.10.3
framer-motion: ^8.0.0
react-merge-refs: ^2.0.1
peerDependencies:
"@react-three/fiber": ^8.2.2
Expand All @@ -7993,7 +7993,7 @@ __metadata:
languageName: unknown
linkType: soft

"framer-motion@^7.10.3, framer-motion@workspace:packages/framer-motion":
"framer-motion@^8.0.0, framer-motion@workspace:packages/framer-motion":
version: 0.0.0-use.local
resolution: "framer-motion@workspace:packages/framer-motion"
dependencies:
Expand Down

0 comments on commit f58fea8

Please sign in to comment.