Skip to content

Commit 690f7a0

Browse files
authored
feat(Float): add autoInvalidate prop for on-demand rendering (#2034)
1 parent 7d3c546 commit 690f7a0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,6 +4350,16 @@ This component makes its contents float or hover.
43504350
</Float>
43514351
```
43524352

4353+
If you have your frameloop set to `demand`, you can set `autoInvalidate` to `true`. This will ensure the animation will render while it is enabled.
4354+
4355+
```js
4356+
<Canvas frameloop="demand">
4357+
<Float autoInvalidate>
4358+
<mesh />
4359+
</Float>
4360+
</Canvas>
4361+
```
4362+
43534363
#### Stage
43544364

43554365
[![](https://img.shields.io/badge/-storybook-%23ff69b4)](https://drei.pmnd.rs/?path=/story/staging-stage--stage-st)

src/core/Float.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type FloatProps = JSX.IntrinsicElements['group'] & {
1010
floatIntensity?: number
1111
children?: React.ReactNode
1212
floatingRange?: [number?, number?]
13+
autoInvalidate?: boolean
1314
}
1415

1516
export const Float: ForwardRefComponent<FloatProps, THREE.Group> = /* @__PURE__ */ React.forwardRef<
@@ -24,6 +25,7 @@ export const Float: ForwardRefComponent<FloatProps, THREE.Group> = /* @__PURE__
2425
rotationIntensity = 1,
2526
floatIntensity = 1,
2627
floatingRange = [-0.1, 0.1],
28+
autoInvalidate = false,
2729
...props
2830
},
2931
forwardRef
@@ -33,6 +35,9 @@ export const Float: ForwardRefComponent<FloatProps, THREE.Group> = /* @__PURE__
3335
const offset = React.useRef(Math.random() * 10000)
3436
useFrame((state) => {
3537
if (!enabled || speed === 0) return
38+
39+
if (autoInvalidate) state.invalidate()
40+
3641
const t = offset.current + state.clock.getElapsedTime()
3742
ref.current.rotation.x = (Math.cos((t / 4) * speed) / 8) * rotationIntensity
3843
ref.current.rotation.y = (Math.sin((t / 4) * speed) / 8) * rotationIntensity

0 commit comments

Comments
 (0)