UNPKG

react-native-swipe-list

Version:

<!--[![Build Status][build-badge]][build]--> [![Version][version-badge]][package] ![Supports iOS and Android][support-badge] [![MIT License][license-badge]][license]

40 lines (39 loc) 1.86 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const react_native_1 = require("react-native"); const SwipeableRow_1 = require("./SwipeableRow"); exports.SwipeableFlatList = (props) => { const _flatListRef = react_1.useRef(); const [isScrolling, setScrolling] = react_1.useState(false); const _onScrollBeginDrag = (e) => { // Close any opens rows on ListView scroll if (!isScrolling) { setScrolling(true); } props.onScrollBeginDrag && props.onScrollBeginDrag(e); }; const _onScrollEndDrag = (e) => { // Close any opens rows on ListView scroll if (isScrolling) { setScrolling(false); } props.onScrollBeginDrag && props.onScrollBeginDrag(e); }; const _renderItem = (info) => { const { renderRightActions = () => null, renderLeftActions = () => null, closeOnScroll = true, } = props; return (react_1.default.createElement(SwipeableRow_1.SwipeableRow, { info: info, renderLeftActions: renderLeftActions, renderRightActions: renderRightActions, isScrolling: isScrolling, closeOnScroll: closeOnScroll }, props.renderItem && props.renderItem(info))); }; return (react_1.default.createElement(react_native_1.FlatList, Object.assign({}, props, { ref: ref => { if (ref !== null) { _flatListRef.current = ref; } }, onScrollBeginDrag: _onScrollBeginDrag, onScrollEndDrag: _onScrollEndDrag, renderItem: _renderItem }))); };