react-native-tab-view 3.2.1 → 3.3.0
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/PagerViewAdapter.js +2 -1
- package/lib/commonjs/PagerViewAdapter.js.map +1 -1
- package/lib/commonjs/PanResponderAdapter.js +2 -1
- package/lib/commonjs/PanResponderAdapter.js.map +1 -1
- package/lib/commonjs/SceneMap.js +9 -12
- package/lib/commonjs/SceneMap.js.map +1 -1
- package/lib/commonjs/SceneView.js +54 -101
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/TabBar.js +327 -327
- package/lib/commonjs/TabBar.js.map +1 -1
- package/lib/commonjs/TabBarIndicator.js +81 -99
- package/lib/commonjs/TabBarIndicator.js.map +1 -1
- package/lib/commonjs/TabBarItem.js +184 -161
- package/lib/commonjs/TabBarItem.js.map +1 -1
- package/lib/module/PagerViewAdapter.js +2 -1
- package/lib/module/PagerViewAdapter.js.map +1 -1
- package/lib/module/PanResponderAdapter.js +2 -1
- package/lib/module/PanResponderAdapter.js.map +1 -1
- package/lib/module/SceneMap.js +9 -14
- package/lib/module/SceneMap.js.map +1 -1
- package/lib/module/SceneView.js +53 -98
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/TabBar.js +323 -323
- package/lib/module/TabBar.js.map +1 -1
- package/lib/module/TabBarIndicator.js +74 -92
- package/lib/module/TabBarIndicator.js.map +1 -1
- package/lib/module/TabBarItem.js +178 -154
- package/lib/module/TabBarItem.js.map +1 -1
- package/lib/typescript/SceneMap.d.ts +5 -3
- package/lib/typescript/SceneView.d.ts +1 -18
- package/lib/typescript/TabBar.d.ts +7 -38
- package/lib/typescript/TabBarIndicator.d.ts +2 -10
- package/lib/typescript/TabBarItem.d.ts +3 -5
- package/package.json +4 -1
- package/src/PagerViewAdapter.tsx +6 -1
- package/src/PanResponderAdapter.tsx +6 -3
- package/src/SceneMap.tsx +11 -7
- package/src/SceneView.tsx +70 -106
- package/src/TabBar.tsx +451 -391
- package/src/TabBarIndicator.tsx +108 -114
- package/src/TabBarItem.tsx +214 -185
|
@@ -9,6 +9,8 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
|
|
12
|
+
var _useLatestCallback = _interopRequireDefault(require("use-latest-callback"));
|
|
13
|
+
|
|
12
14
|
var _PlatformPressable = _interopRequireDefault(require("./PlatformPressable"));
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -17,188 +19,209 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
17
19
|
|
|
18
20
|
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; }
|
|
19
21
|
|
|
20
|
-
function
|
|
22
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
|
|
21
23
|
|
|
22
24
|
const DEFAULT_ACTIVE_COLOR = 'rgba(255, 255, 255, 1)';
|
|
23
25
|
const DEFAULT_INACTIVE_COLOR = 'rgba(255, 255, 255, 0.7)';
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
inputRange,
|
|
34
|
-
outputRange: inputRange.map(i => i === tabIndex ? 1 : 0)
|
|
35
|
-
});
|
|
36
|
-
} else {
|
|
37
|
-
return 1;
|
|
38
|
-
}
|
|
27
|
+
const getActiveOpacity = (position, routesLength, tabIndex) => {
|
|
28
|
+
if (routesLength > 1) {
|
|
29
|
+
const inputRange = Array.from({
|
|
30
|
+
length: routesLength
|
|
31
|
+
}, (_, i) => i);
|
|
32
|
+
return position.interpolate({
|
|
33
|
+
inputRange,
|
|
34
|
+
outputRange: inputRange.map(i => i === tabIndex ? 1 : 0)
|
|
39
35
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
} else {
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getInactiveOpacity = (position, routesLength, tabIndex) => {
|
|
42
|
+
if (routesLength > 1) {
|
|
43
|
+
const inputRange = Array.from({
|
|
44
|
+
length: routesLength
|
|
45
|
+
}, (_, i) => i);
|
|
46
|
+
return position.interpolate({
|
|
47
|
+
inputRange,
|
|
48
|
+
outputRange: inputRange.map(i => i === tabIndex ? 0 : 1)
|
|
51
49
|
});
|
|
50
|
+
} else {
|
|
51
|
+
return 0;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const TabBarItemInternal = _ref => {
|
|
56
|
+
let {
|
|
57
|
+
getAccessibilityLabel,
|
|
58
|
+
getAccessible,
|
|
59
|
+
getLabelText,
|
|
60
|
+
getTestID,
|
|
61
|
+
onLongPress,
|
|
62
|
+
onPress,
|
|
63
|
+
isFocused,
|
|
64
|
+
position,
|
|
65
|
+
route,
|
|
66
|
+
style,
|
|
67
|
+
inactiveColor: inactiveColorCustom,
|
|
68
|
+
activeColor: activeColorCustom,
|
|
69
|
+
labelStyle,
|
|
70
|
+
onLayout,
|
|
71
|
+
index: tabIndex,
|
|
72
|
+
pressColor,
|
|
73
|
+
pressOpacity,
|
|
74
|
+
renderBadge,
|
|
75
|
+
renderIcon,
|
|
76
|
+
defaultTabWidth,
|
|
77
|
+
routesLength,
|
|
78
|
+
renderLabel: renderLabelCustom
|
|
79
|
+
} = _ref;
|
|
80
|
+
|
|
81
|
+
const labelColorFromStyle = _reactNative.StyleSheet.flatten(labelStyle || {}).color;
|
|
82
|
+
|
|
83
|
+
const activeColor = activeColorCustom !== undefined ? activeColorCustom : typeof labelColorFromStyle === 'string' ? labelColorFromStyle : DEFAULT_ACTIVE_COLOR;
|
|
84
|
+
const inactiveColor = inactiveColorCustom !== undefined ? inactiveColorCustom : typeof labelColorFromStyle === 'string' ? labelColorFromStyle : DEFAULT_INACTIVE_COLOR;
|
|
85
|
+
const activeOpacity = getActiveOpacity(position, routesLength, tabIndex);
|
|
86
|
+
const inactiveOpacity = getInactiveOpacity(position, routesLength, tabIndex);
|
|
87
|
+
let icon = null;
|
|
88
|
+
let label = null;
|
|
89
|
+
|
|
90
|
+
if (renderIcon) {
|
|
91
|
+
const activeIcon = renderIcon({
|
|
56
92
|
route,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
getAccessible,
|
|
66
|
-
activeColor: activeColorCustom,
|
|
67
|
-
inactiveColor: inactiveColorCustom,
|
|
68
|
-
pressColor,
|
|
69
|
-
pressOpacity,
|
|
70
|
-
labelStyle,
|
|
71
|
-
style,
|
|
72
|
-
onLayout,
|
|
73
|
-
onPress,
|
|
74
|
-
onLongPress
|
|
75
|
-
} = this.props;
|
|
76
|
-
const tabIndex = navigationState.routes.indexOf(route);
|
|
77
|
-
const isFocused = navigationState.index === tabIndex;
|
|
78
|
-
|
|
79
|
-
const labelColorFromStyle = _reactNative.StyleSheet.flatten(labelStyle || {}).color;
|
|
80
|
-
|
|
81
|
-
const activeColor = activeColorCustom !== undefined ? activeColorCustom : typeof labelColorFromStyle === 'string' ? labelColorFromStyle : DEFAULT_ACTIVE_COLOR;
|
|
82
|
-
const inactiveColor = inactiveColorCustom !== undefined ? inactiveColorCustom : typeof labelColorFromStyle === 'string' ? labelColorFromStyle : DEFAULT_INACTIVE_COLOR;
|
|
83
|
-
const activeOpacity = this.getActiveOpacity(position, navigationState.routes, tabIndex);
|
|
84
|
-
const inactiveOpacity = this.getInactiveOpacity(position, navigationState.routes, tabIndex);
|
|
85
|
-
let icon = null;
|
|
86
|
-
let label = null;
|
|
87
|
-
|
|
88
|
-
if (renderIcon) {
|
|
89
|
-
const activeIcon = renderIcon({
|
|
90
|
-
route,
|
|
91
|
-
focused: true,
|
|
92
|
-
color: activeColor
|
|
93
|
-
});
|
|
94
|
-
const inactiveIcon = renderIcon({
|
|
95
|
-
route,
|
|
96
|
-
focused: false,
|
|
97
|
-
color: inactiveColor
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
if (inactiveIcon != null && activeIcon != null) {
|
|
101
|
-
icon = /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
102
|
-
style: styles.icon
|
|
103
|
-
}, /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
104
|
-
style: {
|
|
105
|
-
opacity: inactiveOpacity
|
|
106
|
-
}
|
|
107
|
-
}, inactiveIcon), /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
108
|
-
style: [_reactNative.StyleSheet.absoluteFill, {
|
|
109
|
-
opacity: activeOpacity
|
|
110
|
-
}]
|
|
111
|
-
}, activeIcon));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const renderLabel = renderLabelCustom !== undefined ? renderLabelCustom : _ref => {
|
|
116
|
-
let {
|
|
117
|
-
route,
|
|
118
|
-
color
|
|
119
|
-
} = _ref;
|
|
120
|
-
const labelText = getLabelText({
|
|
121
|
-
route
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
if (typeof labelText === 'string') {
|
|
125
|
-
return /*#__PURE__*/React.createElement(_reactNative.Animated.Text, {
|
|
126
|
-
style: [styles.label, icon ? {
|
|
127
|
-
marginTop: 0
|
|
128
|
-
} : null, labelStyle, {
|
|
129
|
-
color
|
|
130
|
-
}]
|
|
131
|
-
}, labelText);
|
|
132
|
-
}
|
|
93
|
+
focused: true,
|
|
94
|
+
color: activeColor
|
|
95
|
+
});
|
|
96
|
+
const inactiveIcon = renderIcon({
|
|
97
|
+
route,
|
|
98
|
+
focused: false,
|
|
99
|
+
color: inactiveColor
|
|
100
|
+
});
|
|
133
101
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const activeLabel = renderLabel({
|
|
139
|
-
route,
|
|
140
|
-
focused: true,
|
|
141
|
-
color: activeColor
|
|
142
|
-
});
|
|
143
|
-
const inactiveLabel = renderLabel({
|
|
144
|
-
route,
|
|
145
|
-
focused: false,
|
|
146
|
-
color: inactiveColor
|
|
147
|
-
});
|
|
148
|
-
label = /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
102
|
+
if (inactiveIcon != null && activeIcon != null) {
|
|
103
|
+
icon = /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
104
|
+
style: styles.icon
|
|
105
|
+
}, /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
149
106
|
style: {
|
|
150
107
|
opacity: inactiveOpacity
|
|
151
108
|
}
|
|
152
|
-
},
|
|
109
|
+
}, inactiveIcon), /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
153
110
|
style: [_reactNative.StyleSheet.absoluteFill, {
|
|
154
111
|
opacity: activeOpacity
|
|
155
112
|
}]
|
|
156
|
-
},
|
|
113
|
+
}, activeIcon));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const renderLabel = renderLabelCustom !== undefined ? renderLabelCustom : labelProps => {
|
|
118
|
+
const labelText = getLabelText({
|
|
119
|
+
route: labelProps.route
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (typeof labelText === 'string') {
|
|
123
|
+
return /*#__PURE__*/React.createElement(_reactNative.Animated.Text, {
|
|
124
|
+
style: [styles.label, icon ? {
|
|
125
|
+
marginTop: 0
|
|
126
|
+
} : null, labelStyle, {
|
|
127
|
+
color: labelProps.color
|
|
128
|
+
}]
|
|
129
|
+
}, labelText);
|
|
157
130
|
}
|
|
158
131
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
,
|
|
183
|
-
accessibilityStates: isFocused ? ['selected'] : [],
|
|
184
|
-
pressColor: pressColor,
|
|
185
|
-
pressOpacity: pressOpacity,
|
|
186
|
-
delayPressIn: 0,
|
|
187
|
-
onLayout: onLayout,
|
|
188
|
-
onPress: onPress,
|
|
189
|
-
onLongPress: onLongPress,
|
|
190
|
-
style: [styles.pressable, tabContainerStyle]
|
|
191
|
-
}, /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
192
|
-
pointerEvents: "none",
|
|
193
|
-
style: [styles.item, tabStyle]
|
|
194
|
-
}, icon, label, badge != null ? /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
195
|
-
style: styles.badge
|
|
196
|
-
}, badge) : null));
|
|
132
|
+
return labelText;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
if (renderLabel) {
|
|
136
|
+
const activeLabel = renderLabel({
|
|
137
|
+
route,
|
|
138
|
+
focused: true,
|
|
139
|
+
color: activeColor
|
|
140
|
+
});
|
|
141
|
+
const inactiveLabel = renderLabel({
|
|
142
|
+
route,
|
|
143
|
+
focused: false,
|
|
144
|
+
color: inactiveColor
|
|
145
|
+
});
|
|
146
|
+
label = /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
147
|
+
style: {
|
|
148
|
+
opacity: inactiveOpacity
|
|
149
|
+
}
|
|
150
|
+
}, inactiveLabel), /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
|
|
151
|
+
style: [_reactNative.StyleSheet.absoluteFill, {
|
|
152
|
+
opacity: activeOpacity
|
|
153
|
+
}]
|
|
154
|
+
}, activeLabel));
|
|
197
155
|
}
|
|
198
156
|
|
|
157
|
+
const tabStyle = _reactNative.StyleSheet.flatten(style);
|
|
158
|
+
|
|
159
|
+
const isWidthSet = (tabStyle === null || tabStyle === void 0 ? void 0 : tabStyle.width) !== undefined;
|
|
160
|
+
const tabContainerStyle = isWidthSet ? null : {
|
|
161
|
+
width: defaultTabWidth
|
|
162
|
+
};
|
|
163
|
+
const scene = {
|
|
164
|
+
route
|
|
165
|
+
};
|
|
166
|
+
let accessibilityLabel = getAccessibilityLabel(scene);
|
|
167
|
+
accessibilityLabel = typeof accessibilityLabel !== 'undefined' ? accessibilityLabel : getLabelText(scene);
|
|
168
|
+
const badge = renderBadge ? renderBadge(scene) : null;
|
|
169
|
+
return /*#__PURE__*/React.createElement(_PlatformPressable.default, {
|
|
170
|
+
android_ripple: {
|
|
171
|
+
borderless: true
|
|
172
|
+
},
|
|
173
|
+
testID: getTestID(scene),
|
|
174
|
+
accessible: getAccessible(scene),
|
|
175
|
+
accessibilityLabel: accessibilityLabel,
|
|
176
|
+
accessibilityRole: "tab",
|
|
177
|
+
accessibilityState: {
|
|
178
|
+
selected: isFocused
|
|
179
|
+
} // @ts-ignore: this is to support older React Native versions
|
|
180
|
+
,
|
|
181
|
+
accessibilityStates: isFocused ? ['selected'] : [],
|
|
182
|
+
pressColor: pressColor,
|
|
183
|
+
pressOpacity: pressOpacity,
|
|
184
|
+
delayPressIn: 0,
|
|
185
|
+
onLayout: onLayout,
|
|
186
|
+
onPress: onPress,
|
|
187
|
+
onLongPress: onLongPress,
|
|
188
|
+
style: [styles.pressable, tabContainerStyle]
|
|
189
|
+
}, /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
190
|
+
pointerEvents: "none",
|
|
191
|
+
style: [styles.item, tabStyle]
|
|
192
|
+
}, icon, label, badge != null ? /*#__PURE__*/React.createElement(_reactNative.View, {
|
|
193
|
+
style: styles.badge
|
|
194
|
+
}, badge) : null));
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const MemoizedTabBarItemInternal = /*#__PURE__*/React.memo(TabBarItemInternal);
|
|
198
|
+
|
|
199
|
+
function TabBarItem(props) {
|
|
200
|
+
const {
|
|
201
|
+
onPress,
|
|
202
|
+
onLongPress,
|
|
203
|
+
onLayout,
|
|
204
|
+
navigationState,
|
|
205
|
+
route,
|
|
206
|
+
...rest
|
|
207
|
+
} = props;
|
|
208
|
+
const onPressLatest = (0, _useLatestCallback.default)(onPress);
|
|
209
|
+
const onLongPressLatest = (0, _useLatestCallback.default)(onLongPress);
|
|
210
|
+
const onLayoutLatest = (0, _useLatestCallback.default)(onLayout ? onLayout : () => {});
|
|
211
|
+
const tabIndex = navigationState.routes.indexOf(route);
|
|
212
|
+
return /*#__PURE__*/React.createElement(MemoizedTabBarItemInternal, _extends({}, rest, {
|
|
213
|
+
onPress: onPressLatest,
|
|
214
|
+
onLayout: onLayoutLatest,
|
|
215
|
+
onLongPress: onLongPressLatest,
|
|
216
|
+
isFocused: navigationState.index === tabIndex,
|
|
217
|
+
route: route,
|
|
218
|
+
index: tabIndex,
|
|
219
|
+
routesLength: navigationState.routes.length
|
|
220
|
+
}));
|
|
199
221
|
}
|
|
200
222
|
|
|
201
|
-
|
|
223
|
+
var _default = TabBarItem;
|
|
224
|
+
exports.default = _default;
|
|
202
225
|
|
|
203
226
|
const styles = _reactNative.StyleSheet.create({
|
|
204
227
|
label: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DEFAULT_ACTIVE_COLOR","DEFAULT_INACTIVE_COLOR","TabBarItem","React","Component","position","routes","tabIndex","length","inputRange","map","_","i","interpolate","outputRange","render","route","navigationState","renderLabel","renderLabelCustom","renderIcon","renderBadge","getLabelText","getTestID","getAccessibilityLabel","getAccessible","activeColor","activeColorCustom","inactiveColor","inactiveColorCustom","pressColor","pressOpacity","labelStyle","style","onLayout","onPress","onLongPress","props","indexOf","isFocused","index","labelColorFromStyle","StyleSheet","flatten","color","undefined","activeOpacity","getActiveOpacity","inactiveOpacity","getInactiveOpacity","icon","label","activeIcon","focused","inactiveIcon","styles","opacity","absoluteFill","labelText","marginTop","activeLabel","inactiveLabel","tabStyle","isWidthSet","width","tabContainerStyle","flex","scene","accessibilityLabel","badge","borderless","selected","pressable","item","create","margin","backgroundColor","textTransform","alignItems","justifyContent","padding","minHeight","top","right"],"sources":["TabBarItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n StyleSheet,\n View,\n StyleProp,\n LayoutChangeEvent,\n TextStyle,\n ViewStyle,\n} from 'react-native';\nimport PlatformPressable from './PlatformPressable';\nimport type { Scene, Route, NavigationState } from './types';\n\nexport type Props<T extends Route> = {\n position: Animated.AnimatedInterpolation;\n route: T;\n navigationState: NavigationState<T>;\n activeColor?: string;\n inactiveColor?: string;\n pressColor?: string;\n pressOpacity?: number;\n getLabelText: (scene: Scene<T>) => string | undefined;\n getAccessible: (scene: Scene<T>) => boolean | undefined;\n getAccessibilityLabel: (scene: Scene<T>) => string | undefined;\n getTestID: (scene: Scene<T>) => string | undefined;\n renderLabel?: (scene: {\n route: T;\n focused: boolean;\n color: string;\n }) => React.ReactNode;\n renderIcon?: (scene: {\n route: T;\n focused: boolean;\n color: string;\n }) => React.ReactNode;\n renderBadge?: (scene: Scene<T>) => React.ReactNode;\n onLayout?: (event: LayoutChangeEvent) => void;\n onPress: () => void;\n onLongPress: () => void;\n labelStyle?: StyleProp<TextStyle>;\n style: StyleProp<ViewStyle>;\n};\n\nconst DEFAULT_ACTIVE_COLOR = 'rgba(255, 255, 255, 1)';\nconst DEFAULT_INACTIVE_COLOR = 'rgba(255, 255, 255, 0.7)';\n\nexport default class TabBarItem<T extends Route> extends React.Component<\n Props<T>\n> {\n private getActiveOpacity = (\n position: Animated.AnimatedInterpolation,\n routes: Route[],\n tabIndex: number\n ) => {\n if (routes.length > 1) {\n const inputRange = routes.map((_, i) => i);\n\n return position.interpolate({\n inputRange,\n outputRange: inputRange.map((i) => (i === tabIndex ? 1 : 0)),\n });\n } else {\n return 1;\n }\n };\n\n private getInactiveOpacity = (\n position: Animated.AnimatedInterpolation,\n routes: Route[],\n tabIndex: number\n ) => {\n if (routes.length > 1) {\n const inputRange = routes.map((_: Route, i: number) => i);\n\n return position.interpolate({\n inputRange,\n outputRange: inputRange.map((i: number) => (i === tabIndex ? 0 : 1)),\n });\n } else {\n return 0;\n }\n };\n\n render() {\n const {\n route,\n position,\n navigationState,\n renderLabel: renderLabelCustom,\n renderIcon,\n renderBadge,\n getLabelText,\n getTestID,\n getAccessibilityLabel,\n getAccessible,\n activeColor: activeColorCustom,\n inactiveColor: inactiveColorCustom,\n pressColor,\n pressOpacity,\n labelStyle,\n style,\n onLayout,\n onPress,\n onLongPress,\n } = this.props;\n\n const tabIndex = navigationState.routes.indexOf(route);\n const isFocused = navigationState.index === tabIndex;\n\n const labelColorFromStyle = StyleSheet.flatten(labelStyle || {}).color;\n\n const activeColor =\n activeColorCustom !== undefined\n ? activeColorCustom\n : typeof labelColorFromStyle === 'string'\n ? labelColorFromStyle\n : DEFAULT_ACTIVE_COLOR;\n const inactiveColor =\n inactiveColorCustom !== undefined\n ? inactiveColorCustom\n : typeof labelColorFromStyle === 'string'\n ? labelColorFromStyle\n : DEFAULT_INACTIVE_COLOR;\n\n const activeOpacity = this.getActiveOpacity(\n position,\n navigationState.routes,\n tabIndex\n );\n const inactiveOpacity = this.getInactiveOpacity(\n position,\n navigationState.routes,\n tabIndex\n );\n\n let icon: React.ReactNode | null = null;\n let label: React.ReactNode | null = null;\n\n if (renderIcon) {\n const activeIcon = renderIcon({\n route,\n focused: true,\n color: activeColor,\n });\n const inactiveIcon = renderIcon({\n route,\n focused: false,\n color: inactiveColor,\n });\n\n if (inactiveIcon != null && activeIcon != null) {\n icon = (\n <View style={styles.icon}>\n <Animated.View style={{ opacity: inactiveOpacity }}>\n {inactiveIcon}\n </Animated.View>\n <Animated.View\n style={[StyleSheet.absoluteFill, { opacity: activeOpacity }]}\n >\n {activeIcon}\n </Animated.View>\n </View>\n );\n }\n }\n\n const renderLabel =\n renderLabelCustom !== undefined\n ? renderLabelCustom\n : ({ route, color }: { route: T; color: string }) => {\n const labelText = getLabelText({ route });\n\n if (typeof labelText === 'string') {\n return (\n <Animated.Text\n style={[\n styles.label,\n icon ? { marginTop: 0 } : null,\n labelStyle,\n { color },\n ]}\n >\n {labelText}\n </Animated.Text>\n );\n }\n\n return labelText;\n };\n\n if (renderLabel) {\n const activeLabel = renderLabel({\n route,\n focused: true,\n color: activeColor,\n });\n const inactiveLabel = renderLabel({\n route,\n focused: false,\n color: inactiveColor,\n });\n\n label = (\n <View>\n <Animated.View style={{ opacity: inactiveOpacity }}>\n {inactiveLabel}\n </Animated.View>\n <Animated.View\n style={[StyleSheet.absoluteFill, { opacity: activeOpacity }]}\n >\n {activeLabel}\n </Animated.View>\n </View>\n );\n }\n\n const tabStyle = StyleSheet.flatten(style);\n const isWidthSet = tabStyle?.width !== undefined;\n const tabContainerStyle: ViewStyle | null = isWidthSet ? null : { flex: 1 };\n\n const scene = { route };\n\n let accessibilityLabel = getAccessibilityLabel(scene);\n\n accessibilityLabel =\n typeof accessibilityLabel !== 'undefined'\n ? accessibilityLabel\n : getLabelText(scene);\n\n const badge = renderBadge ? renderBadge(scene) : null;\n\n return (\n <PlatformPressable\n android_ripple={{ borderless: true }}\n testID={getTestID(scene)}\n accessible={getAccessible(scene)}\n accessibilityLabel={accessibilityLabel}\n accessibilityRole=\"tab\"\n accessibilityState={{ selected: isFocused }}\n // @ts-ignore: this is to support older React Native versions\n accessibilityStates={isFocused ? ['selected'] : []}\n pressColor={pressColor}\n pressOpacity={pressOpacity}\n delayPressIn={0}\n onLayout={onLayout}\n onPress={onPress}\n onLongPress={onLongPress}\n style={[styles.pressable, tabContainerStyle]}\n >\n <View pointerEvents=\"none\" style={[styles.item, tabStyle]}>\n {icon}\n {label}\n {badge != null ? <View style={styles.badge}>{badge}</View> : null}\n </View>\n </PlatformPressable>\n );\n }\n}\n\nconst styles = StyleSheet.create({\n label: {\n margin: 4,\n backgroundColor: 'transparent',\n textTransform: 'uppercase',\n },\n icon: {\n margin: 2,\n },\n item: {\n flex: 1,\n alignItems: 'center',\n justifyContent: 'center',\n padding: 10,\n minHeight: 48,\n },\n badge: {\n position: 'absolute',\n top: 0,\n right: 0,\n },\n pressable: {\n // The label is not pressable on Windows\n // Adding backgroundColor: 'transparent' seems to fix it\n backgroundColor: 'transparent',\n },\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AASA;;;;;;;;;;AAiCA,MAAMA,oBAAoB,GAAG,wBAA7B;AACA,MAAMC,sBAAsB,GAAG,0BAA/B;;AAEe,MAAMC,UAAN,SAA0CC,KAAK,CAACC,SAAhD,CAEb;EAAA;IAAA;;IAAA,0CAC2B,CACzBC,QADyB,EAEzBC,MAFyB,EAGzBC,QAHyB,KAItB;MACH,IAAID,MAAM,CAACE,MAAP,GAAgB,CAApB,EAAuB;QACrB,MAAMC,UAAU,GAAGH,MAAM,CAACI,GAAP,CAAW,CAACC,CAAD,EAAIC,CAAJ,KAAUA,CAArB,CAAnB;QAEA,OAAOP,QAAQ,CAACQ,WAAT,CAAqB;UA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F;EAyBD;;AAhND;;;;AAmNF,MAAMd,MAAM,GAAGb,uBAAA,CAAWgC,MAAX,CAAkB;EAC/BvB,KAAK,EAAE;IACLwB,MAAM,EAAE,CADH;IAELC,eAAe,EAAE,aAFZ;IAGLC,aAAa,EAAE;EAHV,CADwB;EAM/B3B,IAAI,EAAE;IACJyB,MAAM,EAAE;EADJ,CANyB;EAS/BF,IAAI,EAAE;IACJP,IAAI,EAAE,CADF;IAEJY,UAAU,EAAE,QAFR;IAGJC,cAAc,EAAE,QAHZ;IAIJC,OAAO,EAAE,EAJL;IAKJC,SAAS,EAAE;EALP,CATyB;EAgB/BZ,KAAK,EAAE;IACLhE,QAAQ,EAAE,UADL;IAEL6E,GAAG,EAAE,CAFA;IAGLC,KAAK,EAAE;EAHF,CAhBwB;EAqB/BX,SAAS,EAAE;IACT;IACA;IACAI,eAAe,EAAE;EAHR;AArBoB,CAAlB,CAAf"}
|
|
1
|
+
{"version":3,"names":["DEFAULT_ACTIVE_COLOR","DEFAULT_INACTIVE_COLOR","getActiveOpacity","position","routesLength","tabIndex","inputRange","Array","from","length","_","i","interpolate","outputRange","map","getInactiveOpacity","TabBarItemInternal","getAccessibilityLabel","getAccessible","getLabelText","getTestID","onLongPress","onPress","isFocused","route","style","inactiveColor","inactiveColorCustom","activeColor","activeColorCustom","labelStyle","onLayout","index","pressColor","pressOpacity","renderBadge","renderIcon","defaultTabWidth","renderLabel","renderLabelCustom","labelColorFromStyle","StyleSheet","flatten","color","undefined","activeOpacity","inactiveOpacity","icon","label","activeIcon","focused","inactiveIcon","styles","opacity","absoluteFill","labelProps","labelText","marginTop","activeLabel","inactiveLabel","tabStyle","isWidthSet","width","tabContainerStyle","scene","accessibilityLabel","badge","borderless","selected","pressable","item","MemoizedTabBarItemInternal","React","memo","TabBarItem","props","navigationState","rest","onPressLatest","useLatestCallback","onLongPressLatest","onLayoutLatest","routes","indexOf","create","margin","backgroundColor","textTransform","flex","alignItems","justifyContent","padding","minHeight","top","right"],"sources":["TabBarItem.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n StyleSheet,\n View,\n StyleProp,\n LayoutChangeEvent,\n TextStyle,\n ViewStyle,\n} from 'react-native';\nimport useLatestCallback from 'use-latest-callback';\nimport PlatformPressable from './PlatformPressable';\nimport type { Scene, Route, NavigationState } from './types';\n\nexport type Props<T extends Route> = {\n position: Animated.AnimatedInterpolation;\n route: T;\n navigationState: NavigationState<T>;\n activeColor?: string;\n inactiveColor?: string;\n pressColor?: string;\n pressOpacity?: number;\n getLabelText: (scene: Scene<T>) => string | undefined;\n getAccessible: (scene: Scene<T>) => boolean | undefined;\n getAccessibilityLabel: (scene: Scene<T>) => string | undefined;\n getTestID: (scene: Scene<T>) => string | undefined;\n renderLabel?: (scene: {\n route: T;\n focused: boolean;\n color: string;\n }) => React.ReactNode;\n renderIcon?: (scene: {\n route: T;\n focused: boolean;\n color: string;\n }) => React.ReactNode;\n renderBadge?: (scene: Scene<T>) => React.ReactNode;\n onLayout?: (event: LayoutChangeEvent) => void;\n onPress: () => void;\n onLongPress: () => void;\n defaultTabWidth?: number;\n labelStyle?: StyleProp<TextStyle>;\n style: StyleProp<ViewStyle>;\n};\n\nconst DEFAULT_ACTIVE_COLOR = 'rgba(255, 255, 255, 1)';\nconst DEFAULT_INACTIVE_COLOR = 'rgba(255, 255, 255, 0.7)';\n\nconst getActiveOpacity = (\n position: Animated.AnimatedInterpolation,\n routesLength: number,\n tabIndex: number\n) => {\n if (routesLength > 1) {\n const inputRange = Array.from({ length: routesLength }, (_, i) => i);\n\n return position.interpolate({\n inputRange,\n outputRange: inputRange.map((i) => (i === tabIndex ? 1 : 0)),\n });\n } else {\n return 1;\n }\n};\n\nconst getInactiveOpacity = (\n position: Animated.AnimatedInterpolation,\n routesLength: number,\n tabIndex: number\n) => {\n if (routesLength > 1) {\n const inputRange = Array.from({ length: routesLength }, (_, i) => i);\n\n return position.interpolate({\n inputRange,\n outputRange: inputRange.map((i: number) => (i === tabIndex ? 0 : 1)),\n });\n } else {\n return 0;\n }\n};\n\ntype TabBarItemInternalProps<T extends Route> = Omit<\n Props<T>,\n 'navigationState'\n> & {\n isFocused: boolean;\n index: number;\n routesLength: number;\n};\n\nconst TabBarItemInternal = <T extends Route>({\n getAccessibilityLabel,\n getAccessible,\n getLabelText,\n getTestID,\n onLongPress,\n onPress,\n isFocused,\n position,\n route,\n style,\n inactiveColor: inactiveColorCustom,\n activeColor: activeColorCustom,\n labelStyle,\n onLayout,\n index: tabIndex,\n pressColor,\n pressOpacity,\n renderBadge,\n renderIcon,\n defaultTabWidth,\n routesLength,\n renderLabel: renderLabelCustom,\n}: TabBarItemInternalProps<T>) => {\n const labelColorFromStyle = StyleSheet.flatten(labelStyle || {}).color;\n\n const activeColor =\n activeColorCustom !== undefined\n ? activeColorCustom\n : typeof labelColorFromStyle === 'string'\n ? labelColorFromStyle\n : DEFAULT_ACTIVE_COLOR;\n const inactiveColor =\n inactiveColorCustom !== undefined\n ? inactiveColorCustom\n : typeof labelColorFromStyle === 'string'\n ? labelColorFromStyle\n : DEFAULT_INACTIVE_COLOR;\n\n const activeOpacity = getActiveOpacity(position, routesLength, tabIndex);\n const inactiveOpacity = getInactiveOpacity(position, routesLength, tabIndex);\n\n let icon: React.ReactNode | null = null;\n let label: React.ReactNode | null = null;\n\n if (renderIcon) {\n const activeIcon = renderIcon({\n route,\n focused: true,\n color: activeColor,\n });\n const inactiveIcon = renderIcon({\n route,\n focused: false,\n color: inactiveColor,\n });\n\n if (inactiveIcon != null && activeIcon != null) {\n icon = (\n <View style={styles.icon}>\n <Animated.View style={{ opacity: inactiveOpacity }}>\n {inactiveIcon}\n </Animated.View>\n <Animated.View\n style={[StyleSheet.absoluteFill, { opacity: activeOpacity }]}\n >\n {activeIcon}\n </Animated.View>\n </View>\n );\n }\n }\n\n const renderLabel =\n renderLabelCustom !== undefined\n ? renderLabelCustom\n : (labelProps: { route: T; color: string }) => {\n const labelText = getLabelText({ route: labelProps.route });\n\n if (typeof labelText === 'string') {\n return (\n <Animated.Text\n style={[\n styles.label,\n icon ? { marginTop: 0 } : null,\n labelStyle,\n { color: labelProps.color },\n ]}\n >\n {labelText}\n </Animated.Text>\n );\n }\n\n return labelText;\n };\n\n if (renderLabel) {\n const activeLabel = renderLabel({\n route,\n focused: true,\n color: activeColor,\n });\n const inactiveLabel = renderLabel({\n route,\n focused: false,\n color: inactiveColor,\n });\n\n label = (\n <View>\n <Animated.View style={{ opacity: inactiveOpacity }}>\n {inactiveLabel}\n </Animated.View>\n <Animated.View\n style={[StyleSheet.absoluteFill, { opacity: activeOpacity }]}\n >\n {activeLabel}\n </Animated.View>\n </View>\n );\n }\n\n const tabStyle = StyleSheet.flatten(style);\n const isWidthSet = tabStyle?.width !== undefined;\n\n const tabContainerStyle: ViewStyle | null = isWidthSet\n ? null\n : { width: defaultTabWidth };\n\n const scene = { route };\n\n let accessibilityLabel = getAccessibilityLabel(scene);\n\n accessibilityLabel =\n typeof accessibilityLabel !== 'undefined'\n ? accessibilityLabel\n : getLabelText(scene);\n\n const badge = renderBadge ? renderBadge(scene) : null;\n\n return (\n <PlatformPressable\n android_ripple={{ borderless: true }}\n testID={getTestID(scene)}\n accessible={getAccessible(scene)}\n accessibilityLabel={accessibilityLabel}\n accessibilityRole=\"tab\"\n accessibilityState={{ selected: isFocused }}\n // @ts-ignore: this is to support older React Native versions\n accessibilityStates={isFocused ? ['selected'] : []}\n pressColor={pressColor}\n pressOpacity={pressOpacity}\n delayPressIn={0}\n onLayout={onLayout}\n onPress={onPress}\n onLongPress={onLongPress}\n style={[styles.pressable, tabContainerStyle]}\n >\n <View pointerEvents=\"none\" style={[styles.item, tabStyle]}>\n {icon}\n {label}\n {badge != null ? <View style={styles.badge}>{badge}</View> : null}\n </View>\n </PlatformPressable>\n );\n};\n\nconst MemoizedTabBarItemInternal = React.memo(\n TabBarItemInternal\n) as typeof TabBarItemInternal;\n\nfunction TabBarItem<T extends Route>(props: Props<T>) {\n const { onPress, onLongPress, onLayout, navigationState, route, ...rest } =\n props;\n const onPressLatest = useLatestCallback(onPress);\n const onLongPressLatest = useLatestCallback(onLongPress);\n const onLayoutLatest = useLatestCallback(onLayout ? onLayout : () => {});\n\n const tabIndex = navigationState.routes.indexOf(route);\n\n return (\n <MemoizedTabBarItemInternal\n {...rest}\n onPress={onPressLatest}\n onLayout={onLayoutLatest}\n onLongPress={onLongPressLatest}\n isFocused={navigationState.index === tabIndex}\n route={route}\n index={tabIndex}\n routesLength={navigationState.routes.length}\n />\n );\n}\n\nexport default TabBarItem;\n\nconst styles = StyleSheet.create({\n label: {\n margin: 4,\n backgroundColor: 'transparent',\n textTransform: 'uppercase',\n },\n icon: {\n margin: 2,\n },\n item: {\n flex: 1,\n alignItems: 'center',\n justifyContent: 'center',\n padding: 10,\n minHeight: 48,\n },\n badge: {\n position: 'absolute',\n top: 0,\n right: 0,\n },\n pressable: {\n // The label is not pressable on Windows\n // Adding backgroundColor: 'transparent' seems to fix it\n backgroundColor: 'transparent',\n },\n});\n"],"mappings":";;;;;;;AAAA;;AACA;;AASA;;AACA;;;;;;;;;;AAkCA,MAAMA,oBAAoB,GAAG,wBAA7B;AACA,MAAMC,sBAAsB,GAAG,0BAA/B;;AAEA,MAAMC,gBAAgB,GAAG,CACvBC,QADuB,EAEvBC,YAFuB,EAGvBC,QAHuB,KAIpB;EACH,IAAID,YAAY,GAAG,CAAnB,EAAsB;IACpB,MAAME,UAAU,GAAGC,KAAK,CAACC,IAAN,CAAW;MAAEC,MAAM,EAAEL;IAAV,CAAX,EAAqC,CAACM,CAAD,EAAIC,CAAJ,KAAUA,CAA/C,CAAnB;IAEA,OAAOR,QAAQ,CAACS,WAAT,CAAqB;MAC1BN,UAD0B;MAE1BO,WAAW,EAAEP,UAAU,CAACQ,GAAX,CAAgBH,CAAD,IAAQA,CAAC,KAAKN,QAAN,GAAiB,CAAjB,GAAqB,CAA5C;IAFa,CAArB,CAAP;EAID,CAPD,MAOO;IACL,OAAO,CAAP;EACD;AACF,CAfD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-103,8 +103,9 @@ export default function PagerViewAdapter(_ref) {
|
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
}, []);
|
|
106
|
+
const memoizedPosition = React.useMemo(() => Animated.add(position, offset), [offset, position]);
|
|
106
107
|
return children({
|
|
107
|
-
position:
|
|
108
|
+
position: memoizedPosition,
|
|
108
109
|
addEnterListener,
|
|
109
110
|
jumpTo,
|
|
110
111
|
render: children => /*#__PURE__*/React.createElement(AnimatedViewPager, _extends({}, rest, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Animated","Keyboard","StyleSheet","ViewPager","useAnimatedValue","AnimatedViewPager","createAnimatedComponent","PagerViewAdapter","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","animationEnabled","rest","index","listenersRef","useRef","pagerRef","indexRef","navigationStateRef","position","offset","useEffect","current","jumpTo","useCallback","key","routes","findIndex","route","setPage","setPageWithoutAnimation","setValue","dismiss","onPageScrollStateChanged","state","pageScrollState","nativeEvent","subscription","addListener","value","next","Math","ceil","floor","forEach","listener","removeListener","addEnterListener","push","indexOf","splice","add","render","styles","container","event","useNativeDriver","e","create","flex"],"sources":["PagerViewAdapter.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Animated, Keyboard, StyleSheet } from 'react-native';\nimport ViewPager, {\n PageScrollStateChangedNativeEvent,\n} from 'react-native-pager-view';\nimport useAnimatedValue from './useAnimatedValue';\nimport type {\n NavigationState,\n Route,\n Listener,\n EventEmitterProps,\n PagerProps,\n} from './types';\n\nconst AnimatedViewPager = Animated.createAnimatedComponent(ViewPager);\n\ntype Props<T extends Route> = PagerProps & {\n onIndexChange: (index: number) => void;\n navigationState: NavigationState<T>;\n children: (\n props: EventEmitterProps & {\n // Animated value which represents the state of current index\n // It can include fractional digits as it represents the intermediate value\n position: Animated.AnimatedInterpolation;\n // Function to actually render the content of the pager\n // The parent component takes care of rendering\n render: (children: React.ReactNode) => React.ReactNode;\n // Callback to call when switching the tab\n // The tab switch animation is performed even if the index in state is unchanged\n jumpTo: (key: string) => void;\n }\n ) => React.ReactElement;\n};\n\nexport default function PagerViewAdapter<T extends Route>({\n keyboardDismissMode = 'auto',\n swipeEnabled = true,\n navigationState,\n onIndexChange,\n onSwipeStart,\n onSwipeEnd,\n children,\n style,\n animationEnabled,\n ...rest\n}: Props<T>) {\n const { index } = navigationState;\n\n const listenersRef = React.useRef<Listener[]>([]);\n\n const pagerRef = React.useRef<ViewPager>();\n const indexRef = React.useRef<number>(index);\n const navigationStateRef = React.useRef(navigationState);\n\n const position = useAnimatedValue(index);\n const offset = useAnimatedValue(0);\n\n React.useEffect(() => {\n navigationStateRef.current = navigationState;\n });\n\n const jumpTo = React.useCallback(\n (key: string) => {\n const index = navigationStateRef.current.routes.findIndex(\n (route: { key: string }) => route.key === key\n );\n\n if (animationEnabled) {\n pagerRef.current?.setPage(index);\n } else {\n pagerRef.current?.setPageWithoutAnimation(index);\n position.setValue(index);\n }\n },\n [animationEnabled, position]\n );\n\n React.useEffect(() => {\n if (keyboardDismissMode === 'auto') {\n Keyboard.dismiss();\n }\n\n if (indexRef.current !== index) {\n if (animationEnabled) {\n pagerRef.current?.setPage(index);\n } else {\n pagerRef.current?.setPageWithoutAnimation(index);\n position.setValue(index);\n }\n }\n }, [keyboardDismissMode, index, animationEnabled, position]);\n\n const onPageScrollStateChanged = (\n state: PageScrollStateChangedNativeEvent\n ) => {\n const { pageScrollState } = state.nativeEvent;\n\n switch (pageScrollState) {\n case 'idle':\n onSwipeEnd?.();\n return;\n case 'dragging': {\n const subscription = offset.addListener(({ value }) => {\n const next =\n index + (value > 0 ? Math.ceil(value) : Math.floor(value));\n\n if (next !== index) {\n listenersRef.current.forEach((listener) => listener(next));\n }\n\n offset.removeListener(subscription);\n });\n\n onSwipeStart?.();\n return;\n }\n }\n };\n\n const addEnterListener = React.useCallback((listener: Listener) => {\n listenersRef.current.push(listener);\n\n return () => {\n const index = listenersRef.current.indexOf(listener);\n\n if (index > -1) {\n listenersRef.current.splice(index, 1);\n }\n };\n }, []);\n\n
|
|
1
|
+
{"version":3,"names":["React","Animated","Keyboard","StyleSheet","ViewPager","useAnimatedValue","AnimatedViewPager","createAnimatedComponent","PagerViewAdapter","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","animationEnabled","rest","index","listenersRef","useRef","pagerRef","indexRef","navigationStateRef","position","offset","useEffect","current","jumpTo","useCallback","key","routes","findIndex","route","setPage","setPageWithoutAnimation","setValue","dismiss","onPageScrollStateChanged","state","pageScrollState","nativeEvent","subscription","addListener","value","next","Math","ceil","floor","forEach","listener","removeListener","addEnterListener","push","indexOf","splice","memoizedPosition","useMemo","add","render","styles","container","event","useNativeDriver","e","create","flex"],"sources":["PagerViewAdapter.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Animated, Keyboard, StyleSheet } from 'react-native';\nimport ViewPager, {\n PageScrollStateChangedNativeEvent,\n} from 'react-native-pager-view';\nimport useAnimatedValue from './useAnimatedValue';\nimport type {\n NavigationState,\n Route,\n Listener,\n EventEmitterProps,\n PagerProps,\n} from './types';\n\nconst AnimatedViewPager = Animated.createAnimatedComponent(ViewPager);\n\ntype Props<T extends Route> = PagerProps & {\n onIndexChange: (index: number) => void;\n navigationState: NavigationState<T>;\n children: (\n props: EventEmitterProps & {\n // Animated value which represents the state of current index\n // It can include fractional digits as it represents the intermediate value\n position: Animated.AnimatedInterpolation;\n // Function to actually render the content of the pager\n // The parent component takes care of rendering\n render: (children: React.ReactNode) => React.ReactNode;\n // Callback to call when switching the tab\n // The tab switch animation is performed even if the index in state is unchanged\n jumpTo: (key: string) => void;\n }\n ) => React.ReactElement;\n};\n\nexport default function PagerViewAdapter<T extends Route>({\n keyboardDismissMode = 'auto',\n swipeEnabled = true,\n navigationState,\n onIndexChange,\n onSwipeStart,\n onSwipeEnd,\n children,\n style,\n animationEnabled,\n ...rest\n}: Props<T>) {\n const { index } = navigationState;\n\n const listenersRef = React.useRef<Listener[]>([]);\n\n const pagerRef = React.useRef<ViewPager>();\n const indexRef = React.useRef<number>(index);\n const navigationStateRef = React.useRef(navigationState);\n\n const position = useAnimatedValue(index);\n const offset = useAnimatedValue(0);\n\n React.useEffect(() => {\n navigationStateRef.current = navigationState;\n });\n\n const jumpTo = React.useCallback(\n (key: string) => {\n const index = navigationStateRef.current.routes.findIndex(\n (route: { key: string }) => route.key === key\n );\n\n if (animationEnabled) {\n pagerRef.current?.setPage(index);\n } else {\n pagerRef.current?.setPageWithoutAnimation(index);\n position.setValue(index);\n }\n },\n [animationEnabled, position]\n );\n\n React.useEffect(() => {\n if (keyboardDismissMode === 'auto') {\n Keyboard.dismiss();\n }\n\n if (indexRef.current !== index) {\n if (animationEnabled) {\n pagerRef.current?.setPage(index);\n } else {\n pagerRef.current?.setPageWithoutAnimation(index);\n position.setValue(index);\n }\n }\n }, [keyboardDismissMode, index, animationEnabled, position]);\n\n const onPageScrollStateChanged = (\n state: PageScrollStateChangedNativeEvent\n ) => {\n const { pageScrollState } = state.nativeEvent;\n\n switch (pageScrollState) {\n case 'idle':\n onSwipeEnd?.();\n return;\n case 'dragging': {\n const subscription = offset.addListener(({ value }) => {\n const next =\n index + (value > 0 ? Math.ceil(value) : Math.floor(value));\n\n if (next !== index) {\n listenersRef.current.forEach((listener) => listener(next));\n }\n\n offset.removeListener(subscription);\n });\n\n onSwipeStart?.();\n return;\n }\n }\n };\n\n const addEnterListener = React.useCallback((listener: Listener) => {\n listenersRef.current.push(listener);\n\n return () => {\n const index = listenersRef.current.indexOf(listener);\n\n if (index > -1) {\n listenersRef.current.splice(index, 1);\n }\n };\n }, []);\n\n const memoizedPosition = React.useMemo(\n () => Animated.add(position, offset),\n [offset, position]\n );\n\n return children({\n position: memoizedPosition,\n addEnterListener,\n jumpTo,\n render: (children) => (\n <AnimatedViewPager\n {...rest}\n ref={pagerRef}\n style={[styles.container, style]}\n initialPage={index}\n keyboardDismissMode={\n keyboardDismissMode === 'auto' ? 'on-drag' : keyboardDismissMode\n }\n onPageScroll={Animated.event(\n [\n {\n nativeEvent: {\n position: position,\n offset: offset,\n },\n },\n ],\n { useNativeDriver: true }\n )}\n onPageSelected={(e) => {\n const index = e.nativeEvent.position;\n indexRef.current = index;\n onIndexChange(index);\n }}\n onPageScrollStateChanged={onPageScrollStateChanged}\n scrollEnabled={swipeEnabled}\n >\n {children}\n </AnimatedViewPager>\n ),\n });\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n});\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SAASC,QAAT,EAAmBC,QAAnB,EAA6BC,UAA7B,QAA+C,cAA/C;AACA,OAAOC,SAAP,MAEO,yBAFP;AAGA,OAAOC,gBAAP,MAA6B,oBAA7B;AASA,MAAMC,iBAAiB,GAAGL,QAAQ,CAACM,uBAAT,CAAiCH,SAAjC,CAA1B;AAoBA,eAAe,SAASI,gBAAT,OAWF;EAAA,IAX6C;IACxDC,mBAAmB,GAAG,MADkC;IAExDC,YAAY,GAAG,IAFyC;IAGxDC,eAHwD;IAIxDC,aAJwD;IAKxDC,YALwD;IAMxDC,UANwD;IAOxDC,QAPwD;IAQxDC,KARwD;IASxDC,gBATwD;IAUxD,GAAGC;EAVqD,CAW7C;EACX,MAAM;IAAEC;EAAF,IAAYR,eAAlB;EAEA,MAAMS,YAAY,GAAGpB,KAAK,CAACqB,MAAN,CAAyB,EAAzB,CAArB;EAEA,MAAMC,QAAQ,GAAGtB,KAAK,CAACqB,MAAN,EAAjB;EACA,MAAME,QAAQ,GAAGvB,KAAK,CAACqB,MAAN,CAAqBF,KAArB,CAAjB;EACA,MAAMK,kBAAkB,GAAGxB,KAAK,CAACqB,MAAN,CAAaV,eAAb,CAA3B;EAEA,MAAMc,QAAQ,GAAGpB,gBAAgB,CAACc,KAAD,CAAjC;EACA,MAAMO,MAAM,GAAGrB,gBAAgB,CAAC,CAAD,CAA/B;EAEAL,KAAK,CAAC2B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EgC,gBADI;IAEdJ,gBAFc;IAGdxB,MAHc;IAId+B,MAAM,EAAG7C,QAAD,iBACN,oBAAC,iBAAD,eACMG,IADN;MAEE,GAAG,EAAEI,QAFP;MAGE,KAAK,EAAE,CAACuC,MAAM,CAACC,SAAR,EAAmB9C,KAAnB,CAHT;MAIE,WAAW,EAAEG,KAJf;MAKE,mBAAmB,EACjBV,mBAAmB,KAAK,MAAxB,GAAiC,SAAjC,GAA6CA,mBANjD;MAQE,YAAY,EAAER,QAAQ,CAAC8D,KAAT,CACZ,CACE;QACErB,WAAW,EAAE;UACXjB,QAAQ,EAAEA,QADC;UAEXC,MAAM,EAAEA;QAFG;MADf,CADF,CADY,EASZ;QAAEsC,eAAe,EAAE;MAAnB,CATY,CARhB;MAmBE,cAAc,EAAGC,CAAD,IAAO;QACrB,MAAM9C,KAAK,GAAG8C,CAAC,CAACvB,WAAF,CAAcjB,QAA5B;QACAF,QAAQ,CAACK,OAAT,GAAmBT,KAAnB;QACAP,aAAa,CAACO,KAAD,CAAb;MACD,CAvBH;MAwBE,wBAAwB,EAAEoB,wBAxB5B;MAyBE,aAAa,EAAE7B;IAzBjB,IA2BGK,QA3BH;EALY,CAAD,CAAf;AAoCD;AAED,MAAM8C,MAAM,GAAG1D,UAAU,CAAC+D,MAAX,CAAkB;EAC/BJ,SAAS,EAAE;IACTK,IAAI,EAAE;EADG;AADoB,CAAlB,CAAf"}
|
|
@@ -181,8 +181,9 @@ export default function PanResponderAdapter(_ref) {
|
|
|
181
181
|
outputRange: [-maxTranslate, 0],
|
|
182
182
|
extrapolate: 'clamp'
|
|
183
183
|
}), I18nManager.isRTL ? -1 : 1);
|
|
184
|
+
const position = React.useMemo(() => layout.width ? Animated.divide(panX, -layout.width) : null, [layout.width, panX]);
|
|
184
185
|
return children({
|
|
185
|
-
position:
|
|
186
|
+
position: position ?? new Animated.Value(index),
|
|
186
187
|
addEnterListener,
|
|
187
188
|
jumpTo,
|
|
188
189
|
render: children => /*#__PURE__*/React.createElement(Animated.View, _extends({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","Animated","PanResponder","Keyboard","StyleSheet","I18nManager","View","useAnimatedValue","DEAD_ZONE","DefaultTransitionSpec","timing","spring","stiffness","damping","mass","overshootClamping","PanResponderAdapter","layout","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","animationEnabled","routes","index","panX","listenersRef","useRef","navigationStateRef","layoutRef","onIndexChangeRef","currentIndexRef","pendingIndexRef","swipeVelocityThreshold","swipeDistanceThreshold","width","jumpToIndex","useCallback","animate","offset","current","transitionConfig","parallel","toValue","useNativeDriver","start","finished","undefined","setValue","useEffect","dismiss","isMovingHorizontally","_","gestureState","Math","abs","dx","dy","vx","vy","canMoveScreen","event","diffX","isRTL","length","startGesture","stopAnimation","setOffset","_value","respondToGesture","position","_offset","next","ceil","floor","forEach","listener","finishGesture","flattenOffset","currentIndex","nextIndex","round","min","max","isFinite","addEnterListener","push","indexOf","splice","jumpTo","key","findIndex","route","panResponder","create","onMoveShouldSetPanResponder","onMoveShouldSetPanResponderCapture","onPanResponderGrant","onPanResponderMove","onPanResponderTerminate","onPanResponderRelease","onPanResponderTerminationRequest","maxTranslate","translateX","multiply","interpolate","inputRange","outputRange","extrapolate","divide","Value","render","styles","sheet","transform","panHandlers","Children","map","child","i","focused","absoluteFill","flex","flexDirection","alignItems"],"sources":["PanResponderAdapter.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n PanResponder,\n Keyboard,\n StyleSheet,\n GestureResponderEvent,\n PanResponderGestureState,\n I18nManager,\n View,\n} from 'react-native';\nimport useAnimatedValue from './useAnimatedValue';\nimport type {\n NavigationState,\n Route,\n Layout,\n EventEmitterProps,\n PagerProps,\n Listener,\n} from './types';\n\ntype Props<T extends Route> = PagerProps & {\n layout: Layout;\n onIndexChange: (index: number) => void;\n navigationState: NavigationState<T>;\n children: (\n props: EventEmitterProps & {\n // Animated value which represents the state of current index\n // It can include fractional digits as it represents the intermediate value\n position: Animated.AnimatedInterpolation;\n // Function to actually render the content of the pager\n // The parent component takes care of rendering\n render: (children: React.ReactNode) => React.ReactNode;\n // Callback to call when switching the tab\n // The tab switch animation is performed even if the index in state is unchanged\n jumpTo: (key: string) => void;\n }\n ) => React.ReactElement;\n};\n\nconst DEAD_ZONE = 12;\n\nconst DefaultTransitionSpec = {\n timing: Animated.spring,\n stiffness: 1000,\n damping: 500,\n mass: 3,\n overshootClamping: true,\n};\n\nexport default function PanResponderAdapter<T extends Route>({\n layout,\n keyboardDismissMode = 'auto',\n swipeEnabled = true,\n navigationState,\n onIndexChange,\n onSwipeStart,\n onSwipeEnd,\n children,\n style,\n animationEnabled = false,\n}: Props<T>) {\n const { routes, index } = navigationState;\n\n const panX = useAnimatedValue(0);\n\n const listenersRef = React.useRef<Listener[]>([]);\n\n const navigationStateRef = React.useRef(navigationState);\n const layoutRef = React.useRef(layout);\n const onIndexChangeRef = React.useRef(onIndexChange);\n\n const currentIndexRef = React.useRef(index);\n const pendingIndexRef = React.useRef<number>();\n\n const swipeVelocityThreshold = 0.15;\n const swipeDistanceThreshold = layout.width / 1.75;\n\n const jumpToIndex = React.useCallback(\n (index: number, animate = animationEnabled) => {\n const offset = -index * layoutRef.current.width;\n\n const { timing, ...transitionConfig } = DefaultTransitionSpec;\n\n if (animate) {\n Animated.parallel([\n timing(panX, {\n ...transitionConfig,\n toValue: offset,\n useNativeDriver: false,\n }),\n ]).start(({ finished }) => {\n if (finished) {\n onIndexChangeRef.current(index);\n pendingIndexRef.current = undefined;\n }\n });\n pendingIndexRef.current = index;\n } else {\n panX.setValue(offset);\n onIndexChangeRef.current(index);\n pendingIndexRef.current = undefined;\n }\n },\n [animationEnabled, panX]\n );\n\n React.useEffect(() => {\n navigationStateRef.current = navigationState;\n layoutRef.current = layout;\n onIndexChangeRef.current = onIndexChange;\n });\n\n React.useEffect(() => {\n const offset = -navigationStateRef.current.index * layout.width;\n\n panX.setValue(offset);\n }, [layout.width, panX]);\n\n React.useEffect(() => {\n if (keyboardDismissMode === 'auto') {\n Keyboard.dismiss();\n }\n\n if (layout.width && currentIndexRef.current !== index) {\n currentIndexRef.current = index;\n jumpToIndex(index);\n }\n }, [jumpToIndex, keyboardDismissMode, layout.width, index]);\n\n const isMovingHorizontally = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n return (\n Math.abs(gestureState.dx) > Math.abs(gestureState.dy * 2) &&\n Math.abs(gestureState.vx) > Math.abs(gestureState.vy * 2)\n );\n };\n\n const canMoveScreen = (\n event: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n if (swipeEnabled === false) {\n return false;\n }\n\n const diffX = I18nManager.isRTL ? -gestureState.dx : gestureState.dx;\n\n return (\n isMovingHorizontally(event, gestureState) &&\n ((diffX >= DEAD_ZONE && currentIndexRef.current > 0) ||\n (diffX <= -DEAD_ZONE && currentIndexRef.current < routes.length - 1))\n );\n };\n\n const startGesture = () => {\n onSwipeStart?.();\n\n if (keyboardDismissMode === 'on-drag') {\n Keyboard.dismiss();\n }\n\n panX.stopAnimation();\n // @ts-expect-error: _value is private, but docs use it as well\n panX.setOffset(panX._value);\n };\n\n const respondToGesture = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n const diffX = I18nManager.isRTL ? -gestureState.dx : gestureState.dx;\n\n if (\n // swiping left\n (diffX > 0 && index <= 0) ||\n // swiping right\n (diffX < 0 && index >= routes.length - 1)\n ) {\n return;\n }\n\n if (layout.width) {\n // @ts-expect-error: _offset is private, but docs use it as well\n const position = (panX._offset + diffX) / -layout.width;\n const next =\n position > index ? Math.ceil(position) : Math.floor(position);\n\n if (next !== index) {\n listenersRef.current.forEach((listener) => listener(next));\n }\n }\n\n panX.setValue(diffX);\n };\n\n const finishGesture = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n panX.flattenOffset();\n\n onSwipeEnd?.();\n\n const currentIndex =\n typeof pendingIndexRef.current === 'number'\n ? pendingIndexRef.current\n : currentIndexRef.current;\n\n let nextIndex = currentIndex;\n\n if (\n Math.abs(gestureState.dx) > Math.abs(gestureState.dy) &&\n Math.abs(gestureState.vx) > Math.abs(gestureState.vy) &&\n (Math.abs(gestureState.dx) > swipeDistanceThreshold ||\n Math.abs(gestureState.vx) > swipeVelocityThreshold)\n ) {\n nextIndex = Math.round(\n Math.min(\n Math.max(\n 0,\n I18nManager.isRTL\n ? currentIndex + gestureState.dx / Math.abs(gestureState.dx)\n : currentIndex - gestureState.dx / Math.abs(gestureState.dx)\n ),\n routes.length - 1\n )\n );\n\n currentIndexRef.current = nextIndex;\n }\n\n if (!isFinite(nextIndex)) {\n nextIndex = currentIndex;\n }\n\n jumpToIndex(nextIndex, true);\n };\n\n // TODO: use the listeners\n const addEnterListener = React.useCallback((listener: Listener) => {\n listenersRef.current.push(listener);\n\n return () => {\n const index = listenersRef.current.indexOf(listener);\n\n if (index > -1) {\n listenersRef.current.splice(index, 1);\n }\n };\n }, []);\n\n const jumpTo = React.useCallback(\n (key: string) => {\n const index = navigationStateRef.current.routes.findIndex(\n (route: { key: string }) => route.key === key\n );\n\n jumpToIndex(index);\n },\n [jumpToIndex]\n );\n\n const panResponder = PanResponder.create({\n onMoveShouldSetPanResponder: canMoveScreen,\n onMoveShouldSetPanResponderCapture: canMoveScreen,\n onPanResponderGrant: startGesture,\n onPanResponderMove: respondToGesture,\n onPanResponderTerminate: finishGesture,\n onPanResponderRelease: finishGesture,\n onPanResponderTerminationRequest: () => true,\n });\n\n const maxTranslate = layout.width * (routes.length - 1);\n const translateX = Animated.multiply(\n panX.interpolate({\n inputRange: [-maxTranslate, 0],\n outputRange: [-maxTranslate, 0],\n extrapolate: 'clamp',\n }),\n I18nManager.isRTL ? -1 : 1\n );\n\n return children({\n position: layout.width\n ? Animated.divide(panX, -layout.width)\n : new Animated.Value(index),\n addEnterListener,\n jumpTo,\n render: (children) => (\n <Animated.View\n style={[\n styles.sheet,\n layout.width\n ? {\n width: routes.length * layout.width,\n transform: [{ translateX }],\n }\n : null,\n style,\n ]}\n {...panResponder.panHandlers}\n >\n {React.Children.map(children, (child, i) => {\n const route = routes[i];\n const focused = i === index;\n\n return (\n <View\n key={route.key}\n style={\n layout.width\n ? { width: layout.width }\n : focused\n ? StyleSheet.absoluteFill\n : null\n }\n >\n {focused || layout.width ? child : null}\n </View>\n );\n })}\n </Animated.View>\n ),\n });\n}\n\nconst styles = StyleSheet.create({\n sheet: {\n flex: 1,\n flexDirection: 'row',\n alignItems: 'stretch',\n },\n});\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,QADF,EAEEC,YAFF,EAGEC,QAHF,EAIEC,UAJF,EAOEC,WAPF,EAQEC,IARF,QASO,cATP;AAUA,OAAOC,gBAAP,MAA6B,oBAA7B;AA6BA,MAAMC,SAAS,GAAG,EAAlB;AAEA,MAAMC,qBAAqB,GAAG;EAC5BC,MAAM,EAAET,QAAQ,CAACU,MADW;EAE5BC,SAAS,EAAE,IAFiB;EAG5BC,OAAO,EAAE,GAHmB;EAI5BC,IAAI,EAAE,CAJsB;EAK5BC,iBAAiB,EAAE;AALS,CAA9B;AAQA,eAAe,SAASC,mBAAT,OAWF;EAAA,IAXgD;IAC3DC,MAD2D;IAE3DC,mBAAmB,GAAG,MAFqC;IAG3DC,YAAY,GAAG,IAH4C;IAI3DC,eAJ2D;IAK3DC,aAL2D;IAM3DC,YAN2D;IAO3DC,UAP2D;IAQ3DC,QAR2D;IAS3DC,KAT2D;IAU3DC,gBAAgB,GAAG;EAVwC,CAWhD;EACX,MAAM;IAAEC,MAAF;IAAUC;EAAV,IAAoBR,eAA1B;EAEA,MAAMS,IAAI,GAAGtB,gBAAgB,CAAC,CAAD,CAA7B;EAEA,MAAMuB,YAAY,GAAG9B,KAAK,CAAC+B,MAAN,CAAyB,EAAzB,CAArB;EAEA,MAAMC,kBAAkB,GAAGhC,KAAK,CAAC+B,MAAN,CAAaX,eAA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oBAAC,IAAD;QACE,GAAG,EAAEoE,KAAK,CAACF,GADb;QAEE,KAAK,EACH7E,MAAM,CAACsB,KAAP,GACI;UAAEA,KAAK,EAAEtB,MAAM,CAACsB;QAAhB,CADJ,GAEIqF,OAAO,GACPxH,UAAU,CAACyH,YADJ,GAEP;MAPR,GAUGD,OAAO,IAAI3G,MAAM,CAACsB,KAAlB,GAA0BmF,KAA1B,GAAkC,IAVrC,CADF;IAcD,CAlBA,CAbH;EAPY,CAAD,CAAf;AA0CD;AAED,MAAMN,MAAM,GAAGhH,UAAU,CAAC8F,MAAX,CAAkB;EAC/BmB,KAAK,EAAE;IACLS,IAAI,EAAE,CADD;IAELC,aAAa,EAAE,KAFV;IAGLC,UAAU,EAAE;EAHP;AADwB,CAAlB,CAAf"}
|
|
1
|
+
{"version":3,"names":["React","Animated","PanResponder","Keyboard","StyleSheet","I18nManager","View","useAnimatedValue","DEAD_ZONE","DefaultTransitionSpec","timing","spring","stiffness","damping","mass","overshootClamping","PanResponderAdapter","layout","keyboardDismissMode","swipeEnabled","navigationState","onIndexChange","onSwipeStart","onSwipeEnd","children","style","animationEnabled","routes","index","panX","listenersRef","useRef","navigationStateRef","layoutRef","onIndexChangeRef","currentIndexRef","pendingIndexRef","swipeVelocityThreshold","swipeDistanceThreshold","width","jumpToIndex","useCallback","animate","offset","current","transitionConfig","parallel","toValue","useNativeDriver","start","finished","undefined","setValue","useEffect","dismiss","isMovingHorizontally","_","gestureState","Math","abs","dx","dy","vx","vy","canMoveScreen","event","diffX","isRTL","length","startGesture","stopAnimation","setOffset","_value","respondToGesture","position","_offset","next","ceil","floor","forEach","listener","finishGesture","flattenOffset","currentIndex","nextIndex","round","min","max","isFinite","addEnterListener","push","indexOf","splice","jumpTo","key","findIndex","route","panResponder","create","onMoveShouldSetPanResponder","onMoveShouldSetPanResponderCapture","onPanResponderGrant","onPanResponderMove","onPanResponderTerminate","onPanResponderRelease","onPanResponderTerminationRequest","maxTranslate","translateX","multiply","interpolate","inputRange","outputRange","extrapolate","useMemo","divide","Value","render","styles","sheet","transform","panHandlers","Children","map","child","i","focused","absoluteFill","flex","flexDirection","alignItems"],"sources":["PanResponderAdapter.tsx"],"sourcesContent":["import * as React from 'react';\nimport {\n Animated,\n PanResponder,\n Keyboard,\n StyleSheet,\n GestureResponderEvent,\n PanResponderGestureState,\n I18nManager,\n View,\n} from 'react-native';\nimport useAnimatedValue from './useAnimatedValue';\nimport type {\n NavigationState,\n Route,\n Layout,\n EventEmitterProps,\n PagerProps,\n Listener,\n} from './types';\n\ntype Props<T extends Route> = PagerProps & {\n layout: Layout;\n onIndexChange: (index: number) => void;\n navigationState: NavigationState<T>;\n children: (\n props: EventEmitterProps & {\n // Animated value which represents the state of current index\n // It can include fractional digits as it represents the intermediate value\n position: Animated.AnimatedInterpolation;\n // Function to actually render the content of the pager\n // The parent component takes care of rendering\n render: (children: React.ReactNode) => React.ReactNode;\n // Callback to call when switching the tab\n // The tab switch animation is performed even if the index in state is unchanged\n jumpTo: (key: string) => void;\n }\n ) => React.ReactElement;\n};\n\nconst DEAD_ZONE = 12;\n\nconst DefaultTransitionSpec = {\n timing: Animated.spring,\n stiffness: 1000,\n damping: 500,\n mass: 3,\n overshootClamping: true,\n};\n\nexport default function PanResponderAdapter<T extends Route>({\n layout,\n keyboardDismissMode = 'auto',\n swipeEnabled = true,\n navigationState,\n onIndexChange,\n onSwipeStart,\n onSwipeEnd,\n children,\n style,\n animationEnabled = false,\n}: Props<T>) {\n const { routes, index } = navigationState;\n\n const panX = useAnimatedValue(0);\n\n const listenersRef = React.useRef<Listener[]>([]);\n\n const navigationStateRef = React.useRef(navigationState);\n const layoutRef = React.useRef(layout);\n const onIndexChangeRef = React.useRef(onIndexChange);\n\n const currentIndexRef = React.useRef(index);\n const pendingIndexRef = React.useRef<number>();\n\n const swipeVelocityThreshold = 0.15;\n const swipeDistanceThreshold = layout.width / 1.75;\n\n const jumpToIndex = React.useCallback(\n (index: number, animate = animationEnabled) => {\n const offset = -index * layoutRef.current.width;\n\n const { timing, ...transitionConfig } = DefaultTransitionSpec;\n\n if (animate) {\n Animated.parallel([\n timing(panX, {\n ...transitionConfig,\n toValue: offset,\n useNativeDriver: false,\n }),\n ]).start(({ finished }) => {\n if (finished) {\n onIndexChangeRef.current(index);\n pendingIndexRef.current = undefined;\n }\n });\n pendingIndexRef.current = index;\n } else {\n panX.setValue(offset);\n onIndexChangeRef.current(index);\n pendingIndexRef.current = undefined;\n }\n },\n [animationEnabled, panX]\n );\n\n React.useEffect(() => {\n navigationStateRef.current = navigationState;\n layoutRef.current = layout;\n onIndexChangeRef.current = onIndexChange;\n });\n\n React.useEffect(() => {\n const offset = -navigationStateRef.current.index * layout.width;\n\n panX.setValue(offset);\n }, [layout.width, panX]);\n\n React.useEffect(() => {\n if (keyboardDismissMode === 'auto') {\n Keyboard.dismiss();\n }\n\n if (layout.width && currentIndexRef.current !== index) {\n currentIndexRef.current = index;\n jumpToIndex(index);\n }\n }, [jumpToIndex, keyboardDismissMode, layout.width, index]);\n\n const isMovingHorizontally = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n return (\n Math.abs(gestureState.dx) > Math.abs(gestureState.dy * 2) &&\n Math.abs(gestureState.vx) > Math.abs(gestureState.vy * 2)\n );\n };\n\n const canMoveScreen = (\n event: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n if (swipeEnabled === false) {\n return false;\n }\n\n const diffX = I18nManager.isRTL ? -gestureState.dx : gestureState.dx;\n\n return (\n isMovingHorizontally(event, gestureState) &&\n ((diffX >= DEAD_ZONE && currentIndexRef.current > 0) ||\n (diffX <= -DEAD_ZONE && currentIndexRef.current < routes.length - 1))\n );\n };\n\n const startGesture = () => {\n onSwipeStart?.();\n\n if (keyboardDismissMode === 'on-drag') {\n Keyboard.dismiss();\n }\n\n panX.stopAnimation();\n // @ts-expect-error: _value is private, but docs use it as well\n panX.setOffset(panX._value);\n };\n\n const respondToGesture = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n const diffX = I18nManager.isRTL ? -gestureState.dx : gestureState.dx;\n\n if (\n // swiping left\n (diffX > 0 && index <= 0) ||\n // swiping right\n (diffX < 0 && index >= routes.length - 1)\n ) {\n return;\n }\n\n if (layout.width) {\n // @ts-expect-error: _offset is private, but docs use it as well\n const position = (panX._offset + diffX) / -layout.width;\n const next =\n position > index ? Math.ceil(position) : Math.floor(position);\n\n if (next !== index) {\n listenersRef.current.forEach((listener) => listener(next));\n }\n }\n\n panX.setValue(diffX);\n };\n\n const finishGesture = (\n _: GestureResponderEvent,\n gestureState: PanResponderGestureState\n ) => {\n panX.flattenOffset();\n\n onSwipeEnd?.();\n\n const currentIndex =\n typeof pendingIndexRef.current === 'number'\n ? pendingIndexRef.current\n : currentIndexRef.current;\n\n let nextIndex = currentIndex;\n\n if (\n Math.abs(gestureState.dx) > Math.abs(gestureState.dy) &&\n Math.abs(gestureState.vx) > Math.abs(gestureState.vy) &&\n (Math.abs(gestureState.dx) > swipeDistanceThreshold ||\n Math.abs(gestureState.vx) > swipeVelocityThreshold)\n ) {\n nextIndex = Math.round(\n Math.min(\n Math.max(\n 0,\n I18nManager.isRTL\n ? currentIndex + gestureState.dx / Math.abs(gestureState.dx)\n : currentIndex - gestureState.dx / Math.abs(gestureState.dx)\n ),\n routes.length - 1\n )\n );\n\n currentIndexRef.current = nextIndex;\n }\n\n if (!isFinite(nextIndex)) {\n nextIndex = currentIndex;\n }\n\n jumpToIndex(nextIndex, true);\n };\n\n // TODO: use the listeners\n const addEnterListener = React.useCallback((listener: Listener) => {\n listenersRef.current.push(listener);\n\n return () => {\n const index = listenersRef.current.indexOf(listener);\n\n if (index > -1) {\n listenersRef.current.splice(index, 1);\n }\n };\n }, []);\n\n const jumpTo = React.useCallback(\n (key: string) => {\n const index = navigationStateRef.current.routes.findIndex(\n (route: { key: string }) => route.key === key\n );\n\n jumpToIndex(index);\n },\n [jumpToIndex]\n );\n\n const panResponder = PanResponder.create({\n onMoveShouldSetPanResponder: canMoveScreen,\n onMoveShouldSetPanResponderCapture: canMoveScreen,\n onPanResponderGrant: startGesture,\n onPanResponderMove: respondToGesture,\n onPanResponderTerminate: finishGesture,\n onPanResponderRelease: finishGesture,\n onPanResponderTerminationRequest: () => true,\n });\n\n const maxTranslate = layout.width * (routes.length - 1);\n const translateX = Animated.multiply(\n panX.interpolate({\n inputRange: [-maxTranslate, 0],\n outputRange: [-maxTranslate, 0],\n extrapolate: 'clamp',\n }),\n I18nManager.isRTL ? -1 : 1\n );\n\n const position = React.useMemo(\n () => (layout.width ? Animated.divide(panX, -layout.width) : null),\n [layout.width, panX]\n );\n\n return children({\n position: position ?? new Animated.Value(index),\n addEnterListener,\n jumpTo,\n render: (children) => (\n <Animated.View\n style={[\n styles.sheet,\n layout.width\n ? {\n width: routes.length * layout.width,\n transform: [{ translateX }],\n }\n : null,\n style,\n ]}\n {...panResponder.panHandlers}\n >\n {React.Children.map(children, (child, i) => {\n const route = routes[i];\n const focused = i === index;\n\n return (\n <View\n key={route.key}\n style={\n layout.width\n ? { width: layout.width }\n : focused\n ? StyleSheet.absoluteFill\n : null\n }\n >\n {focused || layout.width ? child : null}\n </View>\n );\n })}\n </Animated.View>\n ),\n });\n}\n\nconst styles = StyleSheet.create({\n sheet: {\n flex: 1,\n flexDirection: 'row',\n alignItems: 'stretch',\n },\n});\n"],"mappings":";;AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,QADF,EAEEC,YAFF,EAGEC,QAHF,EAIEC,UAJF,EAOEC,WAPF,EAQEC,IARF,QASO,cATP;AAUA,OAAOC,gBAAP,MAA6B,oBAA7B;AA6BA,MAAMC,SAAS,GAAG,EAAlB;AAEA,MAAMC,qBAAqB,GAAG;EAC5BC,MAAM,EAAET,QAAQ,CAACU,MADW;EAE5BC,SAAS,EAAE,IAFiB;EAG5BC,OAAO,EAAE,GAHmB;EAI5BC,IAAI,EAAE,CAJsB;EAK5BC,iBAAiB,EAAE;AALS,CAA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