@amazon-devices/react-navigation__react-native-tab-view 7.0.9000000000 → 8.0.9000000000-rn-83

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 (127) hide show
  1. package/README.md +2 -646
  2. package/SystemBundles/adbcd18d13758315355457809fdb5587894f9f3c2c9838769a5a47bf860685c8.bundle +8564 -0
  3. package/SystemBundles/adbcd18d13758315355457809fdb5587894f9f3c2c9838769a5a47bf860685c8.map +3217 -0
  4. package/SystemModules/amzn__react-navigation__react-native-tab-view-8.modules.txt +12 -0
  5. package/SystemModules/amzn__react-navigation__react-native-tab-view-8.private.modules.txt +63 -0
  6. package/SystemModules/keplerscript-system-bundle-config.json +4 -4
  7. package/kepler-compatibility.json +2 -2
  8. package/lib/module/Pager.android.js +3 -1
  9. package/lib/module/Pager.android.js.map +1 -1
  10. package/lib/module/Pager.ios.js +3 -1
  11. package/lib/module/Pager.ios.js.map +1 -1
  12. package/lib/module/Pager.js +3 -1
  13. package/lib/module/Pager.js.map +1 -1
  14. package/lib/module/PagerViewAdapter.js +29 -22
  15. package/lib/module/PagerViewAdapter.js.map +1 -1
  16. package/lib/module/PanResponderAdapter.js +46 -32
  17. package/lib/module/PanResponderAdapter.js.map +1 -1
  18. package/lib/module/PlatformPressable.js +38 -12
  19. package/lib/module/PlatformPressable.js.map +1 -1
  20. package/lib/module/SceneMap.js +7 -4
  21. package/lib/module/SceneMap.js.map +1 -1
  22. package/lib/module/SceneView.js +16 -14
  23. package/lib/module/SceneView.js.map +1 -1
  24. package/lib/module/TabBar.js +232 -156
  25. package/lib/module/TabBar.js.map +1 -1
  26. package/lib/module/TabBarIndicator.js +47 -26
  27. package/lib/module/TabBarIndicator.js.map +1 -1
  28. package/lib/module/TabBarItem.js +106 -107
  29. package/lib/module/TabBarItem.js.map +1 -1
  30. package/lib/module/TabBarItemLabel.js +33 -0
  31. package/lib/module/TabBarItemLabel.js.map +1 -0
  32. package/lib/module/TabView.js +91 -63
  33. package/lib/module/TabView.js.map +1 -1
  34. package/lib/module/index.js +7 -5
  35. package/lib/module/index.js.map +1 -1
  36. package/lib/module/package.json +1 -0
  37. package/lib/module/types.js +2 -0
  38. package/lib/module/types.js.map +1 -1
  39. package/lib/module/useAnimatedValue.js +4 -2
  40. package/lib/module/useAnimatedValue.js.map +1 -1
  41. package/lib/typescript/package.json +1 -0
  42. package/lib/typescript/src/Pager.android.d.ts +1 -1
  43. package/lib/typescript/src/Pager.android.d.ts.map +1 -1
  44. package/lib/typescript/src/Pager.d.ts +1 -1
  45. package/lib/typescript/src/Pager.d.ts.map +1 -1
  46. package/lib/typescript/src/Pager.ios.d.ts +1 -1
  47. package/lib/typescript/src/Pager.ios.d.ts.map +1 -1
  48. package/lib/typescript/src/PagerViewAdapter.d.ts +4 -1
  49. package/lib/typescript/src/PagerViewAdapter.d.ts.map +1 -1
  50. package/lib/typescript/src/PanResponderAdapter.d.ts +4 -1
  51. package/lib/typescript/src/PanResponderAdapter.d.ts.map +1 -1
  52. package/lib/typescript/src/PlatformPressable.d.ts +6 -8
  53. package/lib/typescript/src/PlatformPressable.d.ts.map +1 -1
  54. package/lib/typescript/src/SceneMap.d.ts +2 -2
  55. package/lib/typescript/src/SceneMap.d.ts.map +1 -1
  56. package/lib/typescript/src/SceneView.d.ts +2 -2
  57. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  58. package/lib/typescript/src/TabBar.d.ts +7 -19
  59. package/lib/typescript/src/TabBar.d.ts.map +1 -1
  60. package/lib/typescript/src/TabBarIndicator.d.ts +8 -6
  61. package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -1
  62. package/lib/typescript/src/TabBarItem.d.ts +4 -22
  63. package/lib/typescript/src/TabBarItem.d.ts.map +1 -1
  64. package/lib/typescript/src/TabBarItemLabel.d.ts +11 -0
  65. package/lib/typescript/src/TabBarItemLabel.d.ts.map +1 -0
  66. package/lib/typescript/src/TabView.d.ts +14 -8
  67. package/lib/typescript/src/TabView.d.ts.map +1 -1
  68. package/lib/typescript/src/index.d.ts +6 -6
  69. package/lib/typescript/src/index.d.ts.map +1 -1
  70. package/lib/typescript/src/types.d.ts +29 -1
  71. package/lib/typescript/src/types.d.ts.map +1 -1
  72. package/lib/typescript/src/useAnimatedValue.d.ts +1 -1
  73. package/lib/typescript/src/useAnimatedValue.d.ts.map +1 -1
  74. package/oss-attribution/attribution.txt +0 -0
  75. package/oss-attribution/licenseInfos.json +1 -0
  76. package/package.json +93 -1
  77. package/src/Pager.android.tsx +1 -1
  78. package/src/Pager.ios.tsx +1 -1
  79. package/src/Pager.tsx +1 -1
  80. package/src/PagerViewAdapter.tsx +26 -21
  81. package/src/PanResponderAdapter.tsx +32 -28
  82. package/src/PlatformPressable.tsx +59 -10
  83. package/src/SceneMap.tsx +3 -3
  84. package/src/SceneView.tsx +6 -7
  85. package/src/TabBar.tsx +282 -193
  86. package/src/TabBarIndicator.tsx +65 -28
  87. package/src/TabBarItem.tsx +119 -130
  88. package/src/TabBarItemLabel.tsx +42 -0
  89. package/src/TabView.tsx +59 -16
  90. package/src/index.tsx +11 -6
  91. package/src/types.tsx +29 -1
  92. package/src/useAnimatedValue.tsx +2 -2
  93. package/SystemBundles/df77923df6c02233e2967296227684cd416c9a363cc8fc6fd81f573829bc74e9.bundle +0 -13783
  94. package/SystemBundles/df77923df6c02233e2967296227684cd416c9a363cc8fc6fd81f573829bc74e9.map +0 -4787
  95. package/SystemModules/amzn__react-navigation__react-native-tab-view-7.modules.txt +0 -41
  96. package/SystemModules/amzn__react-navigation__react-native-tab-view-7.private.modules.txt +0 -96
  97. package/THIRD_PARTY_NOTICES.txt +0 -24
  98. package/lib/commonjs/Pager.android.js +0 -14
  99. package/lib/commonjs/Pager.android.js.map +0 -1
  100. package/lib/commonjs/Pager.ios.js +0 -14
  101. package/lib/commonjs/Pager.ios.js.map +0 -1
  102. package/lib/commonjs/Pager.js +0 -14
  103. package/lib/commonjs/Pager.js.map +0 -1
  104. package/lib/commonjs/PagerViewAdapter.js +0 -132
  105. package/lib/commonjs/PagerViewAdapter.js.map +0 -1
  106. package/lib/commonjs/PanResponderAdapter.js +0 -204
  107. package/lib/commonjs/PanResponderAdapter.js.map +0 -1
  108. package/lib/commonjs/PlatformPressable.js +0 -43
  109. package/lib/commonjs/PlatformPressable.js.map +0 -1
  110. package/lib/commonjs/SceneMap.js +0 -29
  111. package/lib/commonjs/SceneMap.js.map +0 -1
  112. package/lib/commonjs/SceneView.js +0 -78
  113. package/lib/commonjs/SceneView.js.map +0 -1
  114. package/lib/commonjs/TabBar.js +0 -405
  115. package/lib/commonjs/TabBar.js.map +0 -1
  116. package/lib/commonjs/TabBarIndicator.js +0 -110
  117. package/lib/commonjs/TabBarIndicator.js.map +0 -1
  118. package/lib/commonjs/TabBarItem.js +0 -227
  119. package/lib/commonjs/TabBarItem.js.map +0 -1
  120. package/lib/commonjs/TabView.js +0 -122
  121. package/lib/commonjs/TabView.js.map +0 -1
  122. package/lib/commonjs/index.js +0 -42
  123. package/lib/commonjs/index.js.map +0 -1
  124. package/lib/commonjs/types.js +0 -6
  125. package/lib/commonjs/types.js.map +0 -1
  126. package/lib/commonjs/useAnimatedValue.js +0 -18
  127. package/lib/commonjs/useAnimatedValue.js.map +0 -1
package/src/TabView.tsx CHANGED
@@ -1,42 +1,55 @@
1
1
  import * as React from 'react';
2
2
  import {
3
- LayoutChangeEvent,
4
- StyleProp,
3
+ I18nManager,
4
+ type LayoutChangeEvent,
5
+ Platform,
6
+ type StyleProp,
5
7
  StyleSheet,
6
8
  View,
7
- ViewStyle,
9
+ type ViewStyle,
8
10
  } from 'react-native';
9
11
 
10
- import Pager from './Pager';
11
- import SceneView from './SceneView';
12
- import TabBar from './TabBar';
12
+ import { Pager } from './Pager';
13
+ import { SceneView } from './SceneView';
14
+ import { TabBar } from './TabBar';
13
15
  import type {
14
16
  Layout,
17
+ LocaleDirection,
15
18
  NavigationState,
16
19
  PagerProps,
17
20
  Route,
18
21
  SceneRendererProps,
22
+ TabDescriptor,
19
23
  } from './types';
20
24
 
21
- export type Props<T extends Route> = PagerProps & {
25
+ export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
22
26
  onIndexChange: (index: number) => void;
27
+ onTabSelect?: (props: { index: number }) => void;
23
28
  navigationState: NavigationState<T>;
24
- renderScene: (props: SceneRendererProps & { route: T }) => React.ReactNode;
25
29
  renderLazyPlaceholder?: (props: { route: T }) => React.ReactNode;
26
30
  renderTabBar?: (
27
- props: SceneRendererProps & { navigationState: NavigationState<T> }
31
+ props: SceneRendererProps & {
32
+ navigationState: NavigationState<T>;
33
+ options: Record<string, TabDescriptor<T>> | undefined;
34
+ }
28
35
  ) => React.ReactNode;
29
36
  tabBarPosition?: 'top' | 'bottom';
30
37
  initialLayout?: Partial<Layout>;
31
38
  lazy?: ((props: { route: T }) => boolean) | boolean;
32
39
  lazyPreloadDistance?: number;
33
- sceneContainerStyle?: StyleProp<ViewStyle>;
40
+ direction?: LocaleDirection;
34
41
  pagerStyle?: StyleProp<ViewStyle>;
35
42
  style?: StyleProp<ViewStyle>;
43
+ renderScene: (props: SceneRendererProps & { route: T }) => React.ReactNode;
44
+ options?: Record<string, TabDescriptor<T>>;
45
+ commonOptions?: TabDescriptor<T>;
36
46
  };
