MCPcopy Create free account
hub / github.com/shoutem/ui / ScrollView

Function ScrollView

components/ScrollView/ScrollView.js:14–52  ·  view source on GitHub ↗
({ driver, onScroll, primary, style, ...otherProps })

Source from the content-addressed store, hash-verified

12// that is aware of the animation driver context, but want the shoutem themed styling,
13// you should use the plain RN ScrollView and connect it to the 'shoutem.ui.ScrollView' stylename
14const ScrollView = ({ driver, onScroll, primary, style, ...otherProps }) => {
15 const animationDriver = useRef(
16 driver ||
17 new ScrollDriver(
18 { useNativeDriver: true, nativeScrollEventThrottle: 20 },
19 onScroll,
20 ),
21 );
22 const animationDriverContext = useContext(AnimationDriverContext);
23
24 // When transition to and back from the screen containing the scrollview,
25 // we want to switch to appropriate animation driver. We use the following hook
26 // to derive the new driver and cascading styles before the actual navigation transition is done
27 // to avoid rerendering when the actual nav transition completes
28 useFocusEffect(
29 useCallback(() => {
30 const { setAnimationDriver } = animationDriverContext;
31
32 if (setAnimationDriver) {
33 setAnimationDriver(animationDriver.current, primary);
34 }
35
36 // eslint-disable-next-line react-hooks/exhaustive-deps
37 }, []),
38 );
39
40 useEffect(() => {
41 if (driver && animationDriver.current !== driver) {
42 animationDriver.current = driver;
43 }
44 }, [driver]);
45
46 const { scrollViewProps } = animationDriver?.current;
47 const { contentContainerStyle, ...otherStyle } = style;
48
49 return (
50 <Animated.ScrollView
51 contentContainerStyle={contentContainerStyle}
52 {...scrollViewProps}
53 {..._.omit(otherProps, 'onScroll')}
54 style={otherStyle}
55 />

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected