react-native-tab-view 3.5.0 → 3.5.2

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 (107) hide show
  1. package/README.md +2 -646
  2. package/lib/commonjs/Pager.android.js +3 -4
  3. package/lib/commonjs/Pager.android.js.map +1 -1
  4. package/lib/commonjs/Pager.ios.js +3 -4
  5. package/lib/commonjs/Pager.ios.js.map +1 -1
  6. package/lib/commonjs/Pager.js +3 -4
  7. package/lib/commonjs/Pager.js.map +1 -1
  8. package/lib/commonjs/PagerViewAdapter.js +4 -4
  9. package/lib/commonjs/PagerViewAdapter.js.map +1 -1
  10. package/lib/commonjs/PanResponderAdapter.js +3 -4
  11. package/lib/commonjs/PanResponderAdapter.js.map +1 -1
  12. package/lib/commonjs/PlatformPressable.js +1 -1
  13. package/lib/commonjs/PlatformPressable.js.map +1 -1
  14. package/lib/commonjs/SceneMap.js +1 -1
  15. package/lib/commonjs/SceneMap.js.map +1 -1
  16. package/lib/commonjs/SceneView.js +1 -1
  17. package/lib/commonjs/SceneView.js.map +1 -1
  18. package/lib/commonjs/TabBar.js +7 -7
  19. package/lib/commonjs/TabBar.js.map +1 -1
  20. package/lib/commonjs/TabBarIndicator.js +3 -4
  21. package/lib/commonjs/TabBarIndicator.js.map +1 -1
  22. package/lib/commonjs/TabBarItem.js +32 -34
  23. package/lib/commonjs/TabBarItem.js.map +1 -1
  24. package/lib/commonjs/TabBarItemLabel.js +36 -0
  25. package/lib/commonjs/TabBarItemLabel.js.map +1 -0
  26. package/lib/commonjs/TabView.js +7 -8
  27. package/lib/commonjs/TabView.js.map +1 -1
  28. package/lib/commonjs/index.js +10 -11
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/commonjs/useAnimatedValue.js +1 -1
  31. package/lib/commonjs/useAnimatedValue.js.map +1 -1
  32. package/lib/module/Pager.android.js +1 -1
  33. package/lib/module/Pager.android.js.map +1 -1
  34. package/lib/module/Pager.ios.js +1 -1
  35. package/lib/module/Pager.ios.js.map +1 -1
  36. package/lib/module/Pager.js +1 -1
  37. package/lib/module/Pager.js.map +1 -1
  38. package/lib/module/PagerViewAdapter.js +2 -2
  39. package/lib/module/PagerViewAdapter.js.map +1 -1
  40. package/lib/module/PanResponderAdapter.js +2 -2
  41. package/lib/module/PanResponderAdapter.js.map +1 -1
  42. package/lib/module/PlatformPressable.js +1 -1
  43. package/lib/module/PlatformPressable.js.map +1 -1
  44. package/lib/module/SceneMap.js +1 -1
  45. package/lib/module/SceneMap.js.map +1 -1
  46. package/lib/module/SceneView.js +1 -1
  47. package/lib/module/SceneView.js.map +1 -1
  48. package/lib/module/TabBar.js +4 -4
  49. package/lib/module/TabBar.js.map +1 -1
  50. package/lib/module/TabBarIndicator.js +2 -2
  51. package/lib/module/TabBarIndicator.js.map +1 -1
  52. package/lib/module/TabBarItem.js +31 -32
  53. package/lib/module/TabBarItem.js.map +1 -1
  54. package/lib/module/TabBarItemLabel.js +28 -0
  55. package/lib/module/TabBarItemLabel.js.map +1 -0
  56. package/lib/module/TabView.js +4 -4
  57. package/lib/module/TabView.js.map +1 -1
  58. package/lib/module/index.js +5 -5
  59. package/lib/module/index.js.map +1 -1
  60. package/lib/module/useAnimatedValue.js +1 -1
  61. package/lib/module/useAnimatedValue.js.map +1 -1
  62. package/lib/typescript/src/Pager.android.d.ts +1 -1
  63. package/lib/typescript/src/Pager.android.d.ts.map +1 -1
  64. package/lib/typescript/src/Pager.d.ts +1 -1
  65. package/lib/typescript/src/Pager.d.ts.map +1 -1
  66. package/lib/typescript/src/Pager.ios.d.ts +1 -1
  67. package/lib/typescript/src/Pager.ios.d.ts.map +1 -1
  68. package/lib/typescript/src/PagerViewAdapter.d.ts +1 -1
  69. package/lib/typescript/src/PagerViewAdapter.d.ts.map +1 -1
  70. package/lib/typescript/src/PanResponderAdapter.d.ts +1 -1
  71. package/lib/typescript/src/PanResponderAdapter.d.ts.map +1 -1
  72. package/lib/typescript/src/PlatformPressable.d.ts +1 -1
  73. package/lib/typescript/src/PlatformPressable.d.ts.map +1 -1
  74. package/lib/typescript/src/SceneMap.d.ts +1 -1
  75. package/lib/typescript/src/SceneMap.d.ts.map +1 -1
  76. package/lib/typescript/src/SceneView.d.ts +1 -1
  77. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  78. package/lib/typescript/src/TabBar.d.ts +1 -1
  79. package/lib/typescript/src/TabBar.d.ts.map +1 -1
  80. package/lib/typescript/src/TabBarIndicator.d.ts +1 -2
  81. package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -1
  82. package/lib/typescript/src/TabBarItem.d.ts +1 -2
  83. package/lib/typescript/src/TabBarItem.d.ts.map +1 -1
  84. package/lib/typescript/src/TabBarItemLabel.d.ts +11 -0
  85. package/lib/typescript/src/TabBarItemLabel.d.ts.map +1 -0
  86. package/lib/typescript/src/TabView.d.ts +1 -1
  87. package/lib/typescript/src/TabView.d.ts.map +1 -1
  88. package/lib/typescript/src/index.d.ts +5 -5
  89. package/lib/typescript/src/index.d.ts.map +1 -1
  90. package/lib/typescript/src/useAnimatedValue.d.ts +1 -1
  91. package/lib/typescript/src/useAnimatedValue.d.ts.map +1 -1
  92. package/package.json +7 -7
  93. package/src/Pager.android.tsx +1 -1
  94. package/src/Pager.ios.tsx +1 -1
  95. package/src/Pager.tsx +1 -1
  96. package/src/PagerViewAdapter.tsx +2 -2
  97. package/src/PanResponderAdapter.tsx +2 -2
  98. package/src/PlatformPressable.tsx +1 -1
  99. package/src/SceneMap.tsx +1 -1
  100. package/src/SceneView.tsx +2 -2
  101. package/src/TabBar.tsx +4 -4
  102. package/src/TabBarIndicator.tsx +2 -2
  103. package/src/TabBarItem.tsx +52 -46
  104. package/src/TabBarItemLabel.tsx +39 -0
  105. package/src/TabView.tsx +4 -4
  106. package/src/index.tsx +5 -5
  107. package/src/useAnimatedValue.tsx +1 -1
