UNPKG

@tarojsx/library

Version:
20 lines 1.18 kB
import { __rest } from "tslib"; import React, { forwardRef, useMemo, useCallback } from 'react'; import { ScrollView } from '@tarojs/components'; /** * Container scroll view hook * * Use provided width/height synthesize standard onScroll event */ export function useOuterScrollView(_a) { // const outerScrollViewProps = useOuterScrollViewProps(rest) var { width, height } = _a, outerScrollViewProps = __rest(_a, ["width", "height"]); return useMemo(() => forwardRef((props, ref) => { const _a = Object.assign(Object.assign({}, outerScrollViewProps), props), { onScroll } = _a, rest = __rest(_a, ["onScroll"]); const handleScroll = useCallback(event => { onScroll(Object.assign(Object.assign({}, event), { currentTarget: Object.assign(Object.assign({}, event.currentTarget), { clientWidth: width, clientHeight: height }) })); }, [width, height, onScroll]); return (React.createElement(ScrollView, Object.assign({ ref: ref, style: { overflowAnchor: 'auto' }, scrollX: true, scrollY: true, "scroll-anchoring": true, onScroll: handleScroll }, rest))); }), [width, height]); } //# sourceMappingURL=useOuterScrollView.js.map