Skip to content

Commit

Permalink
fix lenis/react autoRaf prop
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Nov 5, 2024
1 parent 338b030 commit a7f1866
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ html.lenis, html.lenis body {
}

.lenis.lenis-stopped {
overflow: hidden;
overflow: clip;
}

.lenis.lenis-smooth iframe {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/lenis.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ html.lenis body {
}

.lenis.lenis-stopped {
overflow: hidden;
overflow: clip;
}

.lenis.lenis-smooth iframe {
Expand Down
10 changes: 9 additions & 1 deletion packages/react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ export const rootLenisContextStore = new Store<LenisContextValue | null>(null)
*/
export const ReactLenis = forwardRef<LenisRef, LenisProps>(
(
{ children, root = false, options = {}, className, props }: LenisProps,
{
children,
root = false,
options = {},
className,
autoRaf = true,
props,
}: LenisProps,
ref
) => {
const wrapperRef = useRef<HTMLDivElement | null>(null)
Expand All @@ -53,6 +60,7 @@ export const ReactLenis = forwardRef<LenisRef, LenisProps>(
wrapper: wrapperRef.current!,
content: contentRef.current!,
}),
autoRaf: options?.autoRaf ?? autoRaf, // this is to avoid breaking the autoRaf prop if it's still used (require breaking change)
})

setLenis(lenis)
Expand Down
6 changes: 1 addition & 5 deletions packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ export type LenisProps = {
/**
* Auto-setup requestAnimationFrame
* @default true
* @deprecated use options.autoRaf instead
*/
autoRaf?: boolean
/**
* RequestAnimationFrame priority
* @default 0
*/
rafPriority?: number
/**
* Children
*/
Expand Down
27 changes: 11 additions & 16 deletions playground/react/app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ReactLenis, { useLenis } from 'lenis/react'
import { ReactLenis, useLenis } from 'lenis/react'
import { LoremIpsum } from 'lorem-ipsum'
import { useEffect, useRef, useState } from 'react'
import { useRef, useState } from 'react'

function App() {
const [lorem] = useState(() => new LoremIpsum().generateParagraphs(200))
Expand All @@ -11,27 +11,22 @@ function App() {

const lenisRef = useRef()

useEffect(() => {
console.log('lenis ref', lenisRef.current)
// useEffect(() => {
// console.log('lenis ref', lenisRef.current)

function raf(time: number) {
lenisRef.current?.lenis?.raf(time)
}
// function raf(time: number) {
// lenisRef.current?.lenis?.raf(time)
// }

const rafId = requestAnimationFrame(raf)
// const rafId = requestAnimationFrame(raf)

return () => cancelAnimationFrame(rafId)
}, [lenis])
// return () => cancelAnimationFrame(rafId)
// }, [lenis])

return (
<>
{/* <ReactLenis root /> */}
<ReactLenis
className="wrapper"
root
options={{ autoRaf: true }}
ref={lenisRef}
>
<ReactLenis className="wrapper" root ref={lenisRef}>
{lorem}
</ReactLenis>
</>
Expand Down

0 comments on commit a7f1866

Please sign in to comment.