UNPKG

3.75 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
3import _createClass from 'babel-runtime/helpers/createClass';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6var __rest = this && this.__rest || function (s, e) {
7 var t = {};
8 for (var p in s) {
9 if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
10 }if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
11 if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
12 }return t;
13};
14import React from 'react';
15import { View, Text } from 'react-native';
16import Swipe from 'react-native-swipeout';
17
18var Swipeout = function (_React$Component) {
19 _inherits(Swipeout, _React$Component);
20
21 function Swipeout(props) {
22 _classCallCheck(this, Swipeout);
23
24 var _this = _possibleConstructorReturn(this, (Swipeout.__proto__ || Object.getPrototypeOf(Swipeout)).call(this, props));
25
26 _this.state = {
27 show: false,
28 paddingTop: 0
29 };
30 return _this;
31 }
32
33 _createClass(Swipeout, [{
34 key: 'renderCustomButton',
35 value: function renderCustomButton(button) {
36 var buttonStyle = button.style || {};
37 var bgColor = buttonStyle.backgroundColor || 'transparent';
38 var Component = React.createElement(
39 View,
40 { style: {
41 flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: bgColor
42 } },
43 React.isValidElement(button.text) ? button.text : React.createElement(
44 Text,
45 { style: [button.style, { textAlign: 'center' }] },
46 button.text
47 )
48 );
49 return {
50 text: button.text || 'Click',
51 onPress: button.onPress,
52 type: 'default',
53 component: Component,
54 backgroundColor: 'transparent',
55 color: '#999',
56 disabled: false
57 };
58 }
59 }, {
60 key: 'render',
61 value: function render() {
62 var _this2 = this;
63
64 var _a = this.props,
65 disabled = _a.disabled,
66 autoClose = _a.autoClose,
67 style = _a.style,
68 left = _a.left,
69 right = _a.right,
70 onOpen = _a.onOpen,
71 onClose = _a.onClose,
72 children = _a.children,
73 restProps = __rest(_a, ["disabled", "autoClose", "style", "left", "right", "onOpen", "onClose", "children"]);
74 var customLeft = left && left.map(function (btn) {
75 return _this2.renderCustomButton(btn);
76 });
77 var customRight = right && right.map(function (btn) {
78 return _this2.renderCustomButton(btn);
79 });
80 return customLeft || customRight ? React.createElement(
81 Swipe,
82 { autoClose: autoClose, left: customLeft, right: customRight, style: style, onOpen: onOpen, onClose: onClose, disabled: disabled },
83 children
84 ) : React.createElement(
85 View,
86 _extends({ style: style }, restProps),
87 children
88 );
89 }
90 }]);
91
92 return Swipeout;
93}(React.Component);
94
95Swipeout.defaultProps = {
96 autoClose: false,
97 disabled: false,
98 onOpen: function onOpen() {},
99 onClose: function onClose() {}
100};
101export default Swipeout;
\No newline at end of file