@react-navigation/bottom-tabs 8.0.0-alpha.4 → 8.0.0-alpha.41

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 (82) hide show
  1. package/lib/module/index.js +1 -1
  2. package/lib/module/index.js.map +1 -1
  3. package/lib/module/navigators/createBottomTabNavigator.js +4 -25
  4. package/lib/module/navigators/createBottomTabNavigator.js.map +1 -1
  5. package/lib/module/utils/useBottomTabAnimation.js +1 -1
  6. package/lib/module/utils/useBottomTabAnimation.js.map +1 -1
  7. package/lib/module/utils/useBottomTabBarHeight.js +1 -1
  8. package/lib/module/utils/useBottomTabBarHeight.js.map +1 -1
  9. package/lib/module/views/BottomTabBar.js +40 -29
  10. package/lib/module/views/BottomTabBar.js.map +1 -1
  11. package/lib/module/views/BottomTabItem.js +2 -2
  12. package/lib/module/views/BottomTabItem.js.map +1 -1
  13. package/lib/module/views/{BottomTabViewCommon.js → BottomTabView.js} +1 -1
  14. package/lib/module/views/BottomTabView.js.map +1 -0
  15. package/lib/module/views/BottomTabViewCustom.js +90 -71
  16. package/lib/module/views/BottomTabViewCustom.js.map +1 -1
  17. package/lib/module/views/BottomTabViewNativeImpl.js +333 -115
  18. package/lib/module/views/BottomTabViewNativeImpl.js.map +1 -1
  19. package/lib/module/views/Deferred.js +41 -0
  20. package/lib/module/views/Deferred.js.map +1 -0
  21. package/lib/module/views/ScreenContent.js.map +1 -1
  22. package/lib/module/views/TabBarIcon.js +11 -48
  23. package/lib/module/views/TabBarIcon.js.map +1 -1
  24. package/lib/typescript/src/TransitionConfigs/SceneStyleInterpolators.d.ts +1 -1
  25. package/lib/typescript/src/TransitionConfigs/SceneStyleInterpolators.d.ts.map +1 -1
  26. package/lib/typescript/src/TransitionConfigs/TransitionPresets.d.ts +1 -1
  27. package/lib/typescript/src/TransitionConfigs/TransitionPresets.d.ts.map +1 -1
  28. package/lib/typescript/src/TransitionConfigs/TransitionSpecs.d.ts +1 -1
  29. package/lib/typescript/src/TransitionConfigs/TransitionSpecs.d.ts.map +1 -1
  30. package/lib/typescript/src/index.d.ts +11 -11
  31. package/lib/typescript/src/index.d.ts.map +1 -1
  32. package/lib/typescript/src/navigators/createBottomTabNavigator.d.ts +9 -15
  33. package/lib/typescript/src/navigators/createBottomTabNavigator.d.ts.map +1 -1
  34. package/lib/typescript/src/types.d.ts +64 -102
  35. package/lib/typescript/src/types.d.ts.map +1 -1
  36. package/lib/typescript/src/utils/BottomTabAnimationContext.d.ts +1 -1
  37. package/lib/typescript/src/utils/BottomTabAnimationContext.d.ts.map +1 -1
  38. package/lib/typescript/src/utils/useAnimatedHashMap.d.ts +1 -1
  39. package/lib/typescript/src/utils/useAnimatedHashMap.d.ts.map +1 -1
  40. package/lib/typescript/src/utils/useBottomTabAnimation.d.ts +1 -1
  41. package/lib/typescript/src/utils/useBottomTabAnimation.d.ts.map +1 -1
  42. package/lib/typescript/src/utils/useTabBarPosition.d.ts +1 -1
  43. package/lib/typescript/src/utils/useTabBarPosition.d.ts.map +1 -1
  44. package/lib/typescript/src/views/BottomTabBar.d.ts +3 -2
  45. package/lib/typescript/src/views/BottomTabBar.d.ts.map +1 -1
  46. package/lib/typescript/src/views/BottomTabItem.d.ts +20 -20
  47. package/lib/typescript/src/views/BottomTabItem.d.ts.map +1 -1
  48. package/lib/typescript/src/views/{BottomTabViewCommon.d.ts → BottomTabView.d.ts} +3 -3
  49. package/lib/typescript/src/views/BottomTabView.d.ts.map +1 -0
  50. package/lib/typescript/src/views/BottomTabViewCustom.d.ts +3 -2
  51. package/lib/typescript/src/views/BottomTabViewCustom.d.ts.map +1 -1
  52. package/lib/typescript/src/views/BottomTabViewNative.android.d.ts +1 -1
  53. package/lib/typescript/src/views/BottomTabViewNative.android.d.ts.map +1 -1
  54. package/lib/typescript/src/views/BottomTabViewNative.d.ts +1 -1
  55. package/lib/typescript/src/views/BottomTabViewNative.d.ts.map +1 -1
  56. package/lib/typescript/src/views/BottomTabViewNative.ios.d.ts +1 -1
  57. package/lib/typescript/src/views/BottomTabViewNative.ios.d.ts.map +1 -1
  58. package/lib/typescript/src/views/BottomTabViewNativeImpl.d.ts +3 -2
  59. package/lib/typescript/src/views/BottomTabViewNativeImpl.d.ts.map +1 -1
  60. package/lib/typescript/src/views/Deferred.d.ts +31 -0
  61. package/lib/typescript/src/views/Deferred.d.ts.map +1 -0
  62. package/lib/typescript/src/views/ScreenContent.d.ts +4 -4
  63. package/lib/typescript/src/views/ScreenContent.d.ts.map +1 -1
  64. package/lib/typescript/src/views/TabBarIcon.d.ts +8 -8
  65. package/lib/typescript/src/views/TabBarIcon.d.ts.map +1 -1
  66. package/package.json +19 -22
  67. package/src/index.tsx +2 -2
  68. package/src/navigators/createBottomTabNavigator.tsx +10 -75
  69. package/src/types.tsx +64 -110
  70. package/src/utils/useAnimatedHashMap.tsx +1 -1
  71. package/src/utils/useBottomTabAnimation.tsx +1 -1
  72. package/src/utils/useBottomTabBarHeight.tsx +1 -1
  73. package/src/views/BottomTabBar.tsx +68 -25
  74. package/src/views/BottomTabItem.tsx +18 -20
  75. package/src/views/BottomTabViewCustom.tsx +155 -125
  76. package/src/views/BottomTabViewNativeImpl.tsx +470 -155
  77. package/src/views/Deferred.tsx +57 -0
  78. package/src/views/ScreenContent.tsx +1 -2
  79. package/src/views/TabBarIcon.tsx +13 -56
  80. package/lib/module/views/BottomTabViewCommon.js.map +0 -1
  81. package/lib/typescript/src/views/BottomTabViewCommon.d.ts.map +0 -1
  82. /package/src/views/{BottomTabViewCommon.tsx → BottomTabView.tsx} +0 -0
@@ -0,0 +1,57 @@
1
+ import * as React from 'react';
2
+
3
+ type Props = {
4
+ /**
5
+ * Whether lazy rendering is enabled.
6
+ */
7
+ lazy: boolean;
8
+ /**
9
+ * Whether the component is visible.
10
+ */
11
+ visible: boolean;
12
+ /**
13
+ * Content to render.
14
+ */
15
+ children: React.ReactElement;
16
+ };
17
+
18
+ /**
19
+ * Render content lazily based on visibility.
20
+ *
21
+ * When lazy is enabled:
22
+ * - If content is visible, it will render immediately
23
+ * - If content is not visible, it won't render until it becomes visible
24
+ *
25
+ * Otherwise:
26
+ * - If content is visible, it will render immediately
27
+ * - If content is not visible, it will defer rendering
28
+ *
29
+ * Once rendered, the content remains rendered.
30
+ */
31
+ export function Deferred({ lazy, visible, children }: Props) {
32
+ const [rendered, setRendered] = React.useState(lazy ? visible : false);
33
+
34
+ const shouldRenderDeferred = !(lazy || visible || rendered);
35
+
36
+ React.useEffect(() => {
37
+ if (shouldRenderDeferred === false) {
38
+ return;
39
+ }
40
+
41
+ React.startTransition(() => {
42
+ setRendered(true);
43
+ });
44
+ }, [shouldRenderDeferred]);
45
+
46
+ if (visible && rendered === false) {
47
+ setRendered(true);
48
+
49
+ return children;
50
+ }
51
+
52
+ if (rendered) {
53
+ return children;
54
+ }
55
+
56
+ return null;
57
+ }
@@ -2,7 +2,6 @@ import { getHeaderTitle, Header } from '@react-navigation/elements';
2
2
  import { Screen } from '@react-navigation/elements/internal';
