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.
Files changed (41) hide show
  1. package/lib/commonjs/PagerViewAdapter.js +2 -1
  2. package/lib/commonjs/PagerViewAdapter.js.map +1 -1
  3. package/lib/commonjs/PanResponderAdapter.js +2 -1
  4. package/lib/commonjs/PanResponderAdapter.js.map +1 -1
  5. package/lib/commonjs/SceneMap.js +9 -12
  6. package/lib/commonjs/SceneMap.js.map +1 -1
  7. package/lib/commonjs/SceneView.js +54 -101
  8. package/lib/commonjs/SceneView.js.map +1 -1
  9. package/lib/commonjs/TabBar.js +327 -327
  10. package/lib/commonjs/TabBar.js.map +1 -1
  11. package/lib/commonjs/TabBarIndicator.js +81 -99
  12. package/lib/commonjs/TabBarIndicator.js.map +1 -1
  13. package/lib/commonjs/TabBarItem.js +184 -161
  14. package/lib/commonjs/TabBarItem.js.map +1 -1
  15. package/lib/module/PagerViewAdapter.js +2 -1
  16. package/lib/module/PagerViewAdapter.js.map +1 -1
  17. package/lib/module/PanResponderAdapter.js +2 -1
  18. package/lib/module/PanResponderAdapter.js.map +1 -1
  19. package/lib/module/SceneMap.js +9 -14
  20. package/lib/module/SceneMap.js.map +1 -1
  21. package/lib/module/SceneView.js +53 -98
  22. package/lib/module/SceneView.js.map +1 -1
  23. package/lib/module/TabBar.js +323 -323
  24. package/lib/module/TabBar.js.map +1 -1
  25. package/lib/module/TabBarIndicator.js +74 -92
  26. package/lib/module/TabBarIndicator.js.map +1 -1
  27. package/lib/module/TabBarItem.js +178 -154
  28. package/lib/module/TabBarItem.js.map +1 -1
  29. package/lib/typescript/SceneMap.d.ts +5 -3
  30. package/lib/typescript/SceneView.d.ts +1 -18
  31. package/lib/typescript/TabBar.d.ts +7 -38
  32. package/lib/typescript/TabBarIndicator.d.ts +2 -10
  33. package/lib/typescript/TabBarItem.d.ts +3 -5
  34. package/package.json +4 -1
  35. package/src/PagerViewAdapter.tsx +6 -1
  36. package/src/PanResponderAdapter.tsx +6 -3
  37. package/src/SceneMap.tsx +11 -7
  38. package/src/SceneView.tsx +70 -106
  39. package/src/TabBar.tsx +451 -391
  40. package/src/TabBarIndicator.tsx +108 -114
  41. package/src/TabBarItem.tsx +214 -185
@@ -1,182 +1,206 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1
+ 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); }
2
2
 
3
3
  import * as React from 'react';
4
4
  import { Animated, StyleSheet, View } from 'react-native';
5
+ import useLatestCallback from 'use-latest-callback';
5
6
  import PlatformPressable from './PlatformPressable';
6
7
  const DEFAULT_ACTIVE_COLOR = 'rgba(255, 255, 255, 1)';
7
8
  const DEFAULT_INACTIVE_COLOR = 'rgba(255, 255, 255, 0.7)';
