@amazon-devices/react-navigation__react-native-tab-view 2.0.1758683737

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 (116) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +649 -0
  3. package/SystemBundles/c5889b273a6efc2a3c30241851055c37630fbf3381df86d403967369775f0536.bundle +14497 -0
  4. package/SystemBundles/c5889b273a6efc2a3c30241851055c37630fbf3381df86d403967369775f0536.map +1 -0
  5. package/SystemModules/amzn__react-navigation__react-native-tab-view-2.modules.txt +41 -0
  6. package/SystemModules/amzn__react-navigation__react-native-tab-view-2.private.modules.txt +98 -0
  7. package/SystemModules/keplerscript-system-bundle-config.json +7 -0
  8. package/THIRD_PARTY_NOTICES.txt +24 -0
  9. package/kepler-compatibility.json +8 -0
  10. package/kepler-transformed-package-info.json +3 -0
  11. package/lib/commonjs/Pager.android.js +14 -0
  12. package/lib/commonjs/Pager.android.js.map +1 -0
  13. package/lib/commonjs/Pager.ios.js +14 -0
  14. package/lib/commonjs/Pager.ios.js.map +1 -0
  15. package/lib/commonjs/Pager.js +14 -0
  16. package/lib/commonjs/Pager.js.map +1 -0
  17. package/lib/commonjs/PagerViewAdapter.js +132 -0
  18. package/lib/commonjs/PagerViewAdapter.js.map +1 -0
  19. package/lib/commonjs/PanResponderAdapter.js +204 -0
  20. package/lib/commonjs/PanResponderAdapter.js.map +1 -0
  21. package/lib/commonjs/PlatformPressable.js +43 -0
  22. package/lib/commonjs/PlatformPressable.js.map +1 -0
  23. package/lib/commonjs/SceneMap.js +29 -0
  24. package/lib/commonjs/SceneMap.js.map +1 -0
  25. package/lib/commonjs/SceneView.js +78 -0
  26. package/lib/commonjs/SceneView.js.map +1 -0
  27. package/lib/commonjs/TabBar.js +405 -0
  28. package/lib/commonjs/TabBar.js.map +1 -0
  29. package/lib/commonjs/TabBarIndicator.js +110 -0
  30. package/lib/commonjs/TabBarIndicator.js.map +1 -0
  31. package/lib/commonjs/TabBarItem.js +227 -0
  32. package/lib/commonjs/TabBarItem.js.map +1 -0
  33. package/lib/commonjs/TabView.js +122 -0
  34. package/lib/commonjs/TabView.js.map +1 -0
  35. package/lib/commonjs/index.js +42 -0
  36. package/lib/commonjs/index.js.map +1 -0
  37. package/lib/commonjs/types.js +6 -0
  38. package/lib/commonjs/types.js.map +1 -0
  39. package/lib/commonjs/useAnimatedValue.js +18 -0
  40. package/lib/commonjs/useAnimatedValue.js.map +1 -0
  41. package/lib/module/Pager.android.js +2 -0
  42. package/lib/module/Pager.android.js.map +1 -0
  43. package/lib/module/Pager.ios.js +2 -0
  44. package/lib/module/Pager.ios.js.map +1 -0
  45. package/lib/module/Pager.js +2 -0
  46. package/lib/module/Pager.js.map +1 -0
  47. package/lib/module/PagerViewAdapter.js +123 -0
  48. package/lib/module/PagerViewAdapter.js.map +1 -0
  49. package/lib/module/PanResponderAdapter.js +195 -0
  50. package/lib/module/PanResponderAdapter.js.map +1 -0
  51. package/lib/module/PlatformPressable.js +35 -0
  52. package/lib/module/PlatformPressable.js.map +1 -0
  53. package/lib/module/SceneMap.js +21 -0
  54. package/lib/module/SceneMap.js.map +1 -0
  55. package/lib/module/SceneView.js +70 -0
  56. package/lib/module/SceneView.js.map +1 -0
  57. package/lib/module/TabBar.js +396 -0
  58. package/lib/module/TabBar.js.map +1 -0
  59. package/lib/module/TabBarIndicator.js +101 -0
  60. package/lib/module/TabBarIndicator.js.map +1 -0
  61. package/lib/module/TabBarItem.js +218 -0
  62. package/lib/module/TabBarItem.js.map +1 -0
  63. package/lib/module/TabView.js +113 -0
  64. package/lib/module/TabView.js.map +1 -0
  65. package/lib/module/index.js +6 -0
  66. package/lib/module/index.js.map +1 -0
  67. package/lib/module/types.js +2 -0
  68. package/lib/module/types.js.map +1 -0
  69. package/lib/module/useAnimatedValue.js +10 -0
  70. package/lib/module/useAnimatedValue.js.map +1 -0
  71. package/lib/typescript/src/Pager.android.d.ts +2 -0
  72. package/lib/typescript/src/Pager.android.d.ts.map +1 -0
  73. package/lib/typescript/src/Pager.d.ts +2 -0
  74. package/lib/typescript/src/Pager.d.ts.map +1 -0
  75. package/lib/typescript/src/Pager.ios.d.ts +2 -0
  76. package/lib/typescript/src/Pager.ios.d.ts.map +1 -0
  77. package/lib/typescript/src/PagerViewAdapter.d.ts +15 -0
  78. package/lib/typescript/src/PagerViewAdapter.d.ts.map +1 -0
  79. package/lib/typescript/src/PanResponderAdapter.d.ts +16 -0
  80. package/lib/typescript/src/PanResponderAdapter.d.ts.map +1 -0
  81. package/lib/typescript/src/PlatformPressable.d.ts +16 -0
  82. package/lib/typescript/src/PlatformPressable.d.ts.map +1 -0
  83. package/lib/typescript/src/SceneMap.d.ts +10 -0
  84. package/lib/typescript/src/SceneMap.d.ts.map +1 -0
  85. package/lib/typescript/src/SceneView.d.ts +16 -0
  86. package/lib/typescript/src/SceneView.d.ts.map +1 -0
  87. package/lib/typescript/src/TabBar.d.ts +44 -0
  88. package/lib/typescript/src/TabBar.d.ts.map +1 -0
  89. package/lib/typescript/src/TabBarIndicator.d.ts +13 -0
  90. package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -0
  91. package/lib/typescript/src/TabBarItem.d.ts +37 -0
  92. package/lib/typescript/src/TabBarItem.d.ts.map +1 -0
  93. package/lib/typescript/src/TabView.d.ts +27 -0
  94. package/lib/typescript/src/TabView.d.ts.map +1 -0
  95. package/lib/typescript/src/index.d.ts +11 -0
  96. package/lib/typescript/src/index.d.ts.map +1 -0
  97. package/lib/typescript/src/types.d.ts +42 -0
  98. package/lib/typescript/src/types.d.ts.map +1 -0
  99. package/lib/typescript/src/useAnimatedValue.d.ts +3 -0
  100. package/lib/typescript/src/useAnimatedValue.d.ts.map +1 -0
  101. package/package.json +1 -0
  102. package/src/Pager.android.tsx +1 -0
  103. package/src/Pager.ios.tsx +1 -0
  104. package/src/Pager.tsx +1 -0
  105. package/src/PagerViewAdapter.tsx +180 -0
  106. package/src/PanResponderAdapter.tsx +340 -0
  107. package/src/PlatformPressable.tsx +42 -0
  108. package/src/SceneMap.tsx +30 -0
  109. package/src/SceneView.tsx +107 -0
  110. package/src/TabBar.tsx +639 -0
  111. package/src/TabBarIndicator.tsx +153 -0
  112. package/src/TabBarItem.tsx +319 -0
  113. package/src/TabView.tsx +155 -0
  114. package/src/index.tsx +10 -0
  115. package/src/types.tsx +59 -0
  116. package/src/useAnimatedValue.tsx +12 -0
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+
3
+ import type { SceneRendererProps } from './types';
4
+
5
+ type SceneProps = {
6
+ route: any;
7
+ } & Omit<SceneRendererProps, 'layout'>;
8
+
9
+ const SceneComponent = React.memo(
10
+ <T extends { component: React.ComponentType<any> } & SceneProps>({
11
+ component,
12
+ ...rest
13
+ }: T) => {
14
+ return React.createElement(component, rest);
15
+ }
16
+ );
17
+
18
+ export default function SceneMap<T extends any>(scenes: {
19
+ [key: string]: React.ComponentType<T>;
20
+ }) {
21
+ return ({ route, jumpTo, position }: SceneProps) => (
22
+ <SceneComponent
23
+ key={route.key}
24
+ component={scenes[route.key]}
25
+ route={route}
26
+ jumpTo={jumpTo}
27
+ position={position}
28
+ />
29
+ );
30
+ }
@@ -0,0 +1,107 @@
1
+ import * as React from 'react';
2
+ import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
3
+
4
+ import type {
5
+ EventEmitterProps,
6
+ NavigationState,
7
+ Route,
8
+ SceneRendererProps,
9
+ } from './types';
10
+
11
+ type Props<T extends Route> = SceneRendererProps &
12
+ EventEmitterProps & {
13
+ navigationState: NavigationState<T>;
14
+ lazy: boolean;
15
+ lazyPreloadDistance: number;
16
+ index: number;
17
+ children: (props: { loading: boolean }) => React.ReactNode;
18
+ style?: StyleProp<ViewStyle>;
19
+ };
20
+
21
+ export default function SceneView<T extends Route>({
22
+ children,
23
+ navigationState,
24
+ lazy,
25
+ layout,
26
+ index,
27
+ lazyPreloadDistance,
28
+ addEnterListener,
29
+ style,
30
+ }: Props<T>) {
31
+ const [isLoading, setIsLoading] = React.useState(
32
+ Math.abs(navigationState.index - index) > lazyPreloadDistance
33
+ );
34
+
35
+ if (
36
+ isLoading &&
37
+ Math.abs(navigationState.index - index) <= lazyPreloadDistance
38
+ ) {
39
+ // Always render the route when it becomes focused
40
+ setIsLoading(false);
41
+ }
42
+
43
+ React.useEffect(() => {
44
+ const handleEnter = (value: number) => {
45
+ // If we're entering the current route, we need to load it
46
+ if (value === index) {
47
+ setIsLoading((prevState) => {
48
+ if (prevState) {
49
+ return false;
50
+ }
51
+ return prevState;
52
+ });
53
+ }
54
+ };
55
+
56
+ let unsubscribe: (() => void) | undefined;
57
+ let timer: NodeJS.Timeout;
58
+
59
+ if (lazy && isLoading) {
60
+ // If lazy mode is enabled, listen to when we enter screens
61
+ unsubscribe = addEnterListener(handleEnter);
62
+ } else if (isLoading) {
63
+ // If lazy mode is not enabled, render the scene with a delay if not loaded already
64
+ // This improves the initial startup time as the scene is no longer blocking
65
+ timer = setTimeout(() => setIsLoading(false), 0);
66
+ }
67
+
68
+ return () => {
69
+ unsubscribe?.();
70
+ clearTimeout(timer);
71
+ };
72
+ }, [addEnterListener, index, isLoading, lazy]);
73
+
74
+ const focused = navigationState.index === index;
75
+
76
+ return (
77
+ <View
78
+ accessibilityElementsHidden={!focused}
79
+ importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
80
+ style={[
81
+ styles.route,
82
+ // If we don't have the layout yet, make the focused screen fill the container
83
+ // This avoids delay before we are able to render pages side by side
84
+ layout.width
85
+ ? { width: layout.width }
86
+ : focused
87
+ ? StyleSheet.absoluteFill
88
+ : null,
89
+ style,
90
+ ]}
91
+ >
92
+ {
93
+ // Only render the route only if it's either focused or layout is available
94
+ // When layout is not available, we must not render unfocused routes
95
+ // so that the focused route can fill the screen
96
+ focused || layout.width ? children({ loading: isLoading }) : null
97
+ }
98
+ </View>
99
+ );
100
+ }
101
+
102
+ const styles = StyleSheet.create({
103
+ route: {
104
+ flex: 1,
105
+ overflow: 'hidden',
106
+ },
107
+ });