UNPKG

@quidone/react-native-wheel-picker

Version:

Picker is a UI component for selecting an item from a list of options.

96 lines (95 loc) 3.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _scrolling = require("../../utils/scrolling"); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } // TODO "any" is not an exact type. How to pass the generic type? const ExtendedAnimatedFlatList = (0, _scrolling.withScrollStartEndEvent)(_reactNative.Animated.FlatList); const VirtualizedList = ({ initialIndex, data, keyExtractor, renderItem, itemHeight, pickerHeight, visibleItemCount, readOnly, scrollOffset, onTouchEnd, onTouchStart, onTouchCancel, onScrollStart, onScrollEnd, contentContainerStyle: contentContainerStyleProp, initialNumToRender, maxToRenderPerBatch, updateCellsBatchingPeriod = 10, windowSize, disableIntervalMomentum, ...restProps }, forwardedRef) => { const snapToOffsets = (0, _react.useMemo)(() => data.map((_, i) => i * itemHeight), [data, itemHeight]); const onScroll = (0, _react.useMemo)(() => _reactNative.Animated.event([{ nativeEvent: { contentOffset: { y: scrollOffset } } }], { useNativeDriver: true }), [scrollOffset]); const getItemLayout = (0, _react.useCallback)((_, index) => ({ length: itemHeight, offset: itemHeight * index, index }), [itemHeight]); const contentContainerStyle = (0, _react.useMemo)(() => { return [{ paddingVertical: (pickerHeight - itemHeight) / 2 }, contentContainerStyleProp]; }, [pickerHeight, itemHeight, contentContainerStyleProp]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(ExtendedAnimatedFlatList, { showsHorizontalScrollIndicator: false, showsVerticalScrollIndicator: false, scrollEventThrottle: 16, scrollEnabled: !readOnly, ...restProps, ref: forwardedRef, data: data, renderItem: renderItem, keyExtractor: keyExtractor, getItemLayout: getItemLayout, initialScrollIndex: initialIndex, onScroll: onScroll, scrollOffset: scrollOffset, snapToOffsets: snapToOffsets, disableIntervalMomentum: disableIntervalMomentum, style: styles.list, contentContainerStyle: contentContainerStyle, onTouchStart: onTouchStart, onTouchEnd: onTouchEnd, onTouchCancel: onTouchCancel, onScrollStart: onScrollStart, onScrollEnd: onScrollEnd, initialNumToRender: initialNumToRender ?? Math.ceil(visibleItemCount / 2), maxToRenderPerBatch: maxToRenderPerBatch ?? Math.ceil(visibleItemCount / 2), updateCellsBatchingPeriod: updateCellsBatchingPeriod, windowSize: windowSize, nestedScrollEnabled: true, removeClippedSubviews: false }); }; const styles = _reactNative.StyleSheet.create({ list: { width: '100%', overflow: 'visible' } }); var _default = exports.default = /*#__PURE__*/(0, _react.memo)(/*#__PURE__*/(0, _react.forwardRef)(VirtualizedList)); //# sourceMappingURL=VirtualizedList.js.map