react-native-tab-view 4.0.0-rc.9 → 4.0.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 (34) hide show
  1. package/lib/commonjs/PlatformPressable.js +8 -8
  2. package/lib/commonjs/PlatformPressable.js.map +1 -1
  3. package/lib/commonjs/SceneView.js.map +1 -1
  4. package/lib/commonjs/TabBar.js +8 -10
  5. package/lib/commonjs/TabBar.js.map +1 -1
  6. package/lib/commonjs/TabView.js +13 -3
  7. package/lib/commonjs/TabView.js.map +1 -1
  8. package/lib/module/PlatformPressable.js +8 -8
  9. package/lib/module/PlatformPressable.js.map +1 -1
  10. package/lib/module/SceneView.js.map +1 -1
  11. package/lib/module/TabBar.js +7 -9
  12. package/lib/module/TabBar.js.map +1 -1
  13. package/lib/module/TabView.js +13 -3
  14. package/lib/module/TabView.js.map +1 -1
  15. package/lib/typescript/commonjs/src/TabBar.d.ts +1 -2
  16. package/lib/typescript/commonjs/src/TabBar.d.ts.map +1 -1
  17. package/lib/typescript/commonjs/src/TabView.d.ts +5 -3
  18. package/lib/typescript/commonjs/src/TabView.d.ts.map +1 -1
  19. package/lib/typescript/commonjs/src/types.d.ts +2 -1
  20. package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
  21. package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
  22. package/lib/typescript/module/src/TabBar.d.ts +1 -2
  23. package/lib/typescript/module/src/TabBar.d.ts.map +1 -1
  24. package/lib/typescript/module/src/TabView.d.ts +5 -3
  25. package/lib/typescript/module/src/TabView.d.ts.map +1 -1
  26. package/lib/typescript/module/src/types.d.ts +2 -1
  27. package/lib/typescript/module/src/types.d.ts.map +1 -1
  28. package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
  29. package/package.json +6 -4
  30. package/src/PlatformPressable.tsx +8 -8
  31. package/src/SceneView.tsx +1 -1
  32. package/src/TabBar.tsx +2 -8
  33. package/src/TabView.tsx +24 -4
  34. package/src/types.tsx +2 -1
package/src/TabView.tsx CHANGED
@@ -19,6 +19,7 @@ import type {
19
19
  PagerProps,
20
20
  Route,
21
21
  SceneRendererProps,
22
+ TabDescriptor,
22
23
  } from './types';
23
24
 
24
25
  export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
@@ -26,17 +27,21 @@ export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
26
27
  navigationState: NavigationState<T>;
27
28
  renderLazyPlaceholder?: (props: { route: T }) => React.ReactNode;
28
29
  renderTabBar?: (
29
- props: SceneRendererProps & { navigationState: NavigationState<T> }
30
+ props: SceneRendererProps & {
31
+ navigationState: NavigationState<T>;
32
+ options: Record<string, TabDescriptor<T>> | undefined;
33
+ }
30
34
  ) => React.ReactNode;
31
35
  tabBarPosition?: 'top' | 'bottom';
32
36
  initialLayout?: Partial<Layout>;
33
37
  lazy?: ((props: { route: T }) => boolean) | boolean;
34
38
  lazyPreloadDistance?: number;
35
- sceneContainerStyle?: StyleProp<ViewStyle>;
36
39
  direction?: LocaleDirection;
37
40
  pagerStyle?: StyleProp<ViewStyle>;
38
41
  style?: StyleProp<ViewStyle>;
39
42
  renderScene: (props: SceneRendererProps & { route: T }) => React.ReactNode;
43
+ options?: Record<string, TabDescriptor<T>>;
44
+ commonOptions?: TabDescriptor<T>;
40
45
  };
41
46
 
42
47
  const renderLazyPlaceholderDefault = () => null;
@@ -54,7 +59,6 @@ export function TabView<T extends Route>({
54
59
  renderLazyPlaceholder = renderLazyPlaceholderDefault,
55
60
  // eslint-disable-next-line @eslint-react/no-unstable-default-props
56
61
  renderTabBar = (props) => <TabBar {...props} />,
57
- sceneContainerStyle,
58
62
  pagerStyle,
59
63
  style,
60
64
  direction = I18nManager.getConstants().isRTL ? 'rtl' : 'ltr',
@@ -62,6 +66,8 @@ export function TabView<T extends Route>({
62
66
  tabBarPosition = 'top',
63
67
  animationEnabled = true,
64
68
  overScrollMode,
69
+ options: sceneOptions,
70
+ commonOptions,
65
71
  }: Props<T>) {
66
72
  if (
67
73
  Platform.OS !== 'web' &&
@@ -98,6 +104,16 @@ export function TabView<T extends Route>({
98
104
  });
99
105
  };
100
106
 
107
+ const options = Object.fromEntries(
108
+ navigationState.routes.map((route) => [
109
+ route.key,
110
+ {
111
+ ...commonOptions,
112
+ ...sceneOptions?.[route.key],
113
+ },
114
+ ])
115
+ );
116
+
101
117
  return (
102
118
  <View onLayout={handleLayout} style={[styles.pager, style]}>
103
119
  <Pager
@@ -127,10 +143,13 @@ export function TabView<T extends Route>({
127
143
  {tabBarPosition === 'top' &&
128
144
  renderTabBar({
129
145
  ...sceneRendererProps,
146
+ options,
130
147
  navigationState,
131
148
  })}
132
149
  {render(
133
150
  navigationState.routes.map((route, i) => {
151
+ const { sceneStyle } = options?.[route.key] ?? {};
152
+
134
153
  return (
135
154
  <SceneView
136
155
  {...sceneRendererProps}
@@ -140,7 +159,7 @@ export function TabView<T extends Route>({
140
159
  lazy={typeof lazy === 'function' ? lazy({ route }) : lazy}
141
160
  lazyPreloadDistance={lazyPreloadDistance}
142
161
  navigationState={navigationState}
143
- style={sceneContainerStyle}
162
+ style={sceneStyle}
144
163
  >
145
164
  {({ loading }) =>
146
165
  loading
@@ -157,6 +176,7 @@ export function TabView<T extends Route>({
157
176
  {tabBarPosition === 'bottom' &&
158
177
  renderTabBar({
159
178
  ...sceneRendererProps,
179
+ options,
160
180
  navigationState,
161
181
  })}
162
182
  </React.Fragment>
package/src/types.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import type { Animated, StyleProp, TextStyle } 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
4
  export type TabDescriptor<T extends Route> = {
@@ -23,6 +23,7 @@ export type TabDescriptor<T extends Route> = {
23
23
  size: number;
24
24
  }) => React.ReactElement;
25
25
  badge?: (props: { route: T }) => React.ReactElement;
26
+ sceneStyle?: StyleProp<ViewStyle>;
26
27
  };
27
28
 
28
29
  export type LocaleDirection = 'ltr' | 'rtl';