fix: passive events (sorry Dan)

This commit is contained in:
cha0s 2022-04-08 13:35:49 -05:00
parent aed0ab97cd
commit 10a9b28099

View File

@ -21,25 +21,7 @@ const Stage = forwardRef(({
ticker,
}, fref) => {
const hostRef = useRef();
useImperativeHandle(fref, () => ({
events: () => K.merge(
[
'click',
'mousemove',
'mouseout',
'mousedown',
'mouseup',
'touchend',
'touchmove',
'touchstart',
'wheel',
]
.map((event) => (
K.fromEvents(
renderer.element,
event,
// Normalize touch events.
(event) => {
const normalizeDeltaAndPosition = (event) => {
let {
clientX,
clientY,
@ -66,9 +48,25 @@ const Stage = forwardRef(({
{get: () => [(clientX - left) / scale, (clientY - top) / scale]},
);
return event;
},
)
};
useImperativeHandle(fref, () => ({
events: () => K.merge(
[].concat(
['touchmove', 'touchstart', 'wheel']
.map((event) => (
K.stream((emitter) => {
const handler = (event) => {
emitter.emit(normalizeDeltaAndPosition(event));
};
renderer.element.addEventListener(event, handler, {passive: true});
return () => {
renderer.element.removeEventListener(event, handler);
}
})
)),
['click', 'mousemove', 'mouseout', 'mousedown', 'mouseup', 'touchend']
.map((event) => K.fromEvents(renderer.element, event, normalizeDeltaAndPosition)),
),
),
}));
useEffect(() => {