Skip to content

Commit

Permalink
Passing IntersectionObserverEntry to viewport listener
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Nov 23, 2021
1 parent 68f5f8c commit eefe7e0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 eefe7e0

Please sign in to comment.