@@ -11,7 +11,8 @@ import {
11
11
  } from 'react-native';
12
12
  import useLatestCallback from 'use-latest-callback';
13
13
 
14
- import PlatformPressable from './PlatformPressable';
14
+ import { PlatformPressable } from './PlatformPressable';
15
+ import { TabBarItemLabel } from './TabBarItemLabel';
15
16
  import type { NavigationState, Route, Scene } from './types';
16
17
 
17
18
  export type Props<T extends Route> = {
@@ -85,18 +86,26 @@ const getInactiveOpacity = (
85
86
 
86
87
  type TabBarItemInternalProps<T extends Route> = Omit<
87
88
  Props<T>,
88
- 'navigationState'
89
+ | 'navigationState'
90
+ | 'getAccessibilityLabel'
91
+ | 'getLabelText'
92
+ | 'getTestID'
93
+ | 'getAccessible'
89
94
  > & {
90
95
  isFocused: boolean;
91
96
  index: number;
92
97
  routesLength: number;
98
+ accessibilityLabel?: string;
99
+ label?: string;
100
+ testID?: string;
101
+ accessible?: boolean;
93
102
  };
94
103
 
95
104
  const TabBarItemInternal = <T extends Route>({
96
- getAccessibilityLabel,
97
- getAccessible,
98
- getLabelText,
99
- getTestID,
105
+ accessibilityLabel,
106
+ accessible,
107
+ label: labelText,
108
+ testID,
100
109
  onLongPress,
101
110
  onPress,
102
111
  isFocused,
@@ -166,29 +175,16 @@ const TabBarItemInternal = <T extends Route>({
166
175
  }
167
176
  }
168
177
 
169
- const renderLabel =
170
- renderLabelCustom !== undefined
171
- ? renderLabelCustom
172
- : (labelProps: { route: T; color: string }) => {
173
- const labelText = getLabelText({ route: labelProps.route });
174
-
175
- if (typeof labelText === 'string') {
176
- return (
177
- <Animated.Text
178
- style={[
179
- styles.label,
180
- icon ? { marginTop: 0 } : null,
181
- labelStyle,
182
- { color: labelProps.color },
183
- ]}
184
- >
185
- {labelText}
186
- </Animated.Text>
187
- );
188
- }
189
-
190
- return labelText;
191
- };
178
+ const renderLabel = renderLabelCustom
179
+ ? renderLabelCustom
180
+ : (labelProps: { color: string }) => (
181
+ <TabBarItemLabel
182
+ {...labelProps}
183
+ icon={icon}
184
+ label={labelText}
185
+ labelStyle={labelStyle}
186
+ />
187
+ );
192
188
 
193
189
  if (renderLabel) {
194
190
  const activeLabel = renderLabel({
@@ -225,20 +221,16 @@ const TabBarItemInternal = <T extends Route>({
225
221
 
226
222
  const scene = { route };
227
223
 
228
- let accessibilityLabel = getAccessibilityLabel(scene);
229
-
230
224
  accessibilityLabel =
231
- typeof accessibilityLabel !== 'undefined'
232
- ? accessibilityLabel
233
- : getLabelText(scene);
225
+ typeof accessibilityLabel !== 'undefined' ? accessibilityLabel : labelText;
234
226
 
235
227
  const badge = renderBadge ? renderBadge(scene) : null;
236
228
 
237
229
  return (
238
230
  <PlatformPressable
239
231
  android_ripple={android_ripple}
240
- testID={getTestID(scene)}
241
- accessible={getAccessible(scene)}
232
+ testID={testID}
233
+ accessible={accessible}
242
234
  accessibilityLabel={accessibilityLabel}
243
235
  accessibilityRole="tab"
244
236
  accessibilityState={{ selected: isFocused }}
@@ -265,15 +257,32 @@ const MemoizedTabBarItemInternal = React.memo(
265
257
  TabBarItemInternal
266
258
  ) as typeof TabBarItemInternal;
267
259
 
268
- function TabBarItem<T extends Route>(props: Props<T>) {
269
- const { onPress, onLongPress, onLayout, navigationState, route, ...rest } =
270
- props;
260
+ export function TabBarItem<T extends Route>(props: Props<T>) {
261
+ const {
262
+ onPress,
263
+ onLongPress,
264
+ onLayout,
265
+ navigationState,
266
+ route,
267
+ getAccessibilityLabel,
268
+ getLabelText,
269
+ getTestID,
270
+ getAccessible,
271
+ ...rest
272
+ } = props;
271
273
  const onPressLatest = useLatestCallback(onPress);
272
274
  const onLongPressLatest = useLatestCallback(onLongPress);
273
275
  const onLayoutLatest = useLatestCallback(onLayout ? onLayout : () => {});
274
276
 
275
277
  const tabIndex = navigationState.routes.indexOf(route);
276
278
 
279
+ const scene = { route };
280
+
281
+ const accessibilityLabel = getAccessibilityLabel(scene);
282
+ const label = getLabelText(scene);
283
+ const testID = getTestID(scene);
284
+ const accessible = getAccessible(scene);
285
+
277
286
  return (
278
287
  <MemoizedTabBarItemInternal
279
288
  {...rest}
@@ -284,18 +293,15 @@ function TabBarItem<T extends Route>(props: Props<T>) {
284
293
  route={route}
285
294
  index={tabIndex}
286
295
  routesLength={navigationState.routes.length}
296
+ accessibilityLabel={accessibilityLabel}
297
+ label={label}
298
+ testID={testID}
299
+ accessible={accessible}
287
300
  />
288
301
  );
289
302
  }
290
303
 
291
- export default TabBarItem;
292
-
293
304
  const styles = StyleSheet.create({
294
- label: {
295
- margin: 4,
296
- backgroundColor: 'transparent',
297
- textTransform: 'uppercase',
298
- },
299
305
  icon: {
300
306
  margin: 2,
301
307
  },
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import type { StyleProp, ViewStyle } from 'react-native';
3
+ import { Animated, StyleSheet } from 'react-native';
4
+
5
+ interface TabBarItemLabelProps {
6
+ color: string;
7
+ label?: string;
8
+ labelStyle: StyleProp<ViewStyle>;
9
+ icon: React.ReactNode;
10
+ }
11
+
12
+ export const TabBarItemLabel = React.memo(
13
+ ({ color, label, labelStyle, icon }: TabBarItemLabelProps) => {
14
+ if (!label) {
15
+ return null;
16
+ }
17
+
18
+ return (
19
+ <Animated.Text
20
+ style={[
21
+ styles.label,
22
+ icon ? { marginTop: 0 } : null,
23
+ labelStyle,
24
+ { color: color },
25
+ ]}
26
+ >
27
+ {label}
28
+ </Animated.Text>
29
+ );
30
+ }
31
+ );
32
+
33
+ const styles = StyleSheet.create({
34
+ label: {
35
+ margin: 4,
36
+ backgroundColor: 'transparent',
37
+ textTransform: 'uppercase',
38
+ },
39
+ });
package/src/TabView.tsx CHANGED
@@ -7,9 +7,9 @@ import {
7
7
  ViewStyle,
8
8
  } from 'react-native';
9
9
 
10
- import Pager from './Pager';
11
- import SceneView from './SceneView';
12
- import TabBar from './TabBar';
10
+ import { Pager } from './Pager';
11
+ import { SceneView } from './SceneView';
12
+ import { TabBar } from './TabBar';
13
13
  import type {
14
14
  Layout,
15
15
  NavigationState,
@@ -35,7 +35,7 @@ export type Props<T extends Route> = PagerProps & {
35
35
  style?: StyleProp<ViewStyle>;
36
36
  };
37
37
 
38
- export default function TabView<T extends Route>({
38
+ export function TabView<T extends Route>({
39
39
  onIndexChange,
40
40
  navigationState,
41
41
  renderScene,
package/src/index.tsx CHANGED
@@ -1,10 +1,10 @@
1
- export { default as SceneMap } from './SceneMap';
1
+ export { SceneMap } from './SceneMap';
2
2
  export type { Props as TabBarProps } from './TabBar';
3
- export { default as TabBar } from './TabBar';
3
+ export { TabBar } from './TabBar';
4
4
  export type { Props as TabBarIndicatorProps } from './TabBarIndicator';
5
- export { default as TabBarIndicator } from './TabBarIndicator';
5
+ export { TabBarIndicator } from './TabBarIndicator';
6
6
  export type { Props as TabBarItemProps } from './TabBarItem';
7
- export { default as TabBarItem } from './TabBarItem';
7
+ export { TabBarItem } from './TabBarItem';
8
8
  export type { Props as TabViewProps } from './TabView';
9
- export { default as TabView } from './TabView';
9
+ export { TabView } from './TabView';
10
10
  export type { NavigationState, Route, SceneRendererProps } from './types';
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { Animated } from 'react-native';
3
3
 
4
- export default function useAnimatedValue(initialValue: number) {
4
+ export function useAnimatedValue(initialValue: number) {
5
5
  const lazyRef = React.useRef<Animated.Value>();
6
6
 
7
7
  if (lazyRef.current === undefined) {