Skip to content

Commit

Permalink
Merge pull request #1157 from framer/fix/hover-supression
Browse files Browse the repository at this point in the history
Remove hover event supression during layout measurements
  • Loading branch information
mergetron[bot] authored May 17, 2021
2 parents 1451d03 + cc0418f commit dce8305
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 35 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Framer Motion adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixing SVG gradientTransform
- Fixing SVG `gradientTransform`.
- Removing hover event suspension during layout measurements.

## [4.1.16] 2021-05-12

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
},
{
"path": "./dist/size-rollup-dom-max.js",
"maxSize": "22.3 kB"
"maxSize": "22.5 kB"
},
{
"path": "./dist/size-webpack-m.js",
Expand Down
9 changes: 1 addition & 8 deletions src/gestures/use-hover-gesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ import { usePointerEvent } from "../events/use-pointer-event"
import { VisualElement } from "../render/types"
import { FeatureProps } from "../motion/features/types"
import { isDragActive } from "./drag/utils/lock"
import { layoutState } from "../render/dom/utils/batch-layout"

function createHoverEvent(
visualElement: VisualElement,
isActive: boolean,
callback?: (event: MouseEvent, info: EventInfo) => void
) {
return (event: MouseEvent, info: EventInfo) => {
if (
!isMouseEvent(event) ||
layoutState.isMeasuringLayout ||
isDragActive()
) {
return
}
if (!isMouseEvent(event) || isDragActive()) return

callback?.(event, info)
visualElement.animationState?.setActive(AnimationType.Hover, isActive)
Expand Down
25 changes: 0 additions & 25 deletions src/render/dom/utils/batch-layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import sync from "framesync"

type Job = () => void

type JobSetter = (job: Job) => void
Expand All @@ -8,10 +6,6 @@ type ReadWrites = (read: JobSetter, write: JobSetter) => void

const unresolvedJobs = new Set<ReadWrites>()

export const layoutState = {
isMeasuringLayout: false,
}

function pushJob(stack: Job[][], job: Job, pointer: number) {
if (!stack[pointer]) stack[pointer] = []
stack[pointer].push(job)
Expand Down Expand Up @@ -45,25 +39,6 @@ export function flushLayout() {

unresolvedJobs.clear()

/**
* Mark that we're currently measuring layouts. This allows us to, for instance, ignore
* hover events that might be triggered as a result of resetting transforms.
*
* The postRender/setTimeout combo seems like an odd bit of scheduling but what it's saying
* is *after* the next render, wait 10ms before re-enabling hover events. Waiting until the
* next frame completely will result in missed, valid hover events. But events seem to
* be fired async from their actual action, so setting this to false too soon can still
* trigger events from layout measurements.
*
* Note: If we figure out a way of measuring layout while transforms remain applied, this can be removed.
* I have attempted unregistering event listeners and setting CSS to pointer-events: none
* but neither seem to work as expected.
*/
layoutState.isMeasuringLayout = true
sync.postRender(() => {
setTimeout(() => (layoutState.isMeasuringLayout = false), 10)
})

/**
* Execute jobs
*/
Expand Down

0 comments on commit dce8305

Please sign in to comment.