37
47
 
38
- export default function TabView<T extends Route>({
48
+ const renderLazyPlaceholderDefault = () => null;
49
+
50
+ export function TabView<T extends Route>({
39
51
  onIndexChange,
52
+ onTabSelect,
40
53
  navigationState,
41
54
  renderScene,
42
55
  initialLayout,
@@ -45,16 +58,30 @@ export default function TabView<T extends Route>({
45
58
  lazyPreloadDistance = 0,
46
59
  onSwipeStart,
47
60
  onSwipeEnd,
48
- renderLazyPlaceholder = () => null,
61
+ renderLazyPlaceholder = renderLazyPlaceholderDefault,
62
+ // eslint-disable-next-line @eslint-react/no-unstable-default-props
49
63
  renderTabBar = (props) => <TabBar {...props} />,
50
- sceneContainerStyle,
51
64
  pagerStyle,
52
65
  style,
66
+ direction = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr',
53
67
  swipeEnabled = true,
54
68
  tabBarPosition = 'top',
55
69
  animationEnabled = true,
56
70
  overScrollMode,
71
+ options: sceneOptions,
72
+ commonOptions,
57
73
  }: Props<T>) {
74
+ if (
75
+ Platform.OS !== 'web' &&
76
+ direction !== (I18nManager.getConstants().isRTL ? 'rtl' : 'ltr')
77
+ ) {
78
+ console.warn(
79
+ `The 'direction' prop is set to '${direction}' but the effective value is '${
80
+ I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'
81
+ }'. This is not supported. Make sure to match the 'direction' prop with the writing direction of the app.`
82
+ );
83
+ }
84
+
58
85
  const [layout, setLayout] = React.useState({
59
86
  width: 0,
60
87
  height: 0,
@@ -79,6 +106,16 @@ export default function TabView<T extends Route>({
79
106
  });
80
107
  };
81
108
 
109
+ const options = Object.fromEntries(
110
+ navigationState.routes.map((route) => [
111
+ route.key,
112
+ {
113
+ ...commonOptions,
114
+ ...sceneOptions?.[route.key],
115
+ },
116
+ ])
117
+ );
118
+
82
119
  return (
83
120
  <View onLayout={handleLayout} style={[styles.pager, style]}>
84
121
  <Pager
@@ -89,12 +126,14 @@ export default function TabView<T extends Route>({
89
126
  onSwipeStart={onSwipeStart}
90
127
  onSwipeEnd={onSwipeEnd}
91
128
  onIndexChange={jumpToIndex}
129
+ onTabSelect={onTabSelect}
92
130
  animationEnabled={animationEnabled}
93
131
  overScrollMode={overScrollMode}
94
132
  style={pagerStyle}
133
+ layoutDirection={direction}
95
134
  >
96
135
  {({ position, render, addEnterListener, jumpTo }) => {
97
- // All of the props here must not change between re-renders
136
+ // All the props here must not change between re-renders
98
137
  // This is crucial to optimizing the routes with PureComponent
99
138
  const sceneRendererProps = {
100
139
  position,
@@ -107,20 +146,23 @@ export default function TabView<T extends Route>({
107
146
  {tabBarPosition === 'top' &&
108
147
  renderTabBar({
109
148
  ...sceneRendererProps,
149
+ options,
110
150
  navigationState,
111
151
  })}
112
152
  {render(
113
153
  navigationState.routes.map((route, i) => {
154
+ const { sceneStyle } = options?.[route.key] ?? {};
155
+
114
156
  return (
115
157
  <SceneView
158
+ key={route.key}
116
159
  {...sceneRendererProps}
117
160
  addEnterListener={addEnterListener}
118
- key={route.key}
119
161
  index={i}
120
162
  lazy={typeof lazy === 'function' ? lazy({ route }) : lazy}
121
163
  lazyPreloadDistance={lazyPreloadDistance}
122
164
  navigationState={navigationState}
123
- style={sceneContainerStyle}
165
+ style={sceneStyle}
124
166
  >
125
167
  {({ loading }) =>
126
168
  loading
@@ -137,6 +179,7 @@ export default function TabView<T extends Route>({
137
179
  {tabBarPosition === 'bottom' &&
138
180
  renderTabBar({
139
181
  ...sceneRendererProps,
182
+ options,
140
183
  navigationState,
141
184
  })}
142
185
  </React.Fragment>
package/src/index.tsx CHANGED
@@ -1,10 +1,15 @@
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';
10
- export type { NavigationState, Route, SceneRendererProps } from './types';
9
+ export { TabView } from './TabView';
10
+ export type {
11
+ NavigationState,
12
+ Route,
13
+ SceneRendererProps,
14
+ TabDescriptor,
15
+ } from './types';
package/src/types.tsx CHANGED
@@ -1,6 +1,34 @@
1
- import type { Animated } from 'react-native';
1
+ import type { Animated, StyleProp, TextStyle, ViewStyle } from 'react-native';
2
2
  import type { PagerViewProps } from 'react-native-pager-view';
3
3
 
4
+ export type TabDescriptor<T extends Route> = {
5
+ accessibilityLabel?: string;
6
+ accessible?: boolean;
7
+ testID?: string;
8
+ labelText?: string;
9
+ labelAllowFontScaling?: boolean;
10
+ href?: string;
11
+ label?: (props: {
12
+ route: T;
13
+ labelText?: string;
14
+ focused: boolean;
15
+ color: string;
16
+ allowFontScaling?: boolean;
17
+ style?: StyleProp<TextStyle>;
18
+ }) => React.ReactNode;
19
+ labelStyle?: StyleProp<TextStyle>;
20
+ icon?: (props: {
21
+ route: T;
22
+ focused: boolean;
23
+ color: string;
24
+ size: number;
25
+ }) => React.ReactNode;
26
+ badge?: (props: { route: T }) => React.ReactElement;
27
+ sceneStyle?: StyleProp<ViewStyle>;
28
+ };
29
+
30
+ export type LocaleDirection = 'ltr' | 'rtl';
31
+
4
32
  export type Route = {
5
33
  key: string;
6
34
  icon?: string;
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { Animated } from 'react-native';
3
3
 
4
- export default function useAnimatedValue(initialValue: number) {
5
- const lazyRef = React.useRef<Animated.Value>();
4
+ export function useAnimatedValue(initialValue: number) {
5
+ const lazyRef = React.useRef<Animated.Value>(undefined);
6
6
 
7
7
  if (lazyRef.current === undefined) {
8
8
  lazyRef.current = new Animated.Value(initialValue);