File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
docs/src/pages/components Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ import { Parallax, ParallaxLayer } from '@react-spring/parallax'
59
59
60
60
### Usage Notes
61
61
62
+ - All direct ` children ` of ` Parallax ` must be ` ParallaxLayer ` s (or ` fragment ` s whose only direct ` children ` are ` ParallaxLayer ` s).
62
63
- ` Parallax ` is a scrollable container so all scroll events are fired from the container itself -- listening for scroll on ` window ` won't work.
63
64
- ` scrollTo ` is a method on ` Parallax ` -- you access it with a ` ref ` and then ` ref.current.scrollTo(pageNumber) ` .
64
65
Original file line number Diff line number Diff line change @@ -14,6 +14,24 @@ function getScrollType(horizontal: boolean) {
14
14
return horizontal ? 'scrollLeft' : 'scrollTop'
15
15
}
16
16
17
+ function mapChildrenRecursive (
18
+ children : React . ReactNode ,
19
+ callback : Function
20
+ ) : React . ReactNode {
21
+ const isReactFragment = ( node : any ) => {
22
+ if ( node . type ) {
23
+ return node . type === React . Fragment
24
+ }
25
+ return node === React . Fragment
26
+ }
27
+
28
+ return React . Children . map ( children , ( child : any ) =>
29
+ isReactFragment ( child )
30
+ ? mapChildrenRecursive ( child . props . children , callback )
31
+ : callback ( child )
32
+ )
33
+ }
34
+
17
35
const START_TRANSLATE_3D = 'translate3d(0px,0px,0px)'
18
36
const START_TRANSLATE = 'translate(0px,0px)'
19
37
@@ -339,14 +357,14 @@ export const Parallax = React.memo(
339
357
...props . innerStyle ,
340
358
} } >
341
359
< ParentContext . Provider value = { state } >
342
- { React . Children . map (
360
+ { mapChildrenRecursive (
343
361
children ,
344
362
( child : any ) => ! child . props . sticky && child
345
363
) }
346
364
</ ParentContext . Provider >
347
365
</ a . div >
348
366
< ParentContext . Provider value = { state } >
349
- { React . Children . map (
367
+ { mapChildrenRecursive (
350
368
children ,
351
369
( child : any ) => child . props . sticky && child
352
370
) }
You can’t perform that action at this time.
0 commit comments