|
|
1
|
+'use strict';
|
|
|
2
|
+
|
|
|
3
|
+Object.defineProperty(exports, "__esModule", {
|
|
|
4
|
+ value: true
|
|
|
5
|
+});
|
|
|
6
|
+
|
|
|
7
|
+var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
|
8
|
+
|
|
|
9
|
+var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
|
10
|
+
|
|
|
11
|
+var _react = require('react');
|
|
|
12
|
+
|
|
|
13
|
+var _react2 = _interopRequireDefault(_react);
|
|
|
14
|
+
|
|
|
15
|
+var _reactNative = require('react-native');
|
|
|
16
|
+
|
|
|
17
|
+var _propTypes = require('prop-types');
|
|
|
18
|
+
|
|
|
19
|
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
20
|
+
|
|
|
21
|
+function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
|
22
|
+
|
|
|
23
|
+function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
|
24
|
+
|
|
|
25
|
+function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
|
26
|
+
|
|
|
27
|
+function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
|
28
|
+
|
|
|
29
|
+function noop() {}
|
|
|
30
|
+
|
|
|
31
|
+var animationFnPropType = _propTypes.PropTypes.oneOf([_reactNative.Animated.decay, _reactNative.Animated.spring, _reactNative.Animated.timing]);
|
|
|
32
|
+
|
|
|
33
|
+var Swipeable = function (_PureComponent) {
|
|
|
34
|
+ _inherits(Swipeable, _PureComponent);
|
|
|
35
|
+
|
|
|
36
|
+ function Swipeable() {
|
|
|
37
|
+ var _ref;
|
|
|
38
|
+
|
|
|
39
|
+ var _temp, _this, _ret;
|
|
|
40
|
+
|
|
|
41
|
+ _classCallCheck(this, Swipeable);
|
|
|
42
|
+
|
|
|
43
|
+ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
|
44
|
+ args[_key] = arguments[_key];
|
|
|
45
|
+ }
|
|
|
46
|
+
|
|
|
47
|
+ return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Swipeable.__proto__ || Object.getPrototypeOf(Swipeable)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
|
|
48
|
+ pan: new _reactNative.Animated.ValueXY(),
|
|
|
49
|
+ width: 0,
|
|
|
50
|
+ lastOffset: { x: 0, y: 0 },
|
|
|
51
|
+ leftActionActivated: false,
|
|
|
52
|
+ leftButtonsActivated: false,
|
|
|
53
|
+ leftButtonsOpen: false,
|
|
|
54
|
+ rightActionActivated: false,
|
|
|
55
|
+ rightButtonsActivated: false,
|
|
|
56
|
+ rightButtonsOpen: false
|
|
|
57
|
+ }, _this.recenter = function () {
|
|
|
58
|
+ var animationFn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.swipeReleaseAnimationFn;
|
|
|
59
|
+ var animationConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this.props.swipeReleaseAnimationConfig;
|
|
|
60
|
+ var onDone = arguments[2];
|
|
|
61
|
+ var pan = _this.state.pan;
|
|
|
62
|
+
|
|
|
63
|
+
|
|
|
64
|
+ _this.setState({
|
|
|
65
|
+ lastOffset: { x: 0, y: 0 },
|
|
|
66
|
+ leftActionActivated: false,
|
|
|
67
|
+ leftButtonsActivated: false,
|
|
|
68
|
+ leftButtonsOpen: false,
|
|
|
69
|
+ rightActionActivated: false,
|
|
|
70
|
+ rightButtonsActivated: false,
|
|
|
71
|
+ rightButtonsOpen: false
|
|
|
72
|
+ });
|
|
|
73
|
+
|
|
|
74
|
+ pan.flattenOffset();
|
|
|
75
|
+
|
|
|
76
|
+ animationFn(pan, animationConfig).start(onDone);
|
|
|
77
|
+ }, _this._unmounted = false, _this._handlePan = _reactNative.Animated.event([null, {
|
|
|
78
|
+ dx: _this.state.pan.x,
|
|
|
79
|
+ dy: _this.state.pan.y
|
|
|
80
|
+ }]), _this._handleMoveShouldSetPanResponder = function (event, gestureState) {
|
|
|
81
|
+ return Math.abs(gestureState.dx) > _this.props.swipeStartMinDistance;
|
|
|
82
|
+ }, _this._handlePanResponderStart = function (event, gestureState) {
|
|
|
83
|
+ var _this$state = _this.state,
|
|
|
84
|
+ lastOffset = _this$state.lastOffset,
|
|
|
85
|
+ pan = _this$state.pan;
|
|
|
86
|
+
|
|
|
87
|
+
|
|
|
88
|
+ pan.setOffset(lastOffset);
|
|
|
89
|
+ _this.props.onSwipeStart(event, gestureState, _this);
|
|
|
90
|
+ }, _this._handlePanResponderMove = function (event, gestureState) {
|
|
|
91
|
+ var _this$props = _this.props,
|
|
|
92
|
+ leftActionActivationDistance = _this$props.leftActionActivationDistance,
|
|
|
93
|
+ leftButtonsActivationDistance = _this$props.leftButtonsActivationDistance,
|
|
|
94
|
+ onLeftActionActivate = _this$props.onLeftActionActivate,
|
|
|
95
|
+ onLeftActionDeactivate = _this$props.onLeftActionDeactivate,
|
|
|
96
|
+ onLeftButtonsActivate = _this$props.onLeftButtonsActivate,
|
|
|
97
|
+ onLeftButtonsDeactivate = _this$props.onLeftButtonsDeactivate,
|
|
|
98
|
+ rightActionActivationDistance = _this$props.rightActionActivationDistance,
|
|
|
99
|
+ rightButtonsActivationDistance = _this$props.rightButtonsActivationDistance,
|
|
|
100
|
+ onRightActionActivate = _this$props.onRightActionActivate,
|
|
|
101
|
+ onRightActionDeactivate = _this$props.onRightActionDeactivate,
|
|
|
102
|
+ onRightButtonsActivate = _this$props.onRightButtonsActivate,
|
|
|
103
|
+ onRightButtonsDeactivate = _this$props.onRightButtonsDeactivate,
|
|
|
104
|
+ onSwipeMove = _this$props.onSwipeMove;
|
|
|
105
|
+ var _this$state2 = _this.state,
|
|
|
106
|
+ lastOffset = _this$state2.lastOffset,
|
|
|
107
|
+ leftActionActivated = _this$state2.leftActionActivated,
|
|
|
108
|
+ leftButtonsActivated = _this$state2.leftButtonsActivated,
|
|
|
109
|
+ rightActionActivated = _this$state2.rightActionActivated,
|
|
|
110
|
+ rightButtonsActivated = _this$state2.rightButtonsActivated;
|
|
|
111
|
+ var dx = gestureState.dx,
|
|
|
112
|
+ vx = gestureState.vx;
|
|
|
113
|
+
|
|
|
114
|
+ var x = dx + lastOffset.x;
|
|
|
115
|
+ var canSwipeRight = _this._canSwipeRight();
|
|
|
116
|
+ var canSwipeLeft = _this._canSwipeLeft();
|
|
|
117
|
+ var hasLeftButtons = _this._hasLeftButtons();
|
|
|
118
|
+ var hasRightButtons = _this._hasRightButtons();
|
|
|
119
|
+ var isSwipingLeft = vx < 0;
|
|
|
120
|
+ var isSwipingRight = vx > 0;
|
|
|
121
|
+ var nextLeftActionActivated = leftActionActivated;
|
|
|
122
|
+ var nextLeftButtonsActivated = leftButtonsActivated;
|
|
|
123
|
+ var nextRightActionActivated = rightActionActivated;
|
|
|
124
|
+ var nextRightButtonsActivated = rightButtonsActivated;
|
|
|
125
|
+
|
|
|
126
|
+ _this._handlePan(event, gestureState);
|
|
|
127
|
+ onSwipeMove(event, gestureState, _this);
|
|
|
128
|
+
|
|
|
129
|
+ if (!leftActionActivated && canSwipeRight && x >= leftActionActivationDistance) {
|
|
|
130
|
+ nextLeftActionActivated = true;
|
|
|
131
|
+ onLeftActionActivate(event, gestureState, _this);
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+ if (leftActionActivated && canSwipeRight && x < leftActionActivationDistance) {
|
|
|
135
|
+ nextLeftActionActivated = false;
|
|
|
136
|
+ onLeftActionDeactivate(event, gestureState, _this);
|
|
|
137
|
+ }
|
|
|
138
|
+
|
|
|
139
|
+ if (!rightActionActivated && canSwipeLeft && x <= -rightActionActivationDistance) {
|
|
|
140
|
+ nextRightActionActivated = true;
|
|
|
141
|
+ onRightActionActivate(event, gestureState, _this);
|
|
|
142
|
+ }
|
|
|
143
|
+
|
|
|
144
|
+ if (rightActionActivated && canSwipeLeft && x > -rightActionActivationDistance) {
|
|
|
145
|
+ nextRightActionActivated = false;
|
|
|
146
|
+ onRightActionDeactivate(event, gestureState, _this);
|
|
|
147
|
+ }
|
|
|
148
|
+
|
|
|
149
|
+ if (!leftButtonsActivated && hasLeftButtons && !isSwipingLeft && x >= leftButtonsActivationDistance) {
|
|
|
150
|
+ nextLeftButtonsActivated = true;
|
|
|
151
|
+ onLeftButtonsActivate(event, gestureState, _this);
|
|
|
152
|
+ }
|
|
|
153
|
+
|
|
|
154
|
+ if (leftButtonsActivated && hasLeftButtons && isSwipingLeft) {
|
|
|
155
|
+ nextLeftButtonsActivated = false;
|
|
|
156
|
+ onLeftButtonsDeactivate(event, gestureState, _this);
|
|
|
157
|
+ }
|
|
|
158
|
+
|
|
|
159
|
+ if (!rightButtonsActivated && hasRightButtons && !isSwipingRight && x <= -rightButtonsActivationDistance) {
|
|
|
160
|
+ nextRightButtonsActivated = true;
|
|
|
161
|
+ onRightButtonsActivate(event, gestureState, _this);
|
|
|
162
|
+ }
|
|
|
163
|
+
|
|
|
164
|
+ if (rightButtonsActivated && hasRightButtons && isSwipingRight) {
|
|
|
165
|
+ nextRightButtonsActivated = false;
|
|
|
166
|
+ onRightButtonsDeactivate(event, gestureState, _this);
|
|
|
167
|
+ }
|
|
|
168
|
+
|
|
|
169
|
+ var needsUpdate = nextLeftActionActivated !== leftActionActivated || nextLeftButtonsActivated !== leftButtonsActivated || nextRightActionActivated !== rightActionActivated || nextRightButtonsActivated !== rightButtonsActivated;
|
|
|
170
|
+
|
|
|
171
|
+ if (needsUpdate) {
|
|
|
172
|
+ _this.setState({
|
|
|
173
|
+ leftActionActivated: nextLeftActionActivated,
|
|
|
174
|
+ leftButtonsActivated: nextLeftButtonsActivated,
|
|
|
175
|
+ rightActionActivated: nextRightActionActivated,
|
|
|
176
|
+ rightButtonsActivated: nextRightButtonsActivated
|
|
|
177
|
+ });
|
|
|
178
|
+ }
|
|
|
179
|
+ }, _this._handlePanResponderEnd = function (event, gestureState) {
|
|
|
180
|
+ var _this$props2 = _this.props,
|
|
|
181
|
+ onLeftActionRelease = _this$props2.onLeftActionRelease,
|
|
|
182
|
+ onLeftActionDeactivate = _this$props2.onLeftActionDeactivate,
|
|
|
183
|
+ onLeftButtonsOpenRelease = _this$props2.onLeftButtonsOpenRelease,
|
|
|
184
|
+ onLeftButtonsCloseRelease = _this$props2.onLeftButtonsCloseRelease,
|
|
|
185
|
+ onRightActionRelease = _this$props2.onRightActionRelease,
|
|
|
186
|
+ onRightActionDeactivate = _this$props2.onRightActionDeactivate,
|
|
|
187
|
+ onRightButtonsOpenRelease = _this$props2.onRightButtonsOpenRelease,
|
|
|
188
|
+ onRightButtonsCloseRelease = _this$props2.onRightButtonsCloseRelease,
|
|
|
189
|
+ onSwipeRelease = _this$props2.onSwipeRelease;
|
|
|
190
|
+ var _this$state3 = _this.state,
|
|
|
191
|
+ leftActionActivated = _this$state3.leftActionActivated,
|
|
|
192
|
+ leftButtonsOpen = _this$state3.leftButtonsOpen,
|
|
|
193
|
+ leftButtonsActivated = _this$state3.leftButtonsActivated,
|
|
|
194
|
+ rightActionActivated = _this$state3.rightActionActivated,
|
|
|
195
|
+ rightButtonsOpen = _this$state3.rightButtonsOpen,
|
|
|
196
|
+ rightButtonsActivated = _this$state3.rightButtonsActivated,
|
|
|
197
|
+ pan = _this$state3.pan;
|
|
|
198
|
+
|
|
|
199
|
+ var animationFn = _this._getReleaseAnimationFn();
|
|
|
200
|
+ var animationConfig = _this._getReleaseAnimationConfig();
|
|
|
201
|
+
|
|
|
202
|
+ onSwipeRelease(event, gestureState, _this);
|
|
|
203
|
+
|
|
|
204
|
+ if (leftActionActivated) {
|
|
|
205
|
+ onLeftActionRelease(event, gestureState, _this);
|
|
|
206
|
+ }
|
|
|
207
|
+
|
|
|
208
|
+ if (rightActionActivated) {
|
|
|
209
|
+ onRightActionRelease(event, gestureState, _this);
|
|
|
210
|
+ }
|
|
|
211
|
+
|
|
|
212
|
+ if (leftButtonsActivated && !leftButtonsOpen) {
|
|
|
213
|
+ onLeftButtonsOpenRelease(event, gestureState, _this);
|
|
|
214
|
+ }
|
|
|
215
|
+
|
|
|
216
|
+ if (!leftButtonsActivated && leftButtonsOpen) {
|
|
|
217
|
+ onLeftButtonsCloseRelease(event, gestureState, _this);
|
|
|
218
|
+ }
|
|
|
219
|
+
|
|
|
220
|
+ if (rightButtonsActivated && !rightButtonsOpen) {
|
|
|
221
|
+ onRightButtonsOpenRelease(event, gestureState, _this);
|
|
|
222
|
+ }
|
|
|
223
|
+
|
|
|
224
|
+ if (!rightButtonsActivated && rightButtonsOpen) {
|
|
|
225
|
+ onRightButtonsCloseRelease(event, gestureState, _this);
|
|
|
226
|
+ }
|
|
|
227
|
+
|
|
|
228
|
+ _this.setState({
|
|
|
229
|
+ lastOffset: { x: animationConfig.toValue.x, y: animationConfig.toValue.y },
|
|
|
230
|
+ leftActionActivated: false,
|
|
|
231
|
+ rightActionActivated: false,
|
|
|
232
|
+ leftButtonsOpen: leftButtonsActivated,
|
|
|
233
|
+ rightButtonsOpen: rightButtonsActivated
|
|
|
234
|
+ });
|
|
|
235
|
+
|
|
|
236
|
+ pan.flattenOffset();
|
|
|
237
|
+
|
|
|
238
|
+ animationFn(pan, animationConfig).start(function () {
|
|
|
239
|
+ if (_this._unmounted) {
|
|
|
240
|
+ return;
|
|
|
241
|
+ }
|
|
|
242
|
+
|
|
|
243
|
+ var _this$props3 = _this.props,
|
|
|
244
|
+ onLeftActionComplete = _this$props3.onLeftActionComplete,
|
|
|
245
|
+ onLeftButtonsOpenComplete = _this$props3.onLeftButtonsOpenComplete,
|
|
|
246
|
+ onLeftButtonsCloseComplete = _this$props3.onLeftButtonsCloseComplete,
|
|
|
247
|
+ onRightActionComplete = _this$props3.onRightActionComplete,
|
|
|
248
|
+ onRightButtonsOpenComplete = _this$props3.onRightButtonsOpenComplete,
|
|
|
249
|
+ onRightButtonsCloseComplete = _this$props3.onRightButtonsCloseComplete,
|
|
|
250
|
+ onSwipeComplete = _this$props3.onSwipeComplete;
|
|
|
251
|
+
|
|
|
252
|
+
|
|
|
253
|
+ onSwipeComplete(event, gestureState, _this);
|
|
|
254
|
+
|
|
|
255
|
+ if (leftActionActivated) {
|
|
|
256
|
+ onLeftActionComplete(event, gestureState, _this);
|
|
|
257
|
+ onLeftActionDeactivate(event, gestureState, _this);
|
|
|
258
|
+ }
|
|
|
259
|
+
|
|
|
260
|
+ if (rightActionActivated) {
|
|
|
261
|
+ onRightActionComplete(event, gestureState, _this);
|
|
|
262
|
+ onRightActionDeactivate(event, gestureState, _this);
|
|
|
263
|
+ }
|
|
|
264
|
+
|
|
|
265
|
+ if (leftButtonsActivated && !leftButtonsOpen) {
|
|
|
266
|
+ onLeftButtonsOpenComplete(event, gestureState, _this);
|
|
|
267
|
+ }
|
|
|
268
|
+
|
|
|
269
|
+ if (!leftButtonsActivated && leftButtonsOpen) {
|
|
|
270
|
+ onLeftButtonsCloseComplete(event, gestureState, _this);
|
|
|
271
|
+ }
|
|
|
272
|
+
|
|
|
273
|
+ if (rightButtonsActivated && !rightButtonsOpen) {
|
|
|
274
|
+ onRightButtonsOpenComplete(event, gestureState, _this);
|
|
|
275
|
+ }
|
|
|
276
|
+
|
|
|
277
|
+ if (!rightButtonsActivated && rightButtonsOpen) {
|
|
|
278
|
+ onRightButtonsCloseComplete(event, gestureState, _this);
|
|
|
279
|
+ }
|
|
|
280
|
+ });
|
|
|
281
|
+ }, _this._panResponder = _reactNative.PanResponder.create({
|
|
|
282
|
+ onMoveShouldSetPanResponder: _this._handleMoveShouldSetPanResponder,
|
|
|
283
|
+ onMoveShouldSetPanResponderCapture: _this._handleMoveShouldSetPanResponder,
|
|
|
284
|
+ onPanResponderGrant: _this._handlePanResponderStart,
|
|
|
285
|
+ onPanResponderMove: _this._handlePanResponderMove,
|
|
|
286
|
+ onPanResponderRelease: _this._handlePanResponderEnd,
|
|
|
287
|
+ onPanResponderTerminate: _this._handlePanResponderEnd,
|
|
|
288
|
+ onPanResponderTerminationRequest: _this._handlePanResponderEnd
|
|
|
289
|
+ }), _this._handleLayout = function (_ref2) {
|
|
|
290
|
+ var width = _ref2.nativeEvent.layout.width;
|
|
|
291
|
+ return _this.setState({ width: width });
|
|
|
292
|
+ }, _temp), _possibleConstructorReturn(_this, _ret);
|
|
|
293
|
+ }
|
|
|
294
|
+
|
|
|
295
|
+ _createClass(Swipeable, [{
|
|
|
296
|
+ key: 'componentWillMount',
|
|
|
297
|
+ value: function componentWillMount() {
|
|
|
298
|
+ var _props = this.props,
|
|
|
299
|
+ onPanAnimatedValueRef = _props.onPanAnimatedValueRef,
|
|
|
300
|
+ onRef = _props.onRef;
|
|
|
301
|
+
|
|
|
302
|
+
|
|
|
303
|
+ onRef(this);
|
|
|
304
|
+ onPanAnimatedValueRef(this.state.pan);
|
|
|
305
|
+ }
|
|
|
306
|
+ }, {
|
|
|
307
|
+ key: 'componentWillUnmount',
|
|
|
308
|
+ value: function componentWillUnmount() {
|
|
|
309
|
+ this._unmounted = true;
|
|
|
310
|
+ }
|
|
|
311
|
+ }, {
|
|
|
312
|
+ key: '_canSwipeRight',
|
|
|
313
|
+ value: function _canSwipeRight() {
|
|
|
314
|
+ return this.props.leftContent || this._hasLeftButtons();
|
|
|
315
|
+ }
|
|
|
316
|
+ }, {
|
|
|
317
|
+ key: '_canSwipeLeft',
|
|
|
318
|
+ value: function _canSwipeLeft() {
|
|
|
319
|
+ return this.props.rightContent || this._hasRightButtons();
|
|
|
320
|
+ }
|
|
|
321
|
+ }, {
|
|
|
322
|
+ key: '_hasLeftButtons',
|
|
|
323
|
+ value: function _hasLeftButtons() {
|
|
|
324
|
+ var _props2 = this.props,
|
|
|
325
|
+ leftButtons = _props2.leftButtons,
|
|
|
326
|
+ leftContent = _props2.leftContent;
|
|
|
327
|
+
|
|
|
328
|
+
|
|
|
329
|
+ return !leftContent && leftButtons && leftButtons.length;
|
|
|
330
|
+ }
|
|
|
331
|
+ }, {
|
|
|
332
|
+ key: '_hasRightButtons',
|
|
|
333
|
+ value: function _hasRightButtons() {
|
|
|
334
|
+ var _props3 = this.props,
|
|
|
335
|
+ rightButtons = _props3.rightButtons,
|
|
|
336
|
+ rightContent = _props3.rightContent;
|
|
|
337
|
+
|
|
|
338
|
+
|
|
|
339
|
+ return !rightContent && rightButtons && rightButtons.length;
|
|
|
340
|
+ }
|
|
|
341
|
+ }, {
|
|
|
342
|
+ key: '_getReleaseAnimationFn',
|
|
|
343
|
+ value: function _getReleaseAnimationFn() {
|
|
|
344
|
+ var _props4 = this.props,
|
|
|
345
|
+ leftActionReleaseAnimationFn = _props4.leftActionReleaseAnimationFn,
|
|
|
346
|
+ leftButtonsOpenReleaseAnimationFn = _props4.leftButtonsOpenReleaseAnimationFn,
|
|
|
347
|
+ leftButtonsCloseReleaseAnimationFn = _props4.leftButtonsCloseReleaseAnimationFn,
|
|
|
348
|
+ rightActionReleaseAnimationFn = _props4.rightActionReleaseAnimationFn,
|
|
|
349
|
+ rightButtonsOpenReleaseAnimationFn = _props4.rightButtonsOpenReleaseAnimationFn,
|
|
|
350
|
+ rightButtonsCloseReleaseAnimationFn = _props4.rightButtonsCloseReleaseAnimationFn,
|
|
|
351
|
+ swipeReleaseAnimationFn = _props4.swipeReleaseAnimationFn;
|
|
|
352
|
+ var _state = this.state,
|
|
|
353
|
+ leftActionActivated = _state.leftActionActivated,
|
|
|
354
|
+ leftButtonsActivated = _state.leftButtonsActivated,
|
|
|
355
|
+ leftButtonsOpen = _state.leftButtonsOpen,
|
|
|
356
|
+ rightActionActivated = _state.rightActionActivated,
|
|
|
357
|
+ rightButtonsActivated = _state.rightButtonsActivated,
|
|
|
358
|
+ rightButtonsOpen = _state.rightButtonsOpen;
|
|
|
359
|
+
|
|
|
360
|
+
|
|
|
361
|
+ if (leftActionActivated && leftActionReleaseAnimationFn) {
|
|
|
362
|
+ return leftActionReleaseAnimationFn;
|
|
|
363
|
+ }
|
|
|
364
|
+
|
|
|
365
|
+ if (rightActionActivated && rightActionReleaseAnimationFn) {
|
|
|
366
|
+ return rightActionReleaseAnimationFn;
|
|
|
367
|
+ }
|
|
|
368
|
+
|
|
|
369
|
+ if (leftButtonsActivated && leftButtonsOpenReleaseAnimationFn) {
|
|
|
370
|
+ return leftButtonsOpenReleaseAnimationFn;
|
|
|
371
|
+ }
|
|
|
372
|
+
|
|
|
373
|
+ if (!leftButtonsActivated && leftButtonsOpen && leftButtonsCloseReleaseAnimationFn) {
|
|
|
374
|
+ return leftButtonsCloseReleaseAnimationFn;
|
|
|
375
|
+ }
|
|
|
376
|
+
|
|
|
377
|
+ if (rightButtonsActivated && rightButtonsOpenReleaseAnimationFn) {
|
|
|
378
|
+ return rightButtonsOpenReleaseAnimationFn;
|
|
|
379
|
+ }
|
|
|
380
|
+
|
|
|
381
|
+ if (!rightButtonsActivated && rightButtonsOpen && rightButtonsCloseReleaseAnimationFn) {
|
|
|
382
|
+ return rightButtonsCloseReleaseAnimationFn;
|
|
|
383
|
+ }
|
|
|
384
|
+
|
|
|
385
|
+ return swipeReleaseAnimationFn;
|
|
|
386
|
+ }
|
|
|
387
|
+ }, {
|
|
|
388
|
+ key: '_getReleaseAnimationConfig',
|
|
|
389
|
+ value: function _getReleaseAnimationConfig() {
|
|
|
390
|
+ var _props5 = this.props,
|
|
|
391
|
+ leftActionReleaseAnimationConfig = _props5.leftActionReleaseAnimationConfig,
|
|
|
392
|
+ leftButtons = _props5.leftButtons,
|
|
|
393
|
+ leftButtonsOpenReleaseAnimationConfig = _props5.leftButtonsOpenReleaseAnimationConfig,
|
|
|
394
|
+ leftButtonsCloseReleaseAnimationConfig = _props5.leftButtonsCloseReleaseAnimationConfig,
|
|
|
395
|
+ leftButtonWidth = _props5.leftButtonWidth,
|
|
|
396
|
+ rightActionReleaseAnimationConfig = _props5.rightActionReleaseAnimationConfig,
|
|
|
397
|
+ rightButtons = _props5.rightButtons,
|
|
|
398
|
+ rightButtonsOpenReleaseAnimationConfig = _props5.rightButtonsOpenReleaseAnimationConfig,
|
|
|
399
|
+ rightButtonsCloseReleaseAnimationConfig = _props5.rightButtonsCloseReleaseAnimationConfig,
|
|
|
400
|
+ rightButtonWidth = _props5.rightButtonWidth,
|
|
|
401
|
+ swipeReleaseAnimationConfig = _props5.swipeReleaseAnimationConfig;
|
|
|
402
|
+ var _state2 = this.state,
|
|
|
403
|
+ leftActionActivated = _state2.leftActionActivated,
|
|
|
404
|
+ leftButtonsActivated = _state2.leftButtonsActivated,
|
|
|
405
|
+ leftButtonsOpen = _state2.leftButtonsOpen,
|
|
|
406
|
+ rightActionActivated = _state2.rightActionActivated,
|
|
|
407
|
+ rightButtonsActivated = _state2.rightButtonsActivated,
|
|
|
408
|
+ rightButtonsOpen = _state2.rightButtonsOpen;
|
|
|
409
|
+
|
|
|
410
|
+
|
|
|
411
|
+ if (leftActionActivated && leftActionReleaseAnimationConfig) {
|
|
|
412
|
+ return leftActionReleaseAnimationConfig;
|
|
|
413
|
+ }
|
|
|
414
|
+
|
|
|
415
|
+ if (rightActionActivated && rightActionReleaseAnimationConfig) {
|
|
|
416
|
+ return rightActionReleaseAnimationConfig;
|
|
|
417
|
+ }
|
|
|
418
|
+
|
|
|
419
|
+ if (leftButtonsActivated) {
|
|
|
420
|
+ return _extends({}, swipeReleaseAnimationConfig, {
|
|
|
421
|
+ toValue: {
|
|
|
422
|
+ x: leftButtons.length * leftButtonWidth,
|
|
|
423
|
+ y: 0
|
|
|
424
|
+ }
|
|
|
425
|
+ }, leftButtonsOpenReleaseAnimationConfig);
|
|
|
426
|
+ }
|
|
|
427
|
+
|
|
|
428
|
+ if (rightButtonsActivated) {
|
|
|
429
|
+ return _extends({}, swipeReleaseAnimationConfig, {
|
|
|
430
|
+ toValue: {
|
|
|
431
|
+ x: rightButtons.length * rightButtonWidth * -1,
|
|
|
432
|
+ y: 0
|
|
|
433
|
+ }
|
|
|
434
|
+ }, rightButtonsOpenReleaseAnimationConfig);
|
|
|
435
|
+ }
|
|
|
436
|
+
|
|
|
437
|
+ if (!leftButtonsActivated && leftButtonsOpen && leftButtonsCloseReleaseAnimationConfig) {
|
|
|
438
|
+ return leftButtonsCloseReleaseAnimationConfig;
|
|
|
439
|
+ }
|
|
|
440
|
+
|
|
|
441
|
+ if (!rightButtonsActivated && rightButtonsOpen && rightButtonsCloseReleaseAnimationConfig) {
|
|
|
442
|
+ return rightButtonsCloseReleaseAnimationConfig;
|
|
|
443
|
+ }
|
|
|
444
|
+
|
|
|
445
|
+ return swipeReleaseAnimationConfig;
|
|
|
446
|
+ }
|
|
|
447
|
+ }, {
|
|
|
448
|
+ key: '_renderButtons',
|
|
|
449
|
+ value: function _renderButtons(buttons, isLeftButtons) {
|
|
|
450
|
+ var _props6 = this.props,
|
|
|
451
|
+ leftButtonContainerStyle = _props6.leftButtonContainerStyle,
|
|
|
452
|
+ rightButtonContainerStyle = _props6.rightButtonContainerStyle;
|
|
|
453
|
+ var _state3 = this.state,
|
|
|
454
|
+ pan = _state3.pan,
|
|
|
455
|
+ width = _state3.width;
|
|
|
456
|
+
|
|
|
457
|
+ var canSwipeLeft = this._canSwipeLeft();
|
|
|
458
|
+ var canSwipeRight = this._canSwipeRight();
|
|
|
459
|
+ var count = buttons.length;
|
|
|
460
|
+ var leftEnd = canSwipeLeft ? -width : 0;
|
|
|
461
|
+ var rightEnd = canSwipeRight ? width : 0;
|
|
|
462
|
+ var inputRange = isLeftButtons ? [0, rightEnd] : [leftEnd, 0];
|
|
|
463
|
+
|
|
|
464
|
+ return buttons.map(function (buttonContent, index) {
|
|
|
465
|
+ var outputMultiplier = -index / count;
|
|
|
466
|
+ var outputRange = isLeftButtons ? [0, rightEnd * outputMultiplier] : [leftEnd * outputMultiplier, 0];
|
|
|
467
|
+ var transform = [{
|
|
|
468
|
+ translateX: pan.x.interpolate({
|
|
|
469
|
+ inputRange: inputRange,
|
|
|
470
|
+ outputRange: outputRange,
|
|
|
471
|
+ extrapolate: 'clamp'
|
|
|
472
|
+ })
|
|
|
473
|
+ }];
|
|
|
474
|
+ var buttonStyle = [_reactNative.StyleSheet.absoluteFill, { width: width, transform: transform }, isLeftButtons ? leftButtonContainerStyle : rightButtonContainerStyle];
|
|
|
475
|
+
|
|
|
476
|
+ return _react2.default.createElement(
|
|
|
477
|
+ _reactNative.Animated.View,
|
|
|
478
|
+ { key: index, style: buttonStyle },
|
|
|
479
|
+ buttonContent
|
|
|
480
|
+ );
|
|
|
481
|
+ });
|
|
|
482
|
+ }
|
|
|
483
|
+ }, {
|
|
|
484
|
+ key: 'render',
|
|
|
485
|
+ value: function render() {
|
|
|
486
|
+ var _props7 = this.props,
|
|
|
487
|
+ children = _props7.children,
|
|
|
488
|
+ contentContainerStyle = _props7.contentContainerStyle,
|
|
|
489
|
+ leftButtons = _props7.leftButtons,
|
|
|
490
|
+ leftContainerStyle = _props7.leftContainerStyle,
|
|
|
491
|
+ leftContent = _props7.leftContent,
|
|
|
492
|
+ rightButtons = _props7.rightButtons,
|
|
|
493
|
+ rightContainerStyle = _props7.rightContainerStyle,
|
|
|
494
|
+ rightContent = _props7.rightContent,
|
|
|
495
|
+ style = _props7.style,
|
|
|
496
|
+ props = _objectWithoutProperties(_props7, ['children', 'contentContainerStyle', 'leftButtons', 'leftContainerStyle', 'leftContent', 'rightButtons', 'rightContainerStyle', 'rightContent', 'style']);
|
|
|
497
|
+
|
|
|
498
|
+ var _state4 = this.state,
|
|
|
499
|
+ pan = _state4.pan,
|
|
|
500
|
+ width = _state4.width;
|
|
|
501
|
+
|
|
|
502
|
+ var canSwipeLeft = this._canSwipeLeft();
|
|
|
503
|
+ var canSwipeRight = this._canSwipeRight();
|
|
|
504
|
+ var transform = [{
|
|
|
505
|
+ translateX: pan.x.interpolate({
|
|
|
506
|
+ inputRange: [canSwipeLeft ? -width : 0, canSwipeRight ? width : 0],
|
|
|
507
|
+ outputRange: [canSwipeLeft ? -width + _reactNative.StyleSheet.hairlineWidth : 0, canSwipeRight ? width - _reactNative.StyleSheet.hairlineWidth : 0],
|
|
|
508
|
+ extrapolate: 'clamp'
|
|
|
509
|
+ })
|
|
|
510
|
+ }];
|
|
|
511
|
+
|
|
|
512
|
+ return _react2.default.createElement(
|
|
|
513
|
+ _reactNative.View,
|
|
|
514
|
+ _extends({ onLayout: this._handleLayout, style: [styles.container, style] }, this._panResponder.panHandlers, props),
|
|
|
515
|
+ canSwipeRight && _react2.default.createElement(
|
|
|
516
|
+ _reactNative.Animated.View,
|
|
|
517
|
+ { style: [{ transform: transform, marginLeft: -width, width: width }, leftContainerStyle] },
|
|
|
518
|
+ leftContent || this._renderButtons(leftButtons, true)
|
|
|
519
|
+ ),
|
|
|
520
|
+ _react2.default.createElement(
|
|
|
521
|
+ _reactNative.Animated.View,
|
|
|
522
|
+ { style: [{ transform: transform }, styles.content, contentContainerStyle] },
|
|
|
523
|
+ children
|
|
|
524
|
+ ),
|
|
|
525
|
+ canSwipeLeft && _react2.default.createElement(
|
|
|
526
|
+ _reactNative.Animated.View,
|
|
|
527
|
+ { style: [{ transform: transform, marginRight: -width, width: width }, rightContainerStyle] },
|
|
|
528
|
+ rightContent || this._renderButtons(rightButtons, false)
|
|
|
529
|
+ )
|
|
|
530
|
+ );
|
|
|
531
|
+ }
|
|
|
532
|
+ }]);
|
|
|
533
|
+
|
|
|
534
|
+ return Swipeable;
|
|
|
535
|
+}(_react.PureComponent);
|
|
|
536
|
+
|
|
|
537
|
+Swipeable.propTypes = {
|
|
|
538
|
+ // elements
|
|
|
539
|
+ children: _propTypes.PropTypes.any,
|
|
|
540
|
+ leftContent: _propTypes.PropTypes.any,
|
|
|
541
|
+ rightContent: _propTypes.PropTypes.any,
|
|
|
542
|
+ leftButtons: _propTypes.PropTypes.array,
|
|
|
543
|
+ rightButtons: _propTypes.PropTypes.array,
|
|
|
544
|
+
|
|
|
545
|
+ // left action lifecycle
|
|
|
546
|
+ onLeftActionActivate: _propTypes.PropTypes.func,
|
|
|
547
|
+ onLeftActionDeactivate: _propTypes.PropTypes.func,
|
|
|
548
|
+ onLeftActionRelease: _propTypes.PropTypes.func,
|
|
|
549
|
+ onLeftActionComplete: _propTypes.PropTypes.func,
|
|
|
550
|
+ leftActionActivationDistance: _propTypes.PropTypes.number,
|
|
|
551
|
+ leftActionReleaseAnimationFn: animationFnPropType,
|
|
|
552
|
+ leftActionReleaseAnimationConfig: _propTypes.PropTypes.object,
|
|
|
553
|
+
|
|
|
554
|
+ // right action lifecycle
|
|
|
555
|
+ onRightActionActivate: _propTypes.PropTypes.func,
|
|
|
556
|
+ onRightActionDeactivate: _propTypes.PropTypes.func,
|
|
|
557
|
+ onRightActionRelease: _propTypes.PropTypes.func,
|
|
|
558
|
+ onRightActionComplete: _propTypes.PropTypes.func,
|
|
|
559
|
+ rightActionActivationDistance: _propTypes.PropTypes.number,
|
|
|
560
|
+ rightActionReleaseAnimationFn: animationFnPropType,
|
|
|
561
|
+ rightActionReleaseAnimationConfig: _propTypes.PropTypes.object,
|
|
|
562
|
+
|
|
|
563
|
+ // left buttons lifecycle
|
|
|
564
|
+ onLeftButtonsActivate: _propTypes.PropTypes.func,
|
|
|
565
|
+ onLeftButtonsDeactivate: _propTypes.PropTypes.func,
|
|
|
566
|
+ onLeftButtonsOpenRelease: _propTypes.PropTypes.func,
|
|
|
567
|
+ onLeftButtonsOpenComplete: _propTypes.PropTypes.func,
|
|
|
568
|
+ onLeftButtonsCloseRelease: _propTypes.PropTypes.func,
|
|
|
569
|
+ onLeftButtonsCloseComplete: _propTypes.PropTypes.func,
|
|
|
570
|
+ leftButtonWidth: _propTypes.PropTypes.number,
|
|
|
571
|
+ leftButtonsActivationDistance: _propTypes.PropTypes.number,
|
|
|
572
|
+ leftButtonsOpenReleaseAnimationFn: animationFnPropType,
|
|
|
573
|
+ leftButtonsOpenReleaseAnimationConfig: _propTypes.PropTypes.object,
|
|
|
574
|
+ leftButtonsCloseReleaseAnimationFn: animationFnPropType,
|
|
|
575
|
+ leftButtonsCloseReleaseAnimationConfig: _propTypes.PropTypes.object,
|
|
|
576
|
+
|
|
|
577
|
+ // right buttons lifecycle
|
|
|
578
|
+ onRightButtonsActivate: _propTypes.PropTypes.func,
|
|
|
579
|
+ onRightButtonsDeactivate: _propTypes.PropTypes.func,
|
|
|
580
|
+ onRightButtonsOpenRelease: _propTypes.PropTypes.func,
|
|
|
581
|
+ onRightButtonsOpenComplete: _propTypes.PropTypes.func,
|
|
|
582
|
+ onRightButtonsCloseRelease: _propTypes.PropTypes.func,
|
|
|
583
|
+ onRightButtonsCloseComplete: _propTypes.PropTypes.func,
|
|
|
584
|
+ rightButtonWidth: _propTypes.PropTypes.number,
|
|
|
585
|
+ rightButtonsActivationDistance: _propTypes.PropTypes.number,
|
|
|
586
|
+ rightButtonsOpenReleaseAnimationFn: animationFnPropType,
|
|
|
587
|
+ rightButtonsOpenReleaseAnimationConfig: _propTypes.PropTypes.object,
|
|
|
588
|
+ rightButtonsCloseReleaseAnimationFn: animationFnPropType,
|
|
|
589
|
+ rightButtonsCloseReleaseAnimationConfig: _propTypes.PropTypes.object,
|
|
|
590
|
+
|
|
|
591
|
+ // base swipe lifecycle
|
|
|
592
|
+ onSwipeStart: _propTypes.PropTypes.func,
|
|
|
593
|
+ onSwipeMove: _propTypes.PropTypes.func,
|
|
|
594
|
+ onSwipeRelease: _propTypes.PropTypes.func,
|
|
|
595
|
+ onSwipeComplete: _propTypes.PropTypes.func,
|
|
|
596
|
+ swipeReleaseAnimationFn: animationFnPropType,
|
|
|
597
|
+ swipeReleaseAnimationConfig: _propTypes.PropTypes.object,
|
|
|
598
|
+
|
|
|
599
|
+ // misc
|
|
|
600
|
+ onRef: _propTypes.PropTypes.func,
|
|
|
601
|
+ onPanAnimatedValueRef: _propTypes.PropTypes.func,
|
|
|
602
|
+ swipeStartMinDistance: _propTypes.PropTypes.number,
|
|
|
603
|
+
|
|
|
604
|
+ // styles
|
|
|
605
|
+ style: _reactNative.View.propTypes.style,
|
|
|
606
|
+ leftContainerStyle: _reactNative.View.propTypes.style,
|
|
|
607
|
+ leftButtonContainerStyle: _reactNative.View.propTypes.style,
|
|
|
608
|
+ rightContainerStyle: _reactNative.View.propTypes.style,
|
|
|
609
|
+ rightButtonContainerStyle: _reactNative.View.propTypes.style,
|
|
|
610
|
+ contentContainerStyle: _reactNative.View.propTypes.style
|
|
|
611
|
+};
|
|
|
612
|
+Swipeable.defaultProps = {
|
|
|
613
|
+ leftContent: null,
|
|
|
614
|
+ rightContent: null,
|
|
|
615
|
+ leftButtons: null,
|
|
|
616
|
+ rightButtons: null,
|
|
|
617
|
+
|
|
|
618
|
+ // left action lifecycle
|
|
|
619
|
+ onLeftActionActivate: noop,
|
|
|
620
|
+ onLeftActionDeactivate: noop,
|
|
|
621
|
+ onLeftActionRelease: noop,
|
|
|
622
|
+ onLeftActionComplete: noop,
|
|
|
623
|
+ leftActionActivationDistance: 125,
|
|
|
624
|
+ leftActionReleaseAnimationFn: null,
|
|
|
625
|
+ leftActionReleaseAnimationConfig: null,
|
|
|
626
|
+
|
|
|
627
|
+ // right action lifecycle
|
|
|
628
|
+ onRightActionActivate: noop,
|
|
|
629
|
+ onRightActionDeactivate: noop,
|
|
|
630
|
+ onRightActionRelease: noop,
|
|
|
631
|
+ onRightActionComplete: noop,
|
|
|
632
|
+ rightActionActivationDistance: 125,
|
|
|
633
|
+ rightActionReleaseAnimationFn: null,
|
|
|
634
|
+ rightActionReleaseAnimationConfig: null,
|
|
|
635
|
+
|
|
|
636
|
+ // left buttons lifecycle
|
|
|
637
|
+ onLeftButtonsActivate: noop,
|
|
|
638
|
+ onLeftButtonsDeactivate: noop,
|
|
|
639
|
+ onLeftButtonsOpenRelease: noop,
|
|
|
640
|
+ onLeftButtonsOpenComplete: noop,
|
|
|
641
|
+ onLeftButtonsCloseRelease: noop,
|
|
|
642
|
+ onLeftButtonsCloseComplete: noop,
|
|
|
643
|
+ leftButtonWidth: 75,
|
|
|
644
|
+ leftButtonsActivationDistance: 75,
|
|
|
645
|
+ leftButtonsOpenReleaseAnimationFn: null,
|
|
|
646
|
+ leftButtonsOpenReleaseAnimationConfig: null,
|
|
|
647
|
+ leftButtonsCloseReleaseAnimationFn: null,
|
|
|
648
|
+ leftButtonsCloseReleaseAnimationConfig: null,
|
|
|
649
|
+
|
|
|
650
|
+ // right buttons lifecycle
|
|
|
651
|
+ onRightButtonsActivate: noop,
|
|
|
652
|
+ onRightButtonsDeactivate: noop,
|
|
|
653
|
+ onRightButtonsOpenRelease: noop,
|
|
|
654
|
+ onRightButtonsOpenComplete: noop,
|
|
|
655
|
+ onRightButtonsCloseRelease: noop,
|
|
|
656
|
+ onRightButtonsCloseComplete: noop,
|
|
|
657
|
+ rightButtonWidth: 75,
|
|
|
658
|
+ rightButtonsActivationDistance: 75,
|
|
|
659
|
+ rightButtonsOpenReleaseAnimationFn: null,
|
|
|
660
|
+ rightButtonsOpenReleaseAnimationConfig: null,
|
|
|
661
|
+ rightButtonsCloseReleaseAnimationFn: null,
|
|
|
662
|
+ rightButtonsCloseReleaseAnimationConfig: null,
|
|
|
663
|
+
|
|
|
664
|
+ // base swipe lifecycle
|
|
|
665
|
+ onSwipeStart: noop,
|
|
|
666
|
+ onSwipeMove: noop,
|
|
|
667
|
+ onSwipeRelease: noop,
|
|
|
668
|
+ onSwipeComplete: noop,
|
|
|
669
|
+ swipeReleaseAnimationFn: _reactNative.Animated.timing,
|
|
|
670
|
+ swipeReleaseAnimationConfig: {
|
|
|
671
|
+ toValue: { x: 0, y: 0 },
|
|
|
672
|
+ duration: 250,
|
|
|
673
|
+ easing: _reactNative.Easing.elastic(0.5)
|
|
|
674
|
+ },
|
|
|
675
|
+
|
|
|
676
|
+ // misc
|
|
|
677
|
+ onRef: noop,
|
|
|
678
|
+ onPanAnimatedValueRef: noop,
|
|
|
679
|
+ swipeStartMinDistance: 15
|
|
|
680
|
+};
|
|
|
681
|
+exports.default = Swipeable;
|
|
|
682
|
+
|
|
|
683
|
+
|
|
|
684
|
+var styles = _reactNative.StyleSheet.create({
|
|
|
685
|
+ container: {
|
|
|
686
|
+ flexDirection: 'row'
|
|
|
687
|
+ },
|
|
|
688
|
+ content: {
|
|
|
689
|
+ flex: 1
|
|
|
690
|
+ }
|
|
|
691
|
+}); |