-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve focal points draggable style/perf (#1371)
* fix: improve focal points draggable style/perf * remove unnecessary global * fix all the things * fix comment
- Loading branch information
1 parent
00945a3
commit d58ab52
Showing
10 changed files
with
195 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { get } from './lodash-lite' | ||
|
||
const hasPointerEvents = process.browser && typeof PointerEvent === 'function' | ||
|
||
// Epiphany browser reports that it's a touch device even though it's not | ||
const isTouchDevice = process.browser && 'ontouchstart' in document && !/Epiphany/.test(navigator.userAgent) | ||
|
||
let pointerDown | ||
let pointerUp | ||
let pointerLeave | ||
let pointerMove | ||
|
||
function createEventListener (event) { | ||
return (node, callback) => { | ||
const listener = e => { | ||
// lightweight polyfill for clientX/clientY in pointer events, | ||
// which is slightly different in touch events | ||
if (typeof e.clientX !== 'number') { | ||
e.clientX = get(e, ['touches', 0, 'clientX']) | ||
} | ||
if (typeof e.clientY !== 'number') { | ||
e.clientY = get(e, ['touches', 0, 'clientY']) | ||
} | ||
callback(e) | ||
} | ||
|
||
node.addEventListener(event, listener) | ||
return { | ||
destroy () { | ||
node.removeEventListener(event, listener) | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (hasPointerEvents) { | ||
pointerDown = createEventListener('pointerdown') | ||
pointerUp = createEventListener('pointerup') | ||
pointerLeave = createEventListener('pointerleave') | ||
pointerMove = createEventListener('pointermove') | ||
} else if (isTouchDevice) { | ||
pointerDown = createEventListener('touchstart') | ||
pointerUp = createEventListener('touchend') | ||
pointerLeave = createEventListener('touchend') | ||
pointerMove = createEventListener('touchmove') | ||
} else { | ||
pointerDown = createEventListener('mousedown') | ||
pointerUp = createEventListener('mouseup') | ||
pointerLeave = createEventListener('mouseleave') | ||
pointerMove = createEventListener('mousemove') | ||
} | ||
|
||
export { pointerDown, pointerUp, pointerLeave, pointerMove } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// modeled after https://github.com/andrewiggins/afterframe | ||
// see also https://github.com/WICG/requestPostAnimationFrame | ||
export const requestPostAnimationFrame = cb => { | ||
requestAnimationFrame(() => { | ||
const channel = new MessageChannel() | ||
channel.port1.onmessage = cb | ||
channel.port2.postMessage(undefined) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.