UNPKG

@kietpt2003/react-native-core-ui

Version:
29 lines (28 loc) 1.74 kB
import { jsx as _jsx } from "react/jsx-runtime"; import React from "react"; import { ScrollView } from "react-native-gesture-handler"; import Animated, { useAnimatedScrollHandler } from "react-native-reanimated"; import { useStableCallback } from "../hooks/DraggableFlatList/useStableCallback"; import { NestableScrollContainerProvider, useSafeNestableScrollContainerContext, } from "../context/DraggableFlatList/nestableScrollContainerContext"; const AnimatedScrollView = Animated.createAnimatedComponent(ScrollView); function NestableScrollContainerInner(props) { const { outerScrollOffset, containerSize, scrollViewSize, scrollableRef, outerScrollEnabled, } = useSafeNestableScrollContainerContext(); const onScroll = useAnimatedScrollHandler({ onScroll: ({ contentOffset }) => { outerScrollOffset.value = contentOffset.y; }, }); const onLayout = useStableCallback((event) => { const { nativeEvent: { layout }, } = event; containerSize.value = layout.height; }); const onContentSizeChange = useStableCallback((w, h) => { var _a; scrollViewSize.value = h; (_a = props.onContentSizeChange) === null || _a === void 0 ? void 0 : _a.call(props, w, h); }); return (_jsx(AnimatedScrollView, Object.assign({}, props, { onLayout: onLayout, onContentSizeChange: onContentSizeChange, scrollEnabled: outerScrollEnabled, ref: scrollableRef, scrollEventThrottle: 1, onScroll: onScroll }))); } export const NestableScrollContainer = React.forwardRef((props, forwardedRef) => { return (_jsx(NestableScrollContainerProvider, { forwardedRef: forwardedRef || undefined, children: _jsx(NestableScrollContainerInner, Object.assign({}, props)) })); });