8
- export default class TabBarItem extends React.Component {
9
- constructor() {
10
- super(...arguments);
11
9
 
12
- _defineProperty(this, "getActiveOpacity", (position, routes, tabIndex) => {
13
- if (routes.length > 1) {
14
- const inputRange = routes.map((_, i) => i);
15
- return position.interpolate({
16
- inputRange,
17
- outputRange: inputRange.map(i => i === tabIndex ? 1 : 0)
18
- });
19
- } else {
20
- return 1;
21
- }
10
+ const getActiveOpacity = (position, routesLength, tabIndex) => {
11
+ if (routesLength > 1) {
12
+ const inputRange = Array.from({
13
+ length: routesLength
14
+ }, (_, i) => i);
15
+ return position.interpolate({
16
+ inputRange,
17
+ outputRange: inputRange.map(i => i === tabIndex ? 1 : 0)
22
18
  });
19
+ } else {
20
+ return 1;
21
+ }
22
+ };
23
23
 
24
- _defineProperty(this, "getInactiveOpacity", (position, routes, tabIndex) => {
25
- if (routes.length > 1) {
26
- const inputRange = routes.map((_, i) => i);
27
- return position.interpolate({
28
- inputRange,
29
- outputRange: inputRange.map(i => i === tabIndex ? 0 : 1)
30
- });
31
- } else {
32
- return 0;
33
- }
24
+ const getInactiveOpacity = (position, routesLength, tabIndex) => {
25
+ if (routesLength > 1) {
26
+ const inputRange = Array.from({
27
+ length: routesLength
28
+ }, (_, i) => i);
29
+ return position.interpolate({
30
+ inputRange,
31
+ outputRange: inputRange.map(i => i === tabIndex ? 0 : 1)
34
32
  });
33
+ } else {
34
+ return 0;
35
35
  }
36
+ };
36
37
 
37
- render() {
38
- const {
39
- route,
40
- position,
41
- navigationState,
42
- renderLabel: renderLabelCustom,
43
- renderIcon,
44
- renderBadge,
45
- getLabelText,
46
- getTestID,
47
- getAccessibilityLabel,
48
- getAccessible,
49
- activeColor: activeColorCustom,
50
- inactiveColor: inactiveColorCustom,
51
- pressColor,
52
- pressOpacity,
53
- labelStyle,
54
- style,
55
- onLayout,
56
- onPress,
57
- onLongPress
58
- } = this.props;
59
- const tabIndex = navigationState.routes.indexOf(route);
60
- const isFocused = navigationState.index === tabIndex;
61
- const labelColorFromStyle = StyleSheet.flatten(labelStyle || {}).color;
62
- const activeColor = activeColorCustom !== undefined ? activeColorCustom : typeof labelColorFromStyle === 'string' ? labelColorFromStyle : DEFAULT_ACTIVE_COLOR;
63
- const inactiveColor = inactiveColorCustom !== undefined ? inactiveColorCustom : typeof labelColorFromStyle === 'string' ? labelColorFromStyle : DEFAULT_INACTIVE_COLOR;
64
- const activeOpacity = this.getActiveOpacity(position, navigationState.routes, tabIndex);
65
- const inactiveOpacity = this.getInactiveOpacity(position, navigationState.routes, tabIndex);
66
- let icon = null;
67
- let label = null;
68
-
69
- if (renderIcon) {
70
- const activeIcon = renderIcon({
71
- route,
72
- focused: true,
73
- color: activeColor
74
- });
75
- const inactiveIcon = renderIcon({
76
- route,
77
- focused: false,
78
- color: inactiveColor
79
- });
80
-
81
- if (inactiveIcon != null && activeIcon != null) {
82
- icon = /*#__PURE__*/React.createElement(View, {
83
- style: styles.icon
84
- }, /*#__PURE__*/React.createElement(Animated.View, {
85
- style: {
86
- opacity: inactiveOpacity
87
- }
88
- }, inactiveIcon), /*#__PURE__*/React.createElement(Animated.View, {
89
- style: [StyleSheet.absoluteFill, {
90
- opacity: activeOpacity
91
- }]
92
- }, activeIcon));
93
- }
94
- }
38
+ const TabBarItemInternal = _ref => {
39
+ let {
40
+ getAccessibilityLabel,
41
+ getAccessible,
42
+ getLabelText,
43
+ getTestID,
44
+ onLongPress,
45
+ onPress,
46
+ isFocused,
47
+ position,
48
+ route,
49
+ style,
50
+ inactiveColor: inactiveColorCustom,
51
+ activeColor: activeColorCustom,
52
+ labelStyle,
53
+ onLayout,
54
+ index: tabIndex,
55
+ pressColor,
56
+ pressOpacity,
57
+ renderBadge,
58
+ renderIcon,
59
+ defaultTabWidth,
60
+ routesLength,
61
+ renderLabel: renderLabelCustom
62
+ } = _ref;
63
+ const labelColorFromStyle = StyleSheet.flatten(labelStyle || {}).color;
64
+ const activeColor = activeColorCustom !== undefined ? activeColorCustom : typeof labelColorFromStyle === 'string' ? labelColorFromStyle : DEFAULT_ACTIVE_COLOR;
65
+ const inactiveColor = inactiveColorCustom !== undefined ? inactiveColorCustom : typeof labelColorFromStyle === 'string' ? labelColorFromStyle : DEFAULT_INACTIVE_COLOR;
66
+ const activeOpacity = getActiveOpacity(position, routesLength, tabIndex);
67
+ const inactiveOpacity = getInactiveOpacity(position, routesLength, tabIndex);
68
+ let icon = null;
69
+ let label = null;
95
70
 
96
- const renderLabel = renderLabelCustom !== undefined ? renderLabelCustom : _ref => {
97
- let {
98
- route,
99
- color
100
- } = _ref;
101
- const labelText = getLabelText({
102
- route
103
- });
104
-
105
- if (typeof labelText === 'string') {
106
- return /*#__PURE__*/React.createElement(Animated.Text, {
107
- style: [styles.label, icon ? {
108
- marginTop: 0
109
- } : null, labelStyle, {
110
- color
111
- }]
112
- }, labelText);
113
- }
114
-
115
- return labelText;
116
- };
71
+ if (renderIcon) {
72
+ const activeIcon = renderIcon({
73
+ route,
74
+ focused: true,
75
+ color: activeColor
76
+ });
77
+ const inactiveIcon = renderIcon({
78
+ route,
79
+ focused: false,
80
+ color: inactiveColor
81
+ });
117
82
 
118
- if (renderLabel) {
119
- const activeLabel = renderLabel({
120
- route,
121
- focused: true,
122
- color: activeColor
123
- });
124
- const inactiveLabel = renderLabel({
125
- route,
126
- focused: false,
127
- color: inactiveColor
128
- });
129
- label = /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(Animated.View, {
83
+ if (inactiveIcon != null && activeIcon != null) {
84
+ icon = /*#__PURE__*/React.createElement(View, {
85
+ style: styles.icon
86
+ }, /*#__PURE__*/React.createElement(Animated.View, {
130
87
  style: {
131
88
  opacity: inactiveOpacity
132
89
  }
133
- }, inactiveLabel), /*#__PURE__*/React.createElement(Animated.View, {
90
+ }, inactiveIcon), /*#__PURE__*/React.createElement(Animated.View, {
134
91
  style: [StyleSheet.absoluteFill, {
135
92
  opacity: activeOpacity
136
93
  }]
137
- }, activeLabel));
94
+ }, activeIcon));
95
+ }
96
+ }
97
+
98
+ const renderLabel = renderLabelCustom !== undefined ? renderLabelCustom : labelProps => {
99
+ const labelText = getLabelText({
100
+ route: labelProps.route
101
+ });
102
+
103
+ if (typeof labelText === 'string') {
104
+ return /*#__PURE__*/React.createElement(Animated.Text, {
105
+ style: [styles.label, icon ? {
106
+ marginTop: 0
107
+ } : null, labelStyle, {
108
+ color: labelProps.color
109
+ }]
110
+ }, labelText);
138
111
  }
139
112
 
140
- const tabStyle = StyleSheet.flatten(style);
141
- const isWidthSet = (tabStyle === null || tabStyle === void 0 ? void 0 : tabStyle.width) !== undefined;
142
- const tabContainerStyle = isWidthSet ? null : {
143
- flex: 1
144
- };
145
- const scene = {
146
- route
147
- };
148
- let accessibilityLabel = getAccessibilityLabel(scene);
149
- accessibilityLabel = typeof accessibilityLabel !== 'undefined' ? accessibilityLabel : getLabelText(scene);
150
- const badge = renderBadge ? renderBadge(scene) : null;
151
- return /*#__PURE__*/React.createElement(PlatformPressable, {
152
- android_ripple: {
153
- borderless: true
154
- },
155
- testID: getTestID(scene),
156
- accessible: getAccessible(scene),
157
- accessibilityLabel: accessibilityLabel,
158
- accessibilityRole: "tab",
159
- accessibilityState: {
160
- selected: isFocused
161
- } // @ts-ignore: this is to support older React Native versions
162
- ,
163
- accessibilityStates: isFocused ? ['selected'] : [],
164
- pressColor: pressColor,
165
- pressOpacity: pressOpacity,
166
- delayPressIn: 0,
167
- onLayout: onLayout,
168
- onPress: onPress,
169
- onLongPress: onLongPress,
170
- style: [styles.pressable, tabContainerStyle]
171
- }, /*#__PURE__*/React.createElement(View, {
172
- pointerEvents: "none",
173
- style: [styles.item, tabStyle]
174
- }, icon, label, badge != null ? /*#__PURE__*/React.createElement(View, {
175
- style: styles.badge
176
- }, badge) : null));
113
+ return labelText;
114
+ };
115
+
116
+ if (renderLabel) {
117
+ const activeLabel = renderLabel({
118
+ route,
119
+ focused: true,
120
+ color: activeColor
121
+ });
122
+ const inactiveLabel = renderLabel({
123
+ route,
124
+ focused: false,
125
+ color: inactiveColor
126
+ });
127
+ label = /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(Animated.View, {
128
+ style: {
129
+ opacity: inactiveOpacity
130
+ }
131
+ }, inactiveLabel), /*#__PURE__*/React.createElement(Animated.View, {
132
+ style: [StyleSheet.absoluteFill, {
133
+ opacity: activeOpacity
134
+ }]
135
+ }, activeLabel));
177
136
  }
178
137
 
138
+ const tabStyle = StyleSheet.flatten(style);
139
+ const isWidthSet = (tabStyle === null || tabStyle === void 0 ? void 0 : tabStyle.width) !== undefined;
140
+ const tabContainerStyle = isWidthSet ? null : {
141
+ width: defaultTabWidth
142
+ };
143
+ const scene = {
144
+ route
145
+ };
146
+ let accessibilityLabel = getAccessibilityLabel(scene);
147
+ accessibilityLabel = typeof accessibilityLabel !== 'undefined' ? accessibilityLabel : getLabelText(scene);
148
+ const badge = renderBadge ? renderBadge(scene) : null;
149
+ return /*#__PURE__*/React.createElement(PlatformPressable, {
150
+ android_ripple: {
151
+ borderless: true
152
+ },
153
+ testID: getTestID(scene),
154
+ accessible: getAccessible(scene),
155
+ accessibilityLabel: accessibilityLabel,
156
+ accessibilityRole: "tab",
157
+ accessibilityState: {
158
+ selected: isFocused
159
+ } // @ts-ignore: this is to support older React Native versions
160
+ ,
161
+ accessibilityStates: isFocused ? ['selected'] : [],
162
+ pressColor: pressColor,
163
+ pressOpacity: pressOpacity,
164
+ delayPressIn: 0,
165
+ onLayout: onLayout,
166
+ onPress: onPress,
167
+ onLongPress: onLongPress,
168
+ style: [styles.pressable, tabContainerStyle]
169
+ }, /*#__PURE__*/React.createElement(View, {
170
+ pointerEvents: "none",
171
+ style: [styles.item, tabStyle]
172
+ }, icon, label, badge != null ? /*#__PURE__*/React.createElement(View, {
173
+ style: styles.badge
174
+ }, badge) : null));
175
+ };
176
+
177
+ const MemoizedTabBarItemInternal = /*#__PURE__*/React.memo(TabBarItemInternal);
178
+
179
+ function TabBarItem(props) {
180
+ const {
181
+ onPress,
182
+ onLongPress,
183
+ onLayout,
184
+ navigationState,
185
+ route,
186
+ ...rest
187
+ } = props;
188
+ const onPressLatest = useLatestCallback(onPress);
189
+ const onLongPressLatest = useLatestCallback(onLongPress);
190
+ const onLayoutLatest = useLatestCallback(onLayout ? onLayout : () => {});
191
+ const tabIndex = navigationState.routes.indexOf(route);
192
+ return /*#__PURE__*/React.createElement(MemoizedTabBarItemInternal, _extends({}, rest, {
193
+ onPress: onPressLatest,
194
+ onLayout: onLayoutLatest,
195
+ onLongPress: onLongPressLatest,
196
+ isFocused: navigationState.index === tabIndex,
197
+ route: route,
198
+ index: tabIndex,
199
+ routesLength: navigationState.routes.length
200
+ }));
179
201
  }
202
+
203
+ export default TabBarItem;
180
204
  const styles = StyleSheet.create({
181
205
  label: {
182
206
  margin: 4,
@@ -1 +1 @@
1
- {"version":3,"names":["React","Animated","StyleSheet","View","PlatformPressable","DEFAULT_ACTIVE_COLOR","DEFAULT_INACTIVE_COLOR","TabBarItem","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","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,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,QADF,EAEEC,UAFF,EAGEC,IAHF,QAQO,cARP;AASA,OAAOC,iBAAP,MAA8B,qBAA9B;AAiCA,MAAMC,oBAAoB,GAAG,wBAA7B;AACA,MAAMC,sBAAsB,GAAG,0BAA/B;AAEA,eAAe,MAAMC,UAAN,SAA0CP,KAAK,CAACQ,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;UAC1BJ,UAD0B;UAE1BK,WAAW,EAAEL,UAAU,CAACC,GAAX,CAAgBE,CAAD,IAAQA,CAAC,KAAKL,QAAN,GAAiB,CAAjB,GAAqB,CAA5C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Z;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;IACL/D,QAAQ,EAAE,UADL;IAEL4E,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":["React","Animated","StyleSheet","View","useLatestCallback","PlatformPressable","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","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","memo","TabBarItem","props","navigationState","rest","onPressLatest","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,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,SACEC,QADF,EAEEC,UAFF,EAGEC,IAHF,QAQO,cARP;AASA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AAkCA,MAAMC,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;;AAiBA,MA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RendererProps } from './types';
3
+ declare type SceneProps = {
4
+ route: any;
5
+ } & Omit<SceneRendererProps, 'layout'>;
3
6
  export default function SceneMap<T extends any>(scenes: {
4
7
  [key: string]: React.ComponentType<T>;
5
- }): ({ route, jumpTo, position }: SceneRendererProps & {
6
- route: any;
7
- }) => JSX.Element;
8
+ }): ({ route, jumpTo, position }: SceneProps) => JSX.Element;
9
+ export {};
@@ -11,22 +11,5 @@ declare type Props<T extends Route> = SceneRendererProps & EventEmitterProps & {
11
11
  }) => React.ReactNode;
12
12
  style?: StyleProp<ViewStyle>;
13
13
  };
14
- declare type State = {
15
- loading: boolean;
16
- };
17
- export default class SceneView<T extends Route> extends React.Component<Props<T>, State> {
18
- static getDerivedStateFromProps(props: Props<Route>, state: State): {
19
- loading: boolean;
20
- } | null;
21
- state: {
22
- loading: boolean;
23
- };
24
- componentDidMount(): void;
25
- componentDidUpdate(prevProps: Props<T>, prevState: State): void;
26
- componentWillUnmount(): void;
27
- private timerHandler;
28
- private unsubscribe;
29
- private handleEnter;
30
- render(): JSX.Element;
31
- }
14
+ export default function SceneView<T extends Route>({ children, navigationState, lazy, layout, index, lazyPreloadDistance, addEnterListener, style, }: Props<T>): JSX.Element;
32
15
  export {};
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { StyleProp, ViewStyle, TextStyle } from 'react-native';
3
3
  import { Props as TabBarItemProps } from './TabBarItem';
4
4
  import { Props as IndicatorProps } from './TabBarIndicator';
5
- import type { Route, Scene, SceneRendererProps, NavigationState, Layout, Event } from './types';
5
+ import type { Route, Scene, SceneRendererProps, NavigationState, Event } from './types';
6
6
  export declare type Props<T extends Route> = SceneRendererProps & {
7
7
  navigationState: NavigationState<T>;
8
8
  scrollEnabled?: boolean;
@@ -11,10 +11,10 @@ export declare type Props<T extends Route> = SceneRendererProps & {
11
11
  inactiveColor?: string;
12
12
  pressColor?: string;
13
13
  pressOpacity?: number;
14
- getLabelText: (scene: Scene<T>) => string | undefined;
15
- getAccessible: (scene: Scene<T>) => boolean | undefined;
16
- getAccessibilityLabel: (scene: Scene<T>) => string | undefined;
17
- getTestID: (scene: Scene<T>) => string | undefined;
14
+ getLabelText?: (scene: Scene<T>) => string | undefined;
15
+ getAccessible?: (scene: Scene<T>) => boolean | undefined;
16
+ getAccessibilityLabel?: (scene: Scene<T>) => string | undefined;
17
+ getTestID?: (scene: Scene<T>) => string | undefined;
18
18
  renderLabel?: (scene: Scene<T> & {
19
19
  focused: boolean;
20
20
  color: string;
@@ -24,7 +24,7 @@ export declare type Props<T extends Route> = SceneRendererProps & {
24
24
  color: string;
25
25
  }) => React.ReactNode;
26
26
  renderBadge?: (scene: Scene<T>) => React.ReactNode;
27
- renderIndicator: (props: IndicatorProps<T>) => React.ReactNode;
27
+ renderIndicator?: (props: IndicatorProps<T>) => React.ReactNode;
28
28
  renderTabBarItem?: (props: TabBarItemProps<T> & {
29
29
  key: string;
30
30
  }) => React.ReactElement;
@@ -38,35 +38,4 @@ export declare type Props<T extends Route> = SceneRendererProps & {
38
38
  style?: StyleProp<ViewStyle>;
39
39
  gap?: number;
40
40
  };
41
- declare type State = {
42
- layout: Layout;
43
- tabWidths: {
44
- [key: string]: number;
45
- };
46
- };
47
- export default class TabBar<T extends Route> extends React.Component<Props<T>, State> {
48
- static defaultProps: {
49
- getLabelText: ({ route }: Scene<Route>) => string | undefined;
50
- getAccessible: ({ route }: Scene<Route>) => boolean;
51
- getAccessibilityLabel: ({ route }: Scene<Route>) => string | undefined;
52
- getTestID: ({ route }: Scene<Route>) => string | undefined;
53
- renderIndicator: (props: IndicatorProps<Route>) => JSX.Element;
54
- gap: number;
55
- };
56
- state: State;
57
- componentDidUpdate(prevProps: Props<T>, prevState: State): void;
58
- private measuredTabWidths;
59
- private scrollAmount;
60
- private flatListRef;
61
- private getFlattenedTabWidth;
62
- private getComputedTabWidth;
63
- private getMaxScrollDistance;
64
- private getTabBarWidth;
65
- private normalizeScrollValue;
66
- private getScrollAmount;
67
- private resetScroll;
68
- private handleLayout;
69
- private getTranslateX;
70
- render(): JSX.Element;
71
- }
72
- export {};
41
+ export default function TabBar<T extends Route>({ getLabelText, getAccessible, getAccessibilityLabel, getTestID, renderIndicator, gap, scrollEnabled, jumpTo, navigationState, position, activeColor, bounces, contentContainerStyle, inactiveColor, indicatorContainerStyle, indicatorStyle, labelStyle, onTabLongPress, onTabPress, pressColor, pressOpacity, renderBadge, renderIcon, renderLabel, renderTabBarItem, style, tabStyle, }: Props<T>): JSX.Element;
@@ -1,4 +1,4 @@
1
- import * as React from 'react';
1
+ /// <reference types="react" />
2
2
  import { StyleProp, ViewStyle } from 'react-native';
3
3
  import type { Route, SceneRendererProps, NavigationState } from './types';
4
4
  export declare type GetTabWidth = (index: number) => number;
@@ -9,12 +9,4 @@ export declare type Props<T extends Route> = SceneRendererProps & {
9
9
  getTabWidth: GetTabWidth;
10
10
  gap?: number;
11
11
  };
12
- export default class TabBarIndicator<T extends Route> extends React.Component<Props<T>> {
13
- componentDidMount(): void;
14
- componentDidUpdate(): void;
15
- private fadeInIndicator;
16
- private isIndicatorShown;
17
- private opacity;
18
- private getTranslateX;
19
- render(): JSX.Element;
20
- }
12
+ export default function TabBarIndicator<T extends Route>({ getTabWidth, layout, navigationState, position, width, gap, style, }: Props<T>): JSX.Element;
@@ -27,11 +27,9 @@ export declare type Props<T extends Route> = {
27
27
  onLayout?: (event: LayoutChangeEvent) => void;
28
28
  onPress: () => void;
29
29
  onLongPress: () => void;
30
+ defaultTabWidth?: number;
30
31
  labelStyle?: StyleProp<TextStyle>;
31
32
  style: StyleProp<ViewStyle>;
32
33
  };
33
- export default class TabBarItem<T extends Route> extends React.Component<Props<T>> {
34
- private getActiveOpacity;
35
- private getInactiveOpacity;
36
- render(): JSX.Element;
37
- }
34
+ declare function TabBarItem<T extends Route>(props: Props<T>): JSX.Element;
35
+ export default TabBarItem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-tab-view",
3
- "version": "3.2.1",
3
+ "version": "3.3.0",
4
4
  "description": "Tab view component for React Native",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "react-native": "src/index.tsx",
@@ -97,5 +97,8 @@
97
97
  }
98
98
  ]
99
99
  ]
100
+ },
101
+ "dependencies": {
102
+ "use-latest-callback": "^0.1.5"
100
103
  }
101
104
  }
@@ -129,8 +129,13 @@ export default function PagerViewAdapter<T extends Route>({
129
129
  };
130
130
  }, []);
131
131
 
132
+ const memoizedPosition = React.useMemo(
133
+ () => Animated.add(position, offset),
134
+ [offset, position]
135
+ );
136
+
132
137
  return children({
133
- position: Animated.add(position, offset),
138
+ position: memoizedPosition,
134
139
  addEnterListener,
135
140
  jumpTo,
136
141
  render: (children) => (
@@ -283,10 +283,13 @@ export default function PanResponderAdapter<T extends Route>({
283
283
  I18nManager.isRTL ? -1 : 1
284
284
  );
285
285
 
286
+ const position = React.useMemo(
287
+ () => (layout.width ? Animated.divide(panX, -layout.width) : null),
288
+ [layout.width, panX]
289
+ );
290
+
286
291
  return children({
287
- position: layout.width
288
- ? Animated.divide(panX, -layout.width)
289
- : new Animated.Value(index),
292
+ position: position ?? new Animated.Value(index),
290
293
  addEnterListener,
291
294
  jumpTo,
292
295
  render: (children) => (