3
3
  import type { ParamListBase, Route } from '@react-navigation/native';
4
4
  import * as React from 'react';
5
- import { type StyleProp, type ViewStyle } from 'react-native';
6
5
 
7
6
  import type {
8
7
  BottomTabNavigationOptions,
@@ -21,7 +20,7 @@ export function ScreenContent({
21
20
  route: Route<string>;
22
21
  navigation: BottomTabNavigationProp<ParamListBase>;
23
22
  options: BottomTabNavigationOptions;
24
- style?: StyleProp<ViewStyle>;
23
+ style?: React.ComponentProps<typeof Screen>['style'];
25
24
  children: React.ReactNode;
26
25
  }) {
27
26
  const {
@@ -1,10 +1,9 @@
1
- import { Badge } from '@react-navigation/elements';
1
+ import { Badge, type Icon, PlatformIcon } from '@react-navigation/elements';
2
2
  import { MissingIcon } from '@react-navigation/elements/internal';
3
- import { MaterialSymbol, type Route, SFSymbol } from '@react-navigation/native';
4
- import React from 'react';
3
+ import { type Route } from '@react-navigation/native';
4
+ import * as React from 'react';
5
5
  import {
6
6
  type ColorValue,
7
- Image,
8
7
  type StyleProp,
9
8
  StyleSheet,
10
9
  type TextStyle,
@@ -12,26 +11,24 @@ import {
12
11
  type ViewStyle,
13
12
  } from 'react-native';
14
13
 
15
- import type { BottomTabIcon } from '../types';
16
-
17
14
  export type TabBarIconProps = {
18
15
  route: Route<string>;
19
16
  variant: 'uikit' | 'material';
20
17
  size: 'compact' | 'regular';
21
- badge?: string | number;
22
- badgeStyle?: StyleProp<TextStyle>;
18
+ badge?: string | number | undefined;
19
+ badgeStyle?: StyleProp<TextStyle> | undefined;
23
20
  activeOpacity: number;
24
21
  inactiveOpacity: number;
25
22
  activeTintColor: ColorValue;
26
23
  inactiveTintColor: ColorValue;
27
24
  icon:
28
- | BottomTabIcon
25
+ | Icon
29
26
  | ((props: {
30
27
  focused: boolean;
31
28
  color: ColorValue;
32
29
  size: number;
33
- }) => BottomTabIcon | React.ReactNode);
34
- allowFontScaling?: boolean;
30
+ }) => Icon | React.ReactNode);
31
+ allowFontScaling?: boolean | undefined;
35
32
  style: StyleProp<ViewStyle>;
36
33
  };
37
34
 
@@ -43,8 +40,8 @@ const ICON_SIZE_WIDE = 31;
43
40
  const ICON_SIZE_WIDE_COMPACT = 23;
44
41
  const ICON_SIZE_TALL = 28;
45
42
  const ICON_SIZE_TALL_COMPACT = 20;
46
- const ICON_SIZE_ROUND = 25;
47
- const ICON_SIZE_ROUND_COMPACT = 18;
43
+ const ICON_SIZE_SQUARE = 23;
44
+ const ICON_SIZE_SQUARE_COMPACT = 17;
48
45
  const ICON_SIZE_MATERIAL = 24;
49
46
 
50
47
  export function TabBarIcon({
@@ -65,8 +62,8 @@ export function TabBarIcon({
65
62
  variant === 'material'
66
63
  ? ICON_SIZE_MATERIAL
67
64
  : size === 'compact'
68
- ? ICON_SIZE_ROUND_COMPACT
69
- : ICON_SIZE_ROUND;
65
+ ? ICON_SIZE_SQUARE_COMPACT
66
+ : ICON_SIZE_SQUARE;
70
67
 
71
68
  // We render the icon twice at the same position on top of each other:
72
69
  // active and inactive one, so we can fade between them.
@@ -141,47 +138,7 @@ function renderIcon({
141
138
  iconValue != null &&
142
139
  'type' in iconValue
143
140
  ) {
144
- switch (iconValue.type) {
145
- case 'image':
146
- return (
147
- <Image
148
- source={iconValue.source}
149
- style={{
150
- width: size,
151
- height: size,
152
- tintColor: iconValue.tinted === false ? undefined : color,
153
- }}
154
- />
155
- );
156
- case 'resource':
157
- return (
158
- <Image
159
- source={{ uri: iconValue.name }}
160
- style={{
161
- width: size,
162
- height: size,
163
- tintColor: iconValue.tinted === false ? undefined : color,
164
- }}
165
- />
166
- );
167
- case 'sfSymbol':
168
- return <SFSymbol name={iconValue.name} size={size} color={color} />;
169
- case 'materialSymbol':
170
- return (
171
- <MaterialSymbol
172
- name={iconValue.name}
173
- variant={iconValue.variant}
174
- weight={iconValue.weight}
175
- size={size}
176
- color={color}
177
- />
178
- );
179
- default: {
180
- const _exhaustiveCheck: never = iconValue;
181
-
182
- return _exhaustiveCheck;
183
- }
184
- }
141
+ return <PlatformIcon icon={iconValue} size={size} color={color} />;
185
142
  }
186
143
 
187
144
  return <MissingIcon color={color} size={size} />;
@@ -1 +0,0 @@
1
- {"version":3,"names":["BottomTabViewCustom","BottomTabViewNative","jsx","_jsx","BottomTabView","props","implementation"],"sourceRoot":"../../../src","sources":["views/BottomTabViewCommon.tsx"],"mappings":";;AAUA,SAASA,mBAAmB,QAAQ,0BAAuB;AAC3D,SAASC,mBAAmB,QAAQ,uBAAuB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAQ5D,OAAO,SAASC,aAAaA,CAACC,KAAY,EAAE;EAC1C,IAAIA,KAAK,CAACC,cAAc,KAAK,QAAQ,EAAE;IACrC,oBAAOH,IAAA,CAACH,mBAAmB;MAAA,GAAKK;IAAK,CAAG,CAAC;EAC3C;EAEA,oBAAOF,IAAA,CAACF,mBAAmB;IAAA,GAAKI;EAAK,CAAG,CAAC;AAC3C","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"BottomTabViewCommon.d.ts","sourceRoot":"","sources":["../../../../src/views/BottomTabViewCommon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EACV,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC3B,MAAM,UAAU,CAAC;AAIlB,KAAK,KAAK,GAAG,yBAAyB,GAAG;IACvC,KAAK,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;IACzC,UAAU,EAAE,0BAA0B,CAAC;IACvC,WAAW,EAAE,sBAAsB,CAAC;CACrC,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,2CAMzC"}