@react-navigation/stack 7.0.12 → 7.0.14
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.
- package/lib/commonjs/views/Stack/Card.js +379 -410
- package/lib/commonjs/views/Stack/Card.js.map +1 -1
- package/lib/commonjs/views/Stack/CardStack.js +331 -352
- package/lib/commonjs/views/Stack/CardStack.js.map +1 -1
- package/lib/commonjs/views/Stack/StackView.js +293 -317
- package/lib/commonjs/views/Stack/StackView.js.map +1 -1
- package/lib/module/views/Stack/Card.js +378 -410
- package/lib/module/views/Stack/Card.js.map +1 -1
- package/lib/module/views/Stack/CardStack.js +330 -352
- package/lib/module/views/Stack/CardStack.js.map +1 -1
- package/lib/module/views/Stack/StackView.js +292 -317
- package/lib/module/views/Stack/StackView.js.map +1 -1
- package/lib/typescript/commonjs/src/views/Stack/StackView.d.ts +2 -2
- package/lib/typescript/module/src/views/Stack/StackView.d.ts +2 -2
- package/package.json +6 -6
- package/lib/commonjs/package.json +0 -1
- package/lib/module/package.json +0 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +0 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
4
|
-
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
5
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
6
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
7
|
-
function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
8
|
-
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
9
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
10
|
-
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
11
|
-
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
12
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
13
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
15
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
3
|
import Color from 'color';
|
|
17
4
|
import * as React from 'react';
|
|
18
5
|
import { Animated, InteractionManager, Platform, StyleSheet, View } from 'react-native';
|
|
@@ -41,432 +28,413 @@ const hasOpacityStyle = style => {
|
|
|
41
28
|
}
|
|
42
29
|
return false;
|
|
43
30
|
};
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_defineProperty(_this, "animate", ({
|
|
61
|
-
closing,
|
|
62
|
-
velocity
|
|
63
|
-
}) => {
|
|
64
|
-
const {
|
|
65
|
-
transitionSpec,
|
|
66
|
-
onOpen,
|
|
67
|
-
onClose,
|
|
68
|
-
onTransition,
|
|
69
|
-
gesture
|
|
70
|
-
} = _this.props;
|
|
71
|
-
const toValue = _this.getAnimateToValue({
|
|
72
|
-
..._this.props,
|
|
73
|
-
closing
|
|
31
|
+
export class Card extends React.Component {
|
|
32
|
+
static defaultProps = {
|
|
33
|
+
shadowEnabled: false,
|
|
34
|
+
gestureEnabled: true,
|
|
35
|
+
gestureVelocityImpact: GESTURE_VELOCITY_IMPACT,
|
|
36
|
+
overlay: ({
|
|
37
|
+
style
|
|
38
|
+
}) => style ? /*#__PURE__*/_jsx(Animated.View, {
|
|
39
|
+
pointerEvents: "none",
|
|
40
|
+
style: [styles.overlay, style]
|
|
41
|
+
}) : null
|
|
42
|
+
};
|
|
43
|
+
componentDidMount() {
|
|
44
|
+
if (!this.props.preloaded) {
|
|
45
|
+
this.animate({
|
|
46
|
+
closing: this.props.closing
|
|
74
47
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
48
|
+
}
|
|
49
|
+
this.isCurrentlyMounted = true;
|
|
50
|
+
}
|
|
51
|
+
componentDidUpdate(prevProps) {
|
|
52
|
+
const {
|
|
53
|
+
gesture,
|
|
54
|
+
direction,
|
|
55
|
+
layout,
|
|
56
|
+
gestureDirection,
|
|
57
|
+
opening,
|
|
58
|
+
closing
|
|
59
|
+
} = this.props;
|
|
60
|
+
const {
|
|
61
|
+
width,
|
|
62
|
+
height
|
|
63
|
+
} = layout;
|
|
64
|
+
if (width !== prevProps.layout.width) {
|
|
65
|
+
this.layout.width.setValue(width);
|
|
66
|
+
}
|
|
67
|
+
if (height !== prevProps.layout.height) {
|
|
68
|
+
this.layout.height.setValue(height);
|
|
69
|
+
}
|
|
70
|
+
if (gestureDirection !== prevProps.gestureDirection) {
|
|
71
|
+
this.inverted.setValue(getInvertedMultiplier(gestureDirection, direction === 'rtl'));
|
|
72
|
+
}
|
|
73
|
+
const toValue = this.getAnimateToValue(this.props);
|
|
74
|
+
if (this.getAnimateToValue(prevProps) !== toValue || this.lastToValue !== toValue) {
|
|
75
|
+
// We need to trigger the animation when route was closed
|
|
76
|
+
// The route might have been closed by a `POP` action or by a gesture
|
|
77
|
+
// When route was closed due to a gesture, the animation would've happened already
|
|
78
|
+
// It's still important to trigger the animation so that `onClose` is called
|
|
79
|
+
// If `onClose` is not called, cleanup step won't be performed for gestures
|
|
80
|
+
this.animate({
|
|
81
|
+
closing
|
|
85
82
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}).start(({
|
|
93
|
-
finished
|
|
94
|
-
}) => {
|
|
95
|
-
_this.handleEndInteraction();
|
|
96
|
-
clearTimeout(_this.pendingGestureCallback);
|
|
97
|
-
if (finished) {
|
|
98
|
-
if (closing) {
|
|
99
|
-
onClose();
|
|
100
|
-
} else {
|
|
101
|
-
onOpen();
|
|
102
|
-
}
|
|
103
|
-
if (_this.isCurrentlyMounted) {
|
|
104
|
-
// Make sure to re-open screen if it wasn't removed
|
|
105
|
-
_this.forceUpdate();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
83
|
+
} else if (opening && !prevProps.opening) {
|
|
84
|
+
// This can happen when screen somewhere below in the stack comes into focus via rearranging
|
|
85
|
+
// Also reset the animated value to make sure that the animation starts from the beginning
|
|
86
|
+
gesture.setValue(getDistanceForDirection(layout, gestureDirection, direction === 'rtl'));
|
|
87
|
+
this.animate({
|
|
88
|
+
closing
|
|
108
89
|
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
componentWillUnmount() {
|
|
93
|
+
this.props.gesture?.stopAnimation();
|
|
94
|
+
this.isCurrentlyMounted = false;
|
|
95
|
+
this.handleEndInteraction();
|
|
96
|
+
}
|
|
97
|
+
isCurrentlyMounted = false;
|
|
98
|
+
isClosing = new Animated.Value(FALSE);
|
|
99
|
+
inverted = new Animated.Value(getInvertedMultiplier(this.props.gestureDirection, this.props.direction === 'rtl'));
|
|
100
|
+
layout = {
|
|
101
|
+
width: new Animated.Value(this.props.layout.width),
|
|
102
|
+
height: new Animated.Value(this.props.layout.height)
|
|
103
|
+
};
|
|
104
|
+
isSwiping = new Animated.Value(FALSE);
|
|
105
|
+
animate = ({
|
|
106
|
+
closing,
|
|
107
|
+
velocity
|
|
108
|
+
}) => {
|
|
109
|
+
const {
|
|
110
|
+
transitionSpec,
|
|
111
|
+
onOpen,
|
|
112
|
+
onClose,
|
|
113
|
+
onTransition,
|
|
114
|
+
gesture
|
|
115
|
+
} = this.props;
|
|
116
|
+
const toValue = this.getAnimateToValue({
|
|
117
|
+
...this.props,
|
|
118
|
+
closing
|
|
109
119
|
});
|
|
110
|
-
|
|
120
|
+
this.lastToValue = toValue;
|
|
121
|
+
this.isClosing.setValue(closing ? TRUE : FALSE);
|
|
122
|
+
const spec = closing ? transitionSpec.close : transitionSpec.open;
|
|
123
|
+
const animation = spec.animation === 'spring' ? Animated.spring : Animated.timing;
|
|
124
|
+
this.setPointerEventsEnabled(!closing);
|
|
125
|
+
this.handleStartInteraction();
|
|
126
|
+
clearTimeout(this.pendingGestureCallback);
|
|
127
|
+
onTransition?.({
|
|
111
128
|
closing,
|
|
112
|
-
|
|
113
|
-
gestureDirection,
|
|
114
|
-
direction,
|
|
115
|
-
preloaded
|
|
116
|
-
}) => {
|
|
117
|
-
if (!closing && !preloaded) {
|
|
118
|
-
return 0;
|
|
119
|
-
}
|
|
120
|
-
return getDistanceForDirection(layout, gestureDirection, direction === 'rtl');
|
|
129
|
+
gesture: velocity !== undefined
|
|
121
130
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
animation(gesture, {
|
|
132
|
+
...spec.config,
|
|
133
|
+
velocity,
|
|
134
|
+
toValue,
|
|
135
|
+
useNativeDriver,
|
|
136
|
+
isInteraction: false
|
|
137
|
+
}).start(({
|
|
138
|
+
finished
|
|
139
|
+
}) => {
|
|
140
|
+
this.handleEndInteraction();
|
|
141
|
+
clearTimeout(this.pendingGestureCallback);
|
|
142
|
+
if (finished) {
|
|
143
|
+
if (closing) {
|
|
144
|
+
onClose();
|
|
145
|
+
} else {
|
|
146
|
+
onOpen();
|
|
147
|
+
}
|
|
148
|
+
if (this.isCurrentlyMounted) {
|
|
149
|
+
// Make sure to re-open screen if it wasn't removed
|
|
150
|
+
this.forceUpdate();
|
|
151
|
+
}
|
|
135
152
|
}
|
|
136
153
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
154
|
+
};
|
|
155
|
+
getAnimateToValue = ({
|
|
156
|
+
closing,
|
|
157
|
+
layout,
|
|
158
|
+
gestureDirection,
|
|
159
|
+
direction,
|
|
160
|
+
preloaded
|
|
161
|
+
}) => {
|
|
162
|
+
if (!closing && !preloaded) {
|
|
163
|
+
return 0;
|
|
164
|
+
}
|
|
165
|
+
return getDistanceForDirection(layout, gestureDirection, direction === 'rtl');
|
|
166
|
+
};
|
|
167
|
+
setPointerEventsEnabled = enabled => {
|
|
168
|
+
const pointerEvents = enabled ? 'box-none' : 'none';
|
|
169
|
+
this.ref.current?.setPointerEvents(pointerEvents);
|
|
170
|
+
};
|
|
171
|
+
handleStartInteraction = () => {
|
|
172
|
+
if (this.interactionHandle === undefined) {
|
|
173
|
+
this.interactionHandle = InteractionManager.createInteractionHandle();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
handleEndInteraction = () => {
|
|
177
|
+
if (this.interactionHandle !== undefined) {
|
|
178
|
+
InteractionManager.clearInteractionHandle(this.interactionHandle);
|
|
179
|
+
this.interactionHandle = undefined;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
handleGestureStateChange = ({
|
|
183
|
+
nativeEvent
|
|
184
|
+
}) => {
|
|
185
|
+
const {
|
|
186
|
+
direction,
|
|
187
|
+
layout,
|
|
188
|
+
onClose,
|
|
189
|
+
onGestureBegin,
|
|
190
|
+
onGestureCanceled,
|
|
191
|
+
onGestureEnd,
|
|
192
|
+
gestureDirection,
|
|
193
|
+
gestureVelocityImpact
|
|
194
|
+
} = this.props;
|
|
195
|
+
switch (nativeEvent.state) {
|
|
196
|
+
case GestureState.ACTIVE:
|
|
197
|
+
this.isSwiping.setValue(TRUE);
|
|
198
|
+
this.handleStartInteraction();
|
|
199
|
+
onGestureBegin?.();
|
|
200
|
+
break;
|
|
201
|
+
case GestureState.CANCELLED:
|
|
202
|
+
case GestureState.FAILED:
|
|
203
|
+
{
|
|
204
|
+
this.isSwiping.setValue(FALSE);
|
|
205
|
+
this.handleEndInteraction();
|
|
206
|
+
const velocity = gestureDirection === 'vertical' || gestureDirection === 'vertical-inverted' ? nativeEvent.velocityY : nativeEvent.velocityX;
|
|
207
|
+
this.animate({
|
|
208
|
+
closing: this.props.closing,
|
|
209
|
+
velocity
|
|
210
|
+
});
|
|
211
|
+
onGestureCanceled?.();
|
|
155
212
|
break;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
213
|
+
}
|
|
214
|
+
case GestureState.END:
|
|
215
|
+
{
|
|
216
|
+
this.isSwiping.setValue(FALSE);
|
|
217
|
+
let distance;
|
|
218
|
+
let translation;
|
|
219
|
+
let velocity;
|
|
220
|
+
if (gestureDirection === 'vertical' || gestureDirection === 'vertical-inverted') {
|
|
221
|
+
distance = layout.height;
|
|
222
|
+
translation = nativeEvent.translationY;
|
|
223
|
+
velocity = nativeEvent.velocityY;
|
|
224
|
+
} else {
|
|
225
|
+
distance = layout.width;
|
|
226
|
+
translation = nativeEvent.translationX;
|
|
227
|
+
velocity = nativeEvent.velocityX;
|
|
168
228
|
}
|
|
169
|
-
|
|
170
|
-
{
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
} else {
|
|
180
|
-
distance = layout.width;
|
|
181
|
-
translation = nativeEvent.translationX;
|
|
182
|
-
velocity = nativeEvent.velocityX;
|
|
183
|
-
}
|
|
184
|
-
const closing = (translation + velocity * gestureVelocityImpact) * getInvertedMultiplier(gestureDirection, direction === 'rtl') > distance / 2 ? velocity !== 0 || translation !== 0 : _this.props.closing;
|
|
185
|
-
_this.animate({
|
|
186
|
-
closing,
|
|
187
|
-
velocity
|
|
188
|
-
});
|
|
189
|
-
if (closing) {
|
|
190
|
-
// We call onClose with a delay to make sure that the animation has already started
|
|
191
|
-
// This will make sure that the state update caused by this doesn't affect start of animation
|
|
192
|
-
_this.pendingGestureCallback = setTimeout(() => {
|
|
193
|
-
onClose();
|
|
229
|
+
const closing = (translation + velocity * gestureVelocityImpact) * getInvertedMultiplier(gestureDirection, direction === 'rtl') > distance / 2 ? velocity !== 0 || translation !== 0 : this.props.closing;
|
|
230
|
+
this.animate({
|
|
231
|
+
closing,
|
|
232
|
+
velocity
|
|
233
|
+
});
|
|
234
|
+
if (closing) {
|
|
235
|
+
// We call onClose with a delay to make sure that the animation has already started
|
|
236
|
+
// This will make sure that the state update caused by this doesn't affect start of animation
|
|
237
|
+
this.pendingGestureCallback = setTimeout(() => {
|
|
238
|
+
onClose();
|
|
194
239
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
onGestureEnd?.();
|
|
201
|
-
break;
|
|
240
|
+
// Trigger an update after we dispatch the action to remove the screen
|
|
241
|
+
// This will make sure that we check if the screen didn't get removed so we can cancel the animation
|
|
242
|
+
this.forceUpdate();
|
|
243
|
+
}, 32);
|
|
202
244
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
_defineProperty(_this, "getInterpolatedStyle", memoize((styleInterpolator, animation) => styleInterpolator(animation)));
|
|
207
|
-
// Keep track of the animation context when deps changes.
|
|
208
|
-
_defineProperty(_this, "getCardAnimation", memoize((interpolationIndex, current, next, layout, insetTop, insetRight, insetBottom, insetLeft) => ({
|
|
209
|
-
index: interpolationIndex,
|
|
210
|
-
current: {
|
|
211
|
-
progress: current
|
|
212
|
-
},
|
|
213
|
-
next: next && {
|
|
214
|
-
progress: next
|
|
215
|
-
},
|
|
216
|
-
closing: _this.isClosing,
|
|
217
|
-
swiping: _this.isSwiping,
|
|
218
|
-
inverted: _this.inverted,
|
|
219
|
-
layouts: {
|
|
220
|
-
screen: layout
|
|
221
|
-
},
|
|
222
|
-
insets: {
|
|
223
|
-
top: insetTop,
|
|
224
|
-
right: insetRight,
|
|
225
|
-
bottom: insetBottom,
|
|
226
|
-
left: insetLeft
|
|
227
|
-
}
|
|
228
|
-
})));
|
|
229
|
-
_defineProperty(_this, "ref", /*#__PURE__*/React.createRef());
|
|
230
|
-
return _this;
|
|
231
|
-
}
|
|
232
|
-
_inherits(Card, _React$Component);
|
|
233
|
-
return _createClass(Card, [{
|
|
234
|
-
key: "componentDidMount",
|
|
235
|
-
value: function componentDidMount() {
|
|
236
|
-
if (!this.props.preloaded) {
|
|
237
|
-
this.animate({
|
|
238
|
-
closing: this.props.closing
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
this.isCurrentlyMounted = true;
|
|
242
|
-
}
|
|
243
|
-
}, {
|
|
244
|
-
key: "componentDidUpdate",
|
|
245
|
-
value: function componentDidUpdate(prevProps) {
|
|
246
|
-
const {
|
|
247
|
-
gesture,
|
|
248
|
-
direction,
|
|
249
|
-
layout,
|
|
250
|
-
gestureDirection,
|
|
251
|
-
opening,
|
|
252
|
-
closing
|
|
253
|
-
} = this.props;
|
|
254
|
-
const {
|
|
255
|
-
width,
|
|
256
|
-
height
|
|
257
|
-
} = layout;
|
|
258
|
-
if (width !== prevProps.layout.width) {
|
|
259
|
-
this.layout.width.setValue(width);
|
|
260
|
-
}
|
|
261
|
-
if (height !== prevProps.layout.height) {
|
|
262
|
-
this.layout.height.setValue(height);
|
|
263
|
-
}
|
|
264
|
-
if (gestureDirection !== prevProps.gestureDirection) {
|
|
265
|
-
this.inverted.setValue(getInvertedMultiplier(gestureDirection, direction === 'rtl'));
|
|
266
|
-
}
|
|
267
|
-
const toValue = this.getAnimateToValue(this.props);
|
|
268
|
-
if (this.getAnimateToValue(prevProps) !== toValue || this.lastToValue !== toValue) {
|
|
269
|
-
// We need to trigger the animation when route was closed
|
|
270
|
-
// The route might have been closed by a `POP` action or by a gesture
|
|
271
|
-
// When route was closed due to a gesture, the animation would've happened already
|
|
272
|
-
// It's still important to trigger the animation so that `onClose` is called
|
|
273
|
-
// If `onClose` is not called, cleanup step won't be performed for gestures
|
|
274
|
-
this.animate({
|
|
275
|
-
closing
|
|
276
|
-
});
|
|
277
|
-
} else if (opening && !prevProps.opening) {
|
|
278
|
-
// This can happen when screen somewhere below in the stack comes into focus via rearranging
|
|
279
|
-
// Also reset the animated value to make sure that the animation starts from the beginning
|
|
280
|
-
gesture.setValue(getDistanceForDirection(layout, gestureDirection, direction === 'rtl'));
|
|
281
|
-
this.animate({
|
|
282
|
-
closing
|
|
283
|
-
});
|
|
284
|
-
}
|
|
245
|
+
onGestureEnd?.();
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
285
248
|
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// Memoize this to avoid extra work on re-render
|
|
252
|
+
getInterpolatedStyle = memoize((styleInterpolator, animation) => styleInterpolator(animation));
|
|
253
|
+
|
|
254
|
+
// Keep track of the animation context when deps changes.
|
|
255
|
+
getCardAnimation = memoize((interpolationIndex, current, next, layout, insetTop, insetRight, insetBottom, insetLeft) => ({
|
|
256
|
+
index: interpolationIndex,
|
|
257
|
+
current: {
|
|
258
|
+
progress: current
|
|
259
|
+
},
|
|
260
|
+
next: next && {
|
|
261
|
+
progress: next
|
|
262
|
+
},
|
|
263
|
+
closing: this.isClosing,
|
|
264
|
+
swiping: this.isSwiping,
|
|
265
|
+
inverted: this.inverted,
|
|
266
|
+
layouts: {
|
|
267
|
+
screen: layout
|
|
268
|
+
},
|
|
269
|
+
insets: {
|
|
270
|
+
top: insetTop,
|
|
271
|
+
right: insetRight,
|
|
272
|
+
bottom: insetBottom,
|
|
273
|
+
left: insetLeft
|
|
292
274
|
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
275
|
+
}));
|
|
276
|
+
gestureActivationCriteria() {
|
|
277
|
+
const {
|
|
278
|
+
direction,
|
|
279
|
+
layout,
|
|
280
|
+
gestureDirection,
|
|
281
|
+
gestureResponseDistance
|
|
282
|
+
} = this.props;
|
|
283
|
+
const enableTrackpadTwoFingerGesture = true;
|
|
284
|
+
const distance = gestureResponseDistance !== undefined ? gestureResponseDistance : gestureDirection === 'vertical' || gestureDirection === 'vertical-inverted' ? GESTURE_RESPONSE_DISTANCE_VERTICAL : GESTURE_RESPONSE_DISTANCE_HORIZONTAL;
|
|
285
|
+
if (gestureDirection === 'vertical') {
|
|
286
|
+
return {
|
|
287
|
+
maxDeltaX: 15,
|
|
288
|
+
minOffsetY: 5,
|
|
289
|
+
hitSlop: {
|
|
290
|
+
bottom: -layout.height + distance
|
|
291
|
+
},
|
|
292
|
+
enableTrackpadTwoFingerGesture
|
|
293
|
+
};
|
|
294
|
+
} else if (gestureDirection === 'vertical-inverted') {
|
|
295
|
+
return {
|
|
296
|
+
maxDeltaX: 15,
|
|
297
|
+
minOffsetY: -5,
|
|
298
|
+
hitSlop: {
|
|
299
|
+
top: -layout.height + distance
|
|
300
|
+
},
|
|
301
|
+
enableTrackpadTwoFingerGesture
|
|
302
|
+
};
|
|
303
|
+
} else {
|
|
304
|
+
const hitSlop = -layout.width + distance;
|
|
305
|
+
const invertedMultiplier = getInvertedMultiplier(gestureDirection, direction === 'rtl');
|
|
306
|
+
if (invertedMultiplier === 1) {
|
|
305
307
|
return {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
+
minOffsetX: 5,
|
|
309
|
+
maxDeltaY: 20,
|
|
308
310
|
hitSlop: {
|
|
309
|
-
|
|
311
|
+
right: hitSlop
|
|
310
312
|
},
|
|
311
313
|
enableTrackpadTwoFingerGesture
|
|
312
314
|
};
|
|
313
|
-
} else
|
|
315
|
+
} else {
|
|
314
316
|
return {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
+
minOffsetX: -5,
|
|
318
|
+
maxDeltaY: 20,
|
|
317
319
|
hitSlop: {
|
|
318
|
-
|
|
320
|
+
left: hitSlop
|
|
319
321
|
},
|
|
320
322
|
enableTrackpadTwoFingerGesture
|
|
321
323
|
};
|
|
322
|
-
} else {
|
|
323
|
-
const hitSlop = -layout.width + distance;
|
|
324
|
-
const invertedMultiplier = getInvertedMultiplier(gestureDirection, direction === 'rtl');
|
|
325
|
-
if (invertedMultiplier === 1) {
|
|
326
|
-
return {
|
|
327
|
-
minOffsetX: 5,
|
|
328
|
-
maxDeltaY: 20,
|
|
329
|
-
hitSlop: {
|
|
330
|
-
right: hitSlop
|
|
331
|
-
},
|
|
332
|
-
enableTrackpadTwoFingerGesture
|
|
333
|
-
};
|
|
334
|
-
} else {
|
|
335
|
-
return {
|
|
336
|
-
minOffsetX: -5,
|
|
337
|
-
maxDeltaY: 20,
|
|
338
|
-
hitSlop: {
|
|
339
|
-
left: hitSlop
|
|
340
|
-
},
|
|
341
|
-
enableTrackpadTwoFingerGesture
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
324
|
}
|
|
345
325
|
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
326
|
+
}
|
|
327
|
+
ref = /*#__PURE__*/React.createRef();
|
|
328
|
+
render() {
|
|
329
|
+
const {
|
|
330
|
+
styleInterpolator,
|
|
331
|
+
interpolationIndex,
|
|
332
|
+
current,
|
|
333
|
+
gesture,
|
|
334
|
+
next,
|
|
335
|
+
layout,
|
|
336
|
+
insets,
|
|
337
|
+
overlay,
|
|
338
|
+
overlayEnabled,
|
|
339
|
+
shadowEnabled,
|
|
340
|
+
gestureEnabled,
|
|
341
|
+
gestureDirection,
|
|
342
|
+
pageOverflowEnabled,
|
|
343
|
+
children,
|
|
344
|
+
containerStyle: customContainerStyle,
|
|
345
|
+
contentStyle,
|
|
346
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
347
|
+
closing,
|
|
348
|
+
direction,
|
|
349
|
+
gestureResponseDistance,
|
|
350
|
+
gestureVelocityImpact,
|
|
351
|
+
onClose,
|
|
352
|
+
onGestureBegin,
|
|
353
|
+
onGestureCanceled,
|
|
354
|
+
onGestureEnd,
|
|
355
|
+
onOpen,
|
|
356
|
+
onTransition,
|
|
357
|
+
transitionSpec,
|
|
358
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
359
|
+
...rest
|
|
360
|
+
} = this.props;
|
|
361
|
+
const interpolationProps = this.getCardAnimation(interpolationIndex, current, next, layout, insets.top, insets.right, insets.bottom, insets.left);
|
|
362
|
+
const interpolatedStyle = this.getInterpolatedStyle(styleInterpolator, interpolationProps);
|
|
363
|
+
const {
|
|
364
|
+
containerStyle,
|
|
365
|
+
cardStyle,
|
|
366
|
+
overlayStyle,
|
|
367
|
+
shadowStyle
|
|
368
|
+
} = interpolatedStyle;
|
|
369
|
+
const handleGestureEvent = gestureEnabled ? Animated.event([{
|
|
370
|
+
nativeEvent: gestureDirection === 'vertical' || gestureDirection === 'vertical-inverted' ? {
|
|
371
|
+
translationY: gesture
|
|
372
|
+
} : {
|
|
373
|
+
translationX: gesture
|
|
374
|
+
}
|
|
375
|
+
}], {
|
|
376
|
+
useNativeDriver
|
|
377
|
+
}) : undefined;
|
|
378
|
+
const {
|
|
379
|
+
backgroundColor
|
|
380
|
+
} = StyleSheet.flatten(contentStyle || {});
|
|
381
|
+
const isTransparent = typeof backgroundColor === 'string' ? Color(backgroundColor).alpha() === 0 : false;
|
|
382
|
+
return /*#__PURE__*/_jsxs(CardAnimationContext.Provider, {
|
|
383
|
+
value: interpolationProps,
|
|
384
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
385
|
+
style: {
|
|
386
|
+
// This is a dummy style that doesn't actually change anything visually.
|
|
387
|
+
// Animated needs the animated value to be used somewhere, otherwise things don't update properly.
|
|
388
|
+
// If we disable animations and hide header, it could end up making the value unused.
|
|
389
|
+
// So we have this dummy style that will always be used regardless of what else changed.
|
|
390
|
+
opacity: current
|
|
394
391
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
,
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
onHandlerStateChange: this.handleGestureStateChange,
|
|
435
|
-
...this.gestureActivationCriteria(),
|
|
436
|
-
children: /*#__PURE__*/_jsxs(Animated.View, {
|
|
437
|
-
needsOffscreenAlphaCompositing: hasOpacityStyle(cardStyle),
|
|
438
|
-
style: [styles.container, cardStyle],
|
|
439
|
-
children: [shadowEnabled && shadowStyle && !isTransparent ? /*#__PURE__*/_jsx(Animated.View, {
|
|
440
|
-
style: [styles.shadow, gestureDirection === 'horizontal' ? [styles.shadowHorizontal, styles.shadowStart] : gestureDirection === 'horizontal-inverted' ? [styles.shadowHorizontal, styles.shadowEnd] : gestureDirection === 'vertical' ? [styles.shadowVertical, styles.shadowTop] : [styles.shadowVertical, styles.shadowBottom], {
|
|
441
|
-
backgroundColor
|
|
442
|
-
}, shadowStyle],
|
|
443
|
-
pointerEvents: "none"
|
|
444
|
-
}) : null, /*#__PURE__*/_jsx(CardSheet, {
|
|
445
|
-
ref: this.ref,
|
|
446
|
-
enabled: pageOverflowEnabled,
|
|
447
|
-
layout: layout,
|
|
448
|
-
style: contentStyle,
|
|
449
|
-
children: children
|
|
450
|
-
})]
|
|
451
|
-
})
|
|
392
|
+
// Make sure that this view isn't removed. If this view is removed, our style with animated value won't apply
|
|
393
|
+
,
|
|
394
|
+
collapsable: false
|
|
395
|
+
}), /*#__PURE__*/_jsxs(View, {
|
|
396
|
+
pointerEvents: "box-none"
|
|
397
|
+
// Make sure this view is not removed on the new architecture, as it causes focus loss during navigation on Android.
|
|
398
|
+
// This can happen when the view flattening results in different trees - due to `overflow` style changing in a parent.
|
|
399
|
+
,
|
|
400
|
+
collapsable: false,
|
|
401
|
+
...rest,
|
|
402
|
+
children: [overlayEnabled ? /*#__PURE__*/_jsx(View, {
|
|
403
|
+
pointerEvents: "box-none",
|
|
404
|
+
style: StyleSheet.absoluteFill,
|
|
405
|
+
children: overlay({
|
|
406
|
+
style: overlayStyle
|
|
407
|
+
})
|
|
408
|
+
}) : null, /*#__PURE__*/_jsx(Animated.View, {
|
|
409
|
+
style: [styles.container, containerStyle, customContainerStyle],
|
|
410
|
+
pointerEvents: "box-none",
|
|
411
|
+
children: /*#__PURE__*/_jsx(PanGestureHandler, {
|
|
412
|
+
enabled: layout.width !== 0 && gestureEnabled,
|
|
413
|
+
onGestureEvent: handleGestureEvent,
|
|
414
|
+
onHandlerStateChange: this.handleGestureStateChange,
|
|
415
|
+
...this.gestureActivationCriteria(),
|
|
416
|
+
children: /*#__PURE__*/_jsxs(Animated.View, {
|
|
417
|
+
needsOffscreenAlphaCompositing: hasOpacityStyle(cardStyle),
|
|
418
|
+
style: [styles.container, cardStyle],
|
|
419
|
+
children: [shadowEnabled && shadowStyle && !isTransparent ? /*#__PURE__*/_jsx(Animated.View, {
|
|
420
|
+
style: [styles.shadow, gestureDirection === 'horizontal' ? [styles.shadowHorizontal, styles.shadowStart] : gestureDirection === 'horizontal-inverted' ? [styles.shadowHorizontal, styles.shadowEnd] : gestureDirection === 'vertical' ? [styles.shadowVertical, styles.shadowTop] : [styles.shadowVertical, styles.shadowBottom], {
|
|
421
|
+
backgroundColor
|
|
422
|
+
}, shadowStyle],
|
|
423
|
+
pointerEvents: "none"
|
|
424
|
+
}) : null, /*#__PURE__*/_jsx(CardSheet, {
|
|
425
|
+
ref: this.ref,
|
|
426
|
+
enabled: pageOverflowEnabled,
|
|
427
|
+
layout: layout,
|
|
428
|
+
style: contentStyle,
|
|
429
|
+
children: children
|
|
430
|
+
})]
|
|
452
431
|
})
|
|
453
|
-
})
|
|
432
|
+
})
|
|
454
433
|
})]
|
|
455
|
-
})
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
_defineProperty(Card, "defaultProps", {
|
|
460
|
-
shadowEnabled: false,
|
|
461
|
-
gestureEnabled: true,
|
|
462
|
-
gestureVelocityImpact: GESTURE_VELOCITY_IMPACT,
|
|
463
|
-
overlay: ({
|
|
464
|
-
style
|
|
465
|
-
}) => style ? /*#__PURE__*/_jsx(Animated.View, {
|
|
466
|
-
pointerEvents: "none",
|
|
467
|
-
style: [styles.overlay, style]
|
|
468
|
-
}) : null
|
|
469
|
-
});
|
|
434
|
+
})]
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
}
|
|
470
438
|
const styles = StyleSheet.create({
|
|
471
439
|
container: {
|
|
472
440
|
flex: 1
|