@momo-kits/swipe 0.0.32-beta → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,146 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits"));var _possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));var _getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _propTypes=_interopRequireDefault(require("prop-types"));var _SwipeAction=_interopRequireDefault(require("./SwipeAction"));var _jsxFileName="/Users/trinh.ho2/momo-folk/kits/src/libs/swipe/dist/SwipeActionList.js";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function _createSuperInternal(){var Super=(0,_getPrototypeOf2.default)(Derived),result;if(hasNativeReflectConstruct){var NewTarget=(0,_getPrototypeOf2.default)(this).constructor;result=Reflect.construct(Super,arguments,NewTarget);}else{result=Super.apply(this,arguments);}return(0,_possibleConstructorReturn2.default)(this,result);};}function _isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));return true;}catch(e){return false;}}var SwipeActionList=function(_Component){(0,_inherits2.default)(SwipeActionList,_Component);var _super=_createSuper(SwipeActionList);function SwipeActionList(props){var _this;(0,_classCallCheck2.default)(this,SwipeActionList);_this=_super.call(this,props);_this.renderRow=function(_ref){var item=_ref.item,index=_ref.index;var _this$props=_this.props,renderItem=_this$props.renderItem,renderItemNonSwipe=_this$props.renderItemNonSwipe,separator=_this$props.separator,leftAction=_this$props.leftAction,rightAction=_this$props.rightAction,renderLeftAction=_this$props.renderLeftAction,renderRightAction=_this$props.renderRightAction,disableRightAction=_this$props.disableRightAction,disableLeftAction=_this$props.disableLeftAction,closeOnPress=_this$props.closeOnPress,actionTextStyle=_this$props.actionTextStyle,actionIconStyle=_this$props.actionIconStyle,_onPress=_this$props.onPress,onClose=_this$props.onClose,actionBackground=_this$props.actionBackground;return _react.default.createElement(_reactNative.View,{__source:{fileName:_jsxFileName,lineNumber:71,columnNumber:13}},_react.default.createElement(_SwipeAction.default,{ref:function ref(row){return _this._rows[""+item+index]=row;},disableRightAction:disableRightAction,disableLeftAction:disableLeftAction,leftAction:leftAction,rightAction:rightAction,onPress:function onPress(){return _onPress&&_onPress(item);},onOpen:function onOpen(){return _this.onOpen(""+item+index,item);},onClose:onClose,setScrollEnabled:function setScrollEnabled(enable){return _this.setScrollEnabled(enable);},closeOnPress:closeOnPress,actionTextStyle:actionTextStyle,actionIconStyle:actionIconStyle,actionBackground:actionBackground,rowIndex:index,renderLeftAction:renderLeftAction,renderRightAction:renderRightAction,__source:{fileName:_jsxFileName,lineNumber:72,columnNumber:17}},renderItem==null?void 0:renderItem(item,index)),renderItemNonSwipe==null?void 0:renderItemNonSwipe(item,index),separator);};_this._rows={};_this.openCellId=null;return _this;}(0,_createClass2.default)(SwipeActionList,[{key:"setScrollEnabled",value:function setScrollEnabled(enable){var _this$_listView;(_this$_listView=this._listView)==null?void 0:_this$_listView.setNativeProps==null?void 0:_this$_listView.setNativeProps({scrollEnabled:enable});}},{key:"closeOpeningRow",value:function closeOpeningRow(){if(this._rows[this.openCellId]){this._rows[this.openCellId].closeRow();}}},{key:"isRowOpen",value:function isRowOpen(){return this.openCellId!=null;}},{key:"onOpen",value:function onOpen(id,rowData){var onOpen=this.props.onOpen;if(this.openCellId&&this.openCellId!==id){this.closeOpeningRow();}this.openCellId=id;if(onOpen)onOpen(rowData);}},{key:"onScroll",value:function onScroll(e){var _this$props2=this.props,closeOnScroll=_this$props2.closeOnScroll,onScroll=_this$props2.onScroll;if(this.openCellId){if(closeOnScroll){this.closeOpeningRow();this.openCellId=null;}}if(onScroll)onScroll(e);}},{key:"render",value:function render(){var _this2=this;var data=this.props.data;return _react.default.createElement(_reactNative.FlatList,(0,_extends2.default)({},this.props,{removeClippedSubviews:false,ref:function ref(c){return _this2._listView=c;},onScroll:function onScroll(e){return _this2.onScroll(e);},data:data,keyExtractor:function keyExtractor(item,index){return index.toString();},renderItem:this.renderRow,__source:{fileName:_jsxFileName,lineNumber:101,columnNumber:13}}));}}]);return SwipeActionList;}(_react.Component);SwipeActionList.propTypes={data:_propTypes.default.array.isRequired,renderItem:_propTypes.default.oneOfType([_propTypes.default.func,_propTypes.default.node,_propTypes.default.element]).isRequired,renderItemNonSwipe:_propTypes.default.oneOfType([_propTypes.default.func,_propTypes.default.node,_propTypes.default.element]),separator:_propTypes.default.oneOfType([_propTypes.default.func,_propTypes.default.node,_propTypes.default.element]),leftAction:_propTypes.default.oneOfType([_propTypes.default.array,_propTypes.default.func,_propTypes.default.element]),rightAction:_propTypes.default.oneOfType([_propTypes.default.array,_propTypes.default.func,_propTypes.default.element]),actionTextStyle:_propTypes.default.object,actionIconStyle:_propTypes.default.object,closeOnScroll:_propTypes.default.bool,closeOnPress:_propTypes.default.bool,disableRightAction:_propTypes.default.bool,disableLeftAction:_propTypes.default.bool,onOpen:_propTypes.default.func,onClose:_propTypes.default.func,onPress:_propTypes.default.func,actionBackground:_propTypes.default.string};SwipeActionList.defaultProps={closeOnScroll:true,closeOnPress:true,disableRightAction:true,disableLeftAction:true};var _default=SwipeActionList;exports.default=_default;
1
+ import React, { Component } from 'react';
2
+ import {
3
+ View,
4
+ FlatList
5
+ } from 'react-native';
6
+
7
+ import PropTypes from 'prop-types';
8
+ import SwipeAction from './SwipeAction';
9
+
10
+ class SwipeActionList extends Component {
11
+ constructor(props) {
12
+ super(props);
13
+ this._rows = {};
14
+ this.openCellId = null;
15
+ }
16
+
17
+ setScrollEnabled(enable) {
18
+ this._listView?.setNativeProps?.({ scrollEnabled: enable });
19
+ }
20
+
21
+ closeOpeningRow() {
22
+ // if the openCellId is stale due to deleting a row this could be undefined
23
+ if (this._rows[this.openCellId]) {
24
+ this._rows[this.openCellId].closeRow();
25
+ }
26
+ }
27
+
28
+ isRowOpen() {
29
+ return this.openCellId != null;
30
+ }
31
+
32
+ onOpen(id, rowData) {
33
+ const { onOpen } = this.props;
34
+ if (this.openCellId && this.openCellId !== id) {
35
+ this.closeOpeningRow();
36
+ }
37
+ this.openCellId = id;
38
+ if (onOpen) onOpen(rowData);
39
+ }
40
+
41
+ onScroll(e) {
42
+ const { closeOnScroll, onScroll } = this.props;
43
+ if (this.openCellId) {
44
+ if (closeOnScroll) {
45
+ this.closeOpeningRow();
46
+ this.openCellId = null;
47
+ }
48
+ }
49
+ if (onScroll) onScroll(e);
50
+ }
51
+
52
+ renderRow = ({ item, index }) => {
53
+ const {
54
+ renderItem,
55
+ renderItemNonSwipe,
56
+ separator,
57
+ leftAction,
58
+ rightAction,
59
+ renderLeftAction,
60
+ renderRightAction,
61
+ disableRightAction,
62
+ disableLeftAction,
63
+ closeOnPress,
64
+ actionTextStyle,
65
+ actionIconStyle,
66
+ onPress,
67
+ onClose,
68
+ actionBackground,
69
+ swipeGestureBegan,
70
+ swipeGestureEnd,
71
+ } = this.props;
72
+ return (
73
+ <View>
74
+ <SwipeAction
75
+ ref={(row) => this._rows[`${item}${index}`] = row}
76
+ disableRightAction={disableRightAction}
77
+ disableLeftAction={disableLeftAction}
78
+ leftAction={leftAction}
79
+ rightAction={rightAction}
80
+ onPress={() => onPress && onPress(item)}
81
+ onOpen={() => this.onOpen(`${item}${index}`, item)}
82
+ onClose={onClose}
83
+ setScrollEnabled={(enable) => this.setScrollEnabled(enable)}
84
+ closeOnPress={closeOnPress}
85
+ actionTextStyle={actionTextStyle}
86
+ actionIconStyle={actionIconStyle}
87
+ actionBackground={actionBackground}
88
+ rowIndex={index}
89
+ renderLeftAction={renderLeftAction}
90
+ renderRightAction={renderRightAction}
91
+ swipeGestureBegan={swipeGestureBegan}
92
+ swipeGestureEnd={swipeGestureEnd}
93
+ >
94
+ {renderItem?.(item, index)}
95
+ </SwipeAction>
96
+ {renderItemNonSwipe?.(item, index)}
97
+ {separator}
98
+ </View>
99
+ );
100
+ };
101
+
102
+ render() {
103
+ const { data } = this.props;
104
+ return (
105
+ <FlatList
106
+ {...this.props}
107
+ removeClippedSubviews={false}
108
+ ref={(c) => this._listView = c}
109
+ onScroll={(e) => this.onScroll(e)}
110
+ data={data}
111
+ keyExtractor={(item, index) => index.toString()}
112
+ renderItem={this.renderRow}
113
+ />
114
+ );
115
+ }
116
+ }
117
+
118
+ SwipeActionList.propTypes = {
119
+ data: PropTypes.array.isRequired,
120
+ renderItem: PropTypes.oneOfType([PropTypes.func, PropTypes.node, PropTypes.element]).isRequired,
121
+ renderItemNonSwipe: PropTypes.oneOfType([PropTypes.func, PropTypes.node, PropTypes.element]),
122
+ separator: PropTypes.oneOfType([PropTypes.func, PropTypes.node, PropTypes.element]),
123
+ leftAction: PropTypes.oneOfType([PropTypes.array, PropTypes.func, PropTypes.element]),
124
+ rightAction: PropTypes.oneOfType([PropTypes.array, PropTypes.func, PropTypes.element]),
125
+ actionTextStyle: PropTypes.object,
126
+ actionIconStyle: PropTypes.object,
127
+ closeOnScroll: PropTypes.bool,
128
+ closeOnPress: PropTypes.bool,
129
+ disableRightAction: PropTypes.bool,
130
+ disableLeftAction: PropTypes.bool,
131
+ onOpen: PropTypes.func,
132
+ onClose: PropTypes.func,
133
+ onPress: PropTypes.func,
134
+ actionBackground: PropTypes.string,
135
+ swipeGestureBegan: PropTypes.func,
136
+ swipeGestureEnd: PropTypes.func,
137
+ };
138
+
139
+ SwipeActionList.defaultProps = {
140
+ closeOnScroll: true,
141
+ closeOnPress: true,
142
+ disableRightAction: true,
143
+ disableLeftAction: true
144
+ };
145
+
146
+ export default SwipeActionList;