Skip to content

Commit

Permalink
Merge pull request #1365 from framer/fix/viewport-listener-arg
Browse files Browse the repository at this point in the history
Passing IntersectionObserverEntry to viewport listener
  • Loading branch information
mergetron[bot] committed Nov 23, 2021
2 parents 68f5f8c + eefe7e0 commit ff3a0e5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ Framer Motion adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Ensuring forced renders are batched so sibling `AnimatePresence` renders are triggered together. [Issue](https://github.com/framer/motion/issues/1358)
- Viewport enter/leave event handlers are passed `IntersectionObserverEntry` or `null` if `IntersectionObserver` is not supported on the device. [Issue](https://github.com/framer/motion/issues/1364)

## [5.3.1] 2021-11-19

Expand Down
4 changes: 3 additions & 1 deletion src/motion/features/viewport/types.ts
Expand Up @@ -2,7 +2,9 @@ import { RefObject } from "react"
import { TargetAndTransition } from "../../../types"
import { VariantLabels } from "../../types"

export type ViewportEventHandler = () => void
export type ViewportEventHandler = (
entry: IntersectionObserverEntry | null
) => void

export interface ViewportOptions {
root?: RefObject<Element>
Expand Down
4 changes: 2 additions & 2 deletions src/motion/features/viewport/use-viewport.ts
Expand Up @@ -86,7 +86,7 @@ function useIntersectionObserver(
const callback = isIntersecting
? props.onViewportEnter
: props.onViewportLeave
callback?.()
callback?.(entry)
}

return observeIntersection(
Expand Down Expand Up @@ -128,7 +128,7 @@ function useMissingIntersectionObserver(
requestAnimationFrame(() => {
state.hasEnteredView = true
const { onViewportEnter } = visualElement.getProps()
onViewportEnter?.()
onViewportEnter?.(null)
visualElement.animationState?.setActive(AnimationType.InView, true)
})
}, [shouldObserve])
Expand Down

0 comments on commit ff3a0e5

Please sign in to comment.