react-native-tab-view 4.2.1 → 5.0.0-alpha.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 (70) hide show
  1. package/lib/module/Pager.android.js +1 -1
  2. package/lib/module/Pager.android.js.map +1 -1
  3. package/lib/module/Pager.ios.js +1 -1
  4. package/lib/module/Pager.ios.js.map +1 -1
  5. package/lib/module/PagerViewAdapter.js +3 -127
  6. package/lib/module/PagerViewAdapter.js.map +1 -1
  7. package/lib/module/PagerViewAdapter.native.js +130 -0
  8. package/lib/module/PagerViewAdapter.native.js.map +1 -0
  9. package/lib/module/PanResponderAdapter.js +43 -31
  10. package/lib/module/PanResponderAdapter.js.map +1 -1
  11. package/lib/module/PlatformPressable.js.map +1 -1
  12. package/lib/module/SceneView.js +22 -31
  13. package/lib/module/SceneView.js.map +1 -1
  14. package/lib/module/ScrollViewAdapter.js +210 -0
  15. package/lib/module/ScrollViewAdapter.js.map +1 -0
  16. package/lib/module/TabBar.js +98 -61
  17. package/lib/module/TabBar.js.map +1 -1
  18. package/lib/module/TabBarIndicator.js +6 -9
  19. package/lib/module/TabBarIndicator.js.map +1 -1
  20. package/lib/module/TabBarItem.js +4 -4
  21. package/lib/module/TabBarItem.js.map +1 -1
  22. package/lib/module/TabView.js +65 -84
  23. package/lib/module/TabView.js.map +1 -1
  24. package/lib/module/index.js +3 -0
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/useMeasureLayout.js +36 -0
  27. package/lib/module/useMeasureLayout.js.map +1 -0
  28. package/lib/typescript/src/PagerViewAdapter.d.ts +3 -17
  29. package/lib/typescript/src/PagerViewAdapter.d.ts.map +1 -1
  30. package/lib/typescript/src/PagerViewAdapter.native.d.ts +6 -0
  31. package/lib/typescript/src/PagerViewAdapter.native.d.ts.map +1 -0
  32. package/lib/typescript/src/PanResponderAdapter.d.ts +3 -17
  33. package/lib/typescript/src/PanResponderAdapter.d.ts.map +1 -1
  34. package/lib/typescript/src/PlatformPressable.d.ts +2 -2
  35. package/lib/typescript/src/PlatformPressable.d.ts.map +1 -1
  36. package/lib/typescript/src/SceneView.d.ts +1 -1
  37. package/lib/typescript/src/SceneView.d.ts.map +1 -1
  38. package/lib/typescript/src/ScrollViewAdapter.d.ts +12 -0
  39. package/lib/typescript/src/ScrollViewAdapter.d.ts.map +1 -0
  40. package/lib/typescript/src/TabBar.d.ts +7 -7
  41. package/lib/typescript/src/TabBar.d.ts.map +1 -1
  42. package/lib/typescript/src/TabBarIndicator.d.ts +1 -1
  43. package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -1
  44. package/lib/typescript/src/TabBarItem.d.ts +4 -4
  45. package/lib/typescript/src/TabBarItem.d.ts.map +1 -1
  46. package/lib/typescript/src/TabBarItemLabel.d.ts +2 -2
  47. package/lib/typescript/src/TabBarItemLabel.d.ts.map +1 -1
  48. package/lib/typescript/src/TabView.d.ts +5 -5
  49. package/lib/typescript/src/TabView.d.ts.map +1 -1
  50. package/lib/typescript/src/index.d.ts +4 -1
  51. package/lib/typescript/src/index.d.ts.map +1 -1
  52. package/lib/typescript/src/types.d.ts +64 -8
  53. package/lib/typescript/src/types.d.ts.map +1 -1
  54. package/lib/typescript/src/useMeasureLayout.d.ts +5 -0
  55. package/lib/typescript/src/useMeasureLayout.d.ts.map +1 -0
  56. package/package.json +11 -11
  57. package/src/PagerViewAdapter.native.tsx +174 -0
  58. package/src/PagerViewAdapter.tsx +8 -181
  59. package/src/PanResponderAdapter.tsx +64 -77
  60. package/src/PlatformPressable.tsx +2 -1
  61. package/src/SceneView.tsx +23 -45
  62. package/src/ScrollViewAdapter.tsx +268 -0
  63. package/src/TabBar.tsx +134 -133
  64. package/src/TabBarIndicator.tsx +7 -11
  65. package/src/TabBarItem.tsx +8 -6
  66. package/src/TabBarItemLabel.tsx +2 -2
  67. package/src/TabView.tsx +79 -100
  68. package/src/index.tsx +10 -0
  69. package/src/types.tsx +75 -17
  70. package/src/useMeasureLayout.tsx +34 -0
@@ -1,12 +1,12 @@
1
- import { Animated, type LayoutChangeEvent, type PressableAndroidRippleConfig, type StyleProp, type ViewStyle } from 'react-native';
1
+ import { Animated, type ColorValue, type LayoutChangeEvent, type PressableAndroidRippleConfig, type StyleProp, type ViewStyle } from 'react-native';
2
2
  import type { NavigationState, Route, TabDescriptor } from './types';
3
3
  export type Props<T extends Route> = TabDescriptor<T> & {
4
4
  position: Animated.AnimatedInterpolation<number>;
5
5
  route: T;
6
6
  navigationState: NavigationState<T>;
7
- activeColor?: string;
8
- inactiveColor?: string;
9
- pressColor?: string;
7
+ activeColor?: ColorValue;
8
+ inactiveColor?: ColorValue;
9
+ pressColor?: ColorValue;
10
10
  pressOpacity?: number;
11
11
  onLayout?: (event: LayoutChangeEvent) => void;
12
12
  onPress: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"TabBarItem.d.ts","sourceRoot":"","sources":["../../../src/TabBarItem.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,KAAK,iBAAiB,EAEtB,KAAK,4BAA4B,EACjC,KAAK,SAAS,EAGd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAErE,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,IAAI,aAAa,CAAC,CAAC,CAAC,GAAG;IACtD,QAAQ,EAAE,QAAQ,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACjD,KAAK,EAAE,CAAC,CAAC;IACT,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC9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AA4B,CAAC;CAC/C,CAAC;AA+NF,wBAAgB,UAAU,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,2CAsB1D"}
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import type { StyleProp, ViewStyle } from 'react-native';
2
+ import type { ColorValue, StyleProp, ViewStyle } from 'react-native';
3
3
  interface TabBarItemLabelProps {
4
- color: string;
4
+ color: ColorValue;
5
5
  label?: string;
6
6
  style: StyleProp<ViewStyle>;
7
7
  icon: React.ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"TabBarItemLabel.d.ts","sourceRoot":"","sources":["../../../src/TabBarItemLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzD,UAAU,oBAAoB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,eAAe,4DACM,oBAAoB,oDAkBrD,CAAC"}
1
+ {"version":3,"file":"TabBarItemLabel.d.ts","sourceRoot":"","sources":["../../../src/TabBarItemLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGrE,UAAU,oBAAoB;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,eAAe,4DACM,oBAAoB,oDAkBrD,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { type StyleProp, type ViewStyle } from 'react-native';
3
- import type { Layout, LocaleDirection, NavigationState, PagerProps, Route, SceneRendererProps, TabDescriptor } from './types';
4
- export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
3
+ import type { AdapterCommonProps, AdapterProps, EventEmitterProps, LocaleDirection, NavigationState, Route, SceneRendererProps, TabDescriptor } from './types';
4
+ export type Props<T extends Route> = AdapterCommonProps & {
5
5
  onIndexChange: (index: number) => void;
6
6
  onTabSelect?: (props: {
7
7
  index: number;
@@ -10,12 +10,12 @@ export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
10
10
  renderLazyPlaceholder?: (props: {
11
11
  route: T;
12
12
  }) => React.ReactNode;
13
- renderTabBar?: (props: SceneRendererProps & {
13
+ renderTabBar?: (props: SceneRendererProps & EventEmitterProps & {
14
14
  navigationState: NavigationState<T>;
15
15
  options: Record<string, TabDescriptor<T>> | undefined;
16
16
  }) => React.ReactNode;
17
+ renderAdapter?: (props: AdapterProps) => React.ReactElement;
17
18
  tabBarPosition?: 'top' | 'bottom';
18
- initialLayout?: Partial<Layout>;
19
19
  lazy?: ((props: {
20
20
  route: T;
21
21
  }) => boolean) | boolean;
@@ -29,5 +29,5 @@ export type Props<T extends Route> = Omit<PagerProps, 'layoutDirection'> & {
29
29
  options?: Record<string, TabDescriptor<T>>;
30
30
  commonOptions?: TabDescriptor<T>;
31
31
  };
32
- export declare function TabView<T extends Route>({ onIndexChange, onTabSelect, navigationState, renderScene, initialLayout, keyboardDismissMode, lazy, lazyPreloadDistance, onSwipeStart, onSwipeEnd, renderLazyPlaceholder, renderTabBar, pagerStyle, style, direction, swipeEnabled, tabBarPosition, animationEnabled, overScrollMode, options: sceneOptions, commonOptions, }: Props<T>): import("react/jsx-runtime").JSX.Element;
32
+ export declare function TabView<T extends Route>({ onIndexChange, onTabSelect, navigationState, renderScene, keyboardDismissMode, lazy, lazyPreloadDistance, onSwipeStart, onSwipeEnd, renderLazyPlaceholder, renderTabBar, renderAdapter, pagerStyle, style, direction, swipeEnabled, tabBarPosition, animationEnabled, options: sceneOptions, commonOptions, }: Props<T>): import("react/jsx-runtime").JSX.Element;
33
33
  //# sourceMappingURL=TabView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TabView.d.ts","sourceRoot":"","sources":["../../../src/TabView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAIL,KAAK,SAAS,EAGd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAKtB,OAAO,KAAK,EACV,MAAM,EACN,eAAe,EACf,eAAe,EACf,UAAU,EACV,KAAK,EACL,kBAAkB,EAClB,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,GAAG;IACzE,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACjD,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACpC,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,CAAC,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,CAAC;IACjE,YAAY,CAAC,EAAE,CACb,KAAK,EAAE,kBAAkB,GAAG;QAC1B,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;QACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;KACvD,KACE,KAAK,CAAC,SAAS,CAAC;IACrB,cAAc,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAClC,aAAa,CAAC,EAAE,OAAO,CAAC,MA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CAAC;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;CAClC,CAAC;AAIF,wBAAgB,OAAO,CAAC,CAAC,SAAS,KAAK,EAAE,EACvC,aAAa,EACb,WAAW,EACX,eAAe,EACf,WAAW,EACX,mBAA4B,EAC5B,IAAY,EACZ,mBAAuB,EACvB,YAAY,EACZ,UAAU,EACV,qBAAoD,EAEpD,YAA+C,EAE/C,aAA+C,EAC/C,UAAU,EACV,KAAK,EACL,SAA4D,EAC5D,YAAmB,EACnB,cAAsB,EACtB,gBAAuB,EACvB,OAAO,EAAE,YAAY,EACrB,aAAa,GACd,EAAE,KAAK,CAAC,CAAC,CAAC,2CAgGV"}
@@ -1,4 +1,7 @@
1
+ export { PagerViewAdapter, type PagerViewAdapterProps, } from './PagerViewAdapter';
2
+ export { PanResponderAdapter } from './PanResponderAdapter';
1
3
  export { SceneMap } from './SceneMap';
4
+ export { ScrollViewAdapter, type ScrollViewAdapterProps, } from './ScrollViewAdapter';
2
5
  export type { Props as TabBarProps } from './TabBar';
3
6
  export { TabBar } from './TabBar';
4
7
  export type { Props as TabBarIndicatorProps } from './TabBarIndicator';
@@ -7,5 +10,5 @@ export type { Props as TabBarItemProps } from './TabBarItem';
7
10
  export { TabBarItem } from './TabBarItem';
8
11
  export type { Props as TabViewProps } from './TabView';
9
12
  export { TabView } from './TabView';
10
- export type { NavigationState, Route, SceneRendererProps, TabDescriptor, } from './types';
13
+ export type { AdapterProps, NavigationState, Route, SceneRendererProps, TabDescriptor, } from './types';
11
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,KAAK,IAAI,WAA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,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,YAAY,EACZ,eAAe,EACf,KAAK,EACL,kBAAkB,EAClB,aAAa,GACd,MAAM,SAAS,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { Animated, StyleProp, TextStyle, ViewStyle } from 'react-native';
2
- import type { PagerViewProps } from 'react-native-pager-view';
1
+ import * as React from 'react';
2
+ import type { Animated, ColorValue, StyleProp, TextStyle, ViewStyle } from 'react-native';
3
3
  export type TabDescriptor<T extends Route> = {
4
4
  accessibilityLabel?: string;
5
5
  accessible?: boolean;
@@ -11,7 +11,7 @@ export type TabDescriptor<T extends Route> = {
11
11
  route: T;
12
12
  labelText?: string;
13
13
  focused: boolean;
14
- color: string;
14
+ color: ColorValue;
15
15
  allowFontScaling?: boolean;
16
16
  style?: StyleProp<TextStyle>;
17
17
  }) => React.ReactNode;
@@ -19,7 +19,7 @@ export type TabDescriptor<T extends Route> = {
19
19
  icon?: (props: {
20
20
  route: T;
21
21
  focused: boolean;
22
- color: string;
22
+ color: ColorValue;
23
23
  size: number;
24
24
  }) => React.ReactNode;
25
25
  badge?: (props: {
@@ -51,20 +51,76 @@ export type Layout = {
51
51
  width: number;
52
52
  height: number;
53
53
  };
54
- export type Listener = (value: number) => void;
54
+ export type Listener = (event: {
55
+ type: 'enter';
56
+ index: number;
57
+ }) => void;
55
58
  export type SceneRendererProps = {
56
- layout: Layout;
57
59
  position: Animated.AnimatedInterpolation<number>;
58
60
  jumpTo: (key: string) => void;
59
61
  };
60
62
  export type EventEmitterProps = {
61
- addEnterListener: (listener: Listener) => () => void;
63
+ subscribe: (listener: Listener) => () => void;
62
64
  };
63
- export type PagerProps = Omit<PagerViewProps, 'initialPage' | 'scrollEnabled' | 'onPageScroll' | 'onPageSelected' | 'onPageScrollStateChanged' | 'keyboardDismissMode' | 'children'> & {
65
+ export type AdapterCommonProps = {
66
+ /**
67
+ * Determines whether the keyboard gets dismissed in response to a drag.
68
+ * - 'auto' (default) - the keyboard is dismissed on drag and tab changes
69
+ * - 'on-drag' - the keyboard is dismissed when a drag begins
70
+ * - 'none' - drags and tab changes do not dismiss the keyboard
71
+ */
64
72
  keyboardDismissMode?: 'none' | 'on-drag' | 'auto';
73
+ /**
74
+ * Whether swiping between tabs is enabled.
75
+ */
65
76
  swipeEnabled?: boolean;
77
+ /**
78
+ * Whether the tab switch animation is enabled.
79
+ * If set to false, the tab switch will happen immediately without animation.
80
+ */
66
81
  animationEnabled?: boolean;
82
+ /**
83
+ * Callback that is called when the swipe gesture starts.
84
+ */
67
85
  onSwipeStart?: () => void;
86
+ /**
87
+ * Callback that is called when the swipe gesture ends.
88
+ */
68
89
  onSwipeEnd?: () => void;
90
+ /**
91
+ * Callback that is called when a tab is selected.
92
+ * This is called regardless of whether the index has changed or not.
93
+ */
94
+ onTabSelect?: (props: {
95
+ index: number;
96
+ }) => void;
97
+ /**
98
+ * Style for the pager adapter.
99
+ */
100
+ style?: StyleProp<ViewStyle>;
101
+ };
102
+ export type AdapterRendererProps = {
103
+ /**
104
+ * Callback to call when the index changes.
105
+ */
106
+ onIndexChange: (index: number) => void;
107
+ /**
108
+ * The current navigation state of the tab view.
109
+ */
110
+ navigationState: NavigationState<Route>;
111
+ /**
112
+ * The writing direction of the layout.
113
+ * This can be 'ltr' or 'rtl' based on tab view's `direction` prop.
114
+ */
115
+ layoutDirection?: LocaleDirection;
116
+ /**
117
+ * Render callback that should render the pages of the tab view.
118
+ */
119
+ children: (props: EventEmitterProps & {
120
+ position: Animated.AnimatedInterpolation<number>;
121
+ render: (children: React.ReactElement[]) => React.ReactNode;
122
+ jumpTo: (key: string) => void;
123
+ }) => React.ReactElement;
69
124
  };
125
+ export type AdapterProps = AdapterRendererProps & AdapterCommonProps;
70
126
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EA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angeEvent, type View } from 'react-native';
3
+ import type { Layout } from './types';
4
+ export declare function useMeasureLayout(ref: React.RefObject<View | null>, onMeasure?: (layout: Layout) => void): readonly [Layout, (event: LayoutChangeEvent) => void];
5
+ //# sourceMappingURL=useMeasureLayout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useMeasureLayout.d.ts","sourceRoot":"","sources":["../../../src/useMeasureLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,IAAI,EAAE,MAAM,cAAc,CAAC;AAGjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,EACjC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,6BAoBO,iBAAiB,WAK7D"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-tab-view",
3
3
  "description": "Tab view component for React Native",
4
- "version": "4.2.1",
4
+ "version": "5.0.0-alpha.0",
5
5
  "keywords": [
6
6
  "react-native-component",
7
7
  "react-component",
@@ -44,23 +44,23 @@
44
44
  "clean": "del lib"
45
45
  },
46
46
  "dependencies": {
47
- "use-latest-callback": "^0.2.4"
47
+ "use-latest-callback": "^0.3.2"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@jest/globals": "^30.0.0",
51
- "@testing-library/react-native": "^13.2.0",
51
+ "@testing-library/react-native": "^13.2.1",
52
52
  "del-cli": "^6.0.0",
53
- "react": "19.0.0",
54
- "react-native": "0.79.3",
53
+ "react": "19.1.0",
54
+ "react-native": "0.81.4",
55
55
  "react-native-builder-bob": "^0.40.12",
56
- "react-native-pager-view": "6.8.1",
57
- "react-test-renderer": "19.0.0",
58
- "typescript": "^5.8.3"
56
+ "react-native-pager-view": "^8.0.0",
57
+ "react-test-renderer": "19.1.0",
58
+ "typescript": "^5.9.2"
59
59
  },
60
60
  "peerDependencies": {
61
- "react": ">= 18.2.0",
61
+ "react": ">= 19.0.0",
62
62
  "react-native": "*",
63
- "react-native-pager-view": ">= 6.0.0"
63
+ "react-native-pager-view": ">= 7.0.0"
64
64
  },
65
65
  "react-native-builder-bob": {
66
66
  "source": "src",
@@ -80,5 +80,5 @@
80
80
  ]
81
81
  ]
82
82
  },
83
- "gitHead": "64c92e064652e38fce292ff26ec7d613aa33b040"
83
+ "gitHead": "46daae524ec6a59737147ed506222dd09a5b6e39"
84
84
  }
@@ -0,0 +1,174 @@
1
+ import * as React from 'react';
2
+ import { Animated, Keyboard, Platform, StyleSheet } from 'react-native';
3
+ import ViewPager, {
4
+ type PagerViewProps,
5
+ type PageScrollStateChangedNativeEvent,
6
+ } from 'react-native-pager-view';
7
+ import useLatestCallback from 'use-latest-callback';
8
+
9
+ import type { AdapterProps, Listener } from './types';
10
+ import { useAnimatedValue } from './useAnimatedValue';
11
+
12
+ const AnimatedViewPager = Animated.createAnimatedComponent(ViewPager);
13
+
14
+ export type PagerViewAdapterProps = AdapterProps &
15
+ Omit<
16
+ PagerViewProps,
17
+ | keyof AdapterProps
18
+ | 'initialPage'
19
+ | 'scrollEnabled'
20
+ | 'onPageScroll'
21
+ | 'onPageSelected'
22
+ | 'onPageScrollStateChanged'
23
+ | 'children'
24
+ >;
25
+
26
+ const useNativeDriver = Platform.OS !== 'web';
27
+
28
+ export function PagerViewAdapter({
29
+ keyboardDismissMode = 'auto',
30
+ swipeEnabled = true,
31
+ navigationState,
32
+ onIndexChange,
33
+ onTabSelect,
34
+ onSwipeStart,
35
+ onSwipeEnd,
36
+ children,
37
+ style,
38
+ animationEnabled,
39
+ ...rest
40
+ }: PagerViewAdapterProps) {
41
+ const { index } = navigationState;
42
+
43
+ const listeners = React.useRef<Set<Listener>>(new Set()).current;
44
+
45
+ const pagerRef = React.useRef<ViewPager>(null);
46
+ const indexRef = React.useRef<number>(index);
47
+ const navigationStateRef = React.useRef(navigationState);
48
+
49
+ const position = useAnimatedValue(index);
50
+ const offset = useAnimatedValue(0);
51
+
52
+ React.useEffect(() => {
53
+ navigationStateRef.current = navigationState;
54
+ });
55
+
56
+ const jumpTo = useLatestCallback((key: string) => {
57
+ const index = navigationStateRef.current.routes.findIndex(
58
+ (route: { key: string }) => route.key === key
59
+ );
60
+
61
+ if (animationEnabled) {
62
+ pagerRef.current?.setPage(index);
63
+ } else {
64
+ pagerRef.current?.setPageWithoutAnimation(index);
65
+ position.setValue(index);
66
+ }
67
+
68
+ onIndexChange(index);
69
+ });
70
+
71
+ React.useEffect(() => {
72
+ if (keyboardDismissMode === 'auto') {
73
+ Keyboard.dismiss();
74
+ }
75
+
76
+ if (indexRef.current !== index) {
77
+ if (animationEnabled) {
78
+ pagerRef.current?.setPage(index);
79
+ } else {
80
+ pagerRef.current?.setPageWithoutAnimation(index);
81
+ position.setValue(index);
82
+ }
83
+ }
84
+ }, [keyboardDismissMode, index, animationEnabled, position]);
85
+
86
+ const onPageScrollStateChanged = (
87
+ state: PageScrollStateChangedNativeEvent
88
+ ) => {
89
+ const { pageScrollState } = state.nativeEvent;
90
+
91
+ switch (pageScrollState) {
92
+ case 'idle':
93
+ onSwipeEnd?.();
94
+ return;
95
+ case 'dragging': {
96
+ const subscription = offset.addListener(({ value }) => {
97
+ const next =
98
+ index + (value > 0 ? Math.ceil(value) : Math.floor(value));
99
+
100
+ if (next !== index) {
101
+ listeners.forEach((listener) =>
102
+ listener({
103
+ type: 'enter',
104
+ index: next,
105
+ })
106
+ );
107
+ }
108
+
109
+ offset.removeListener(subscription);
110
+ });
111
+
112
+ onSwipeStart?.();
113
+ return;
114
+ }
115
+ }
116
+ };
117
+
118
+ const subscribe = useLatestCallback((listener: Listener) => {
119
+ listeners.add(listener);
120
+
121
+ return () => {
122
+ listeners.delete(listener);
123
+ };
124
+ });
125
+
126
+ const memoizedPosition = React.useMemo(
127
+ () => Animated.add(position, offset),
128
+ [offset, position]
129
+ );
130
+
131
+ return children({
132
+ position: memoizedPosition,
133
+ subscribe,
134
+ jumpTo,
135
+ render: (children) => (
136
+ <AnimatedViewPager
137
+ {...rest}
138
+ ref={pagerRef}
139
+ style={[styles.container, style]}
140
+ initialPage={index}
141
+ keyboardDismissMode={
142
+ keyboardDismissMode === 'auto' ? 'on-drag' : keyboardDismissMode
143
+ }
144
+ onPageScroll={Animated.event(
145
+ [
146
+ {
147
+ nativeEvent: {
148
+ position: position,
149
+ offset: offset,
150
+ },
151
+ },
152
+ ],
153
+ { useNativeDriver }
154
+ )}
155
+ onPageSelected={(e) => {
156
+ const index = e.nativeEvent.position;
157
+ indexRef.current = index;
158
+ onIndexChange(index);
159
+ onTabSelect?.({ index });
160
+ }}
161
+ onPageScrollStateChanged={onPageScrollStateChanged}
162
+ scrollEnabled={swipeEnabled}
163
+ >
164
+ {children}
165
+ </AnimatedViewPager>
166
+ ),
167
+ });
168
+ }
169
+
170
+ const styles = StyleSheet.create({
171
+ container: {
172
+ flex: 1,
173
+ },
174
+ });
@@ -1,185 +1,12 @@
1
- import * as React from 'react';
2
- import { Animated, Keyboard, Platform, StyleSheet } from 'react-native';
3
- import ViewPager, {
4
- type PageScrollStateChangedNativeEvent,
5
- } from 'react-native-pager-view';
6
- import useLatestCallback from 'use-latest-callback';
7
-
8
1
  import type {
9
- EventEmitterProps,
10
- Listener,
11
- NavigationState,
12
- PagerProps,
13
- Route,
14
- } from './types';
15
- import { useAnimatedValue } from './useAnimatedValue';
16
-
17
- const AnimatedViewPager = Animated.createAnimatedComponent(ViewPager);
18
-
19
- type Props<T extends Route> = PagerProps & {
20
- onIndexChange: (index: number) => void;
21
- onTabSelect?: (props: { index: number }) => void;
22
- navigationState: NavigationState<T>;
23
- children: (
24
- props: EventEmitterProps & {
25
- // Animated value which represents the state of current index
26
- // It can include fractional digits as it represents the intermediate value
27
- position: Animated.AnimatedInterpolation<number>;
28
- // Function to actually render the content of the pager
29
- // The parent component takes care of rendering
30
- render: (children: React.ReactNode) => React.ReactNode;
31
- // Callback to call when switching the tab
32
- // The tab switch animation is performed even if the index in state is unchanged
33
- jumpTo: (key: string) => void;
34
- }
35
- ) => React.ReactElement;
36
- };
37
-
38
- const useNativeDriver = Platform.OS !== 'web';
39
-
40
- export function PagerViewAdapter<T extends Route>({
41
- keyboardDismissMode = 'auto',
42
- swipeEnabled = true,
43
- navigationState,
44
- onIndexChange,
45
- onTabSelect,
46
- onSwipeStart,
47
- onSwipeEnd,
48
- children,
49
- style,
50
- animationEnabled,
51
- ...rest
52
- }: Props<T>) {
53
- const { index } = navigationState;
54
-
55
- const listenersRef = React.useRef<Listener[]>([]);
56
-
57
- const pagerRef = React.useRef<ViewPager>(null);
58
- const indexRef = React.useRef<number>(index);
59
- const navigationStateRef = React.useRef(navigationState);
60
-
61
- const position = useAnimatedValue(index);
62
- const offset = useAnimatedValue(0);
63
-
64
- React.useEffect(() => {
65
- navigationStateRef.current = navigationState;
66
- });
67
-
68
- const jumpTo = useLatestCallback((key: string) => {
69
- const index = navigationStateRef.current.routes.findIndex(
70
- (route: { key: string }) => route.key === key
71
- );
72
-
73
- if (animationEnabled) {
74
- pagerRef.current?.setPage(index);
75
- } else {
76
- pagerRef.current?.setPageWithoutAnimation(index);
77
- position.setValue(index);
78
- }
79
-
80
- onIndexChange(index);
81
- });
2
+ PagerViewAdapter as PagerViewAdapterType,
3
+ PagerViewAdapterProps,
4
+ } from './PagerViewAdapter.native';
82
5
 
83
- React.useEffect(() => {
84
- if (keyboardDismissMode === 'auto') {
85
- Keyboard.dismiss();
86
- }
6
+ export type { PagerViewAdapterProps };
87
7
 
88
- if (indexRef.current !== index) {
89
- if (animationEnabled) {
90
- pagerRef.current?.setPage(index);
91
- } else {
92
- pagerRef.current?.setPageWithoutAnimation(index);
93
- position.setValue(index);
94
- }
95
- }
96
- }, [keyboardDismissMode, index, animationEnabled, position]);
97
-
98
- const onPageScrollStateChanged = (
99
- state: PageScrollStateChangedNativeEvent
100
- ) => {
101
- const { pageScrollState } = state.nativeEvent;
102
-
103
- switch (pageScrollState) {
104
- case 'idle':
105
- onSwipeEnd?.();
106
- return;
107
- case 'dragging': {
108
- const subscription = offset.addListener(({ value }) => {
109
- const next =
110
- index + (value > 0 ? Math.ceil(value) : Math.floor(value));
111
-
112
- if (next !== index) {
113
- listenersRef.current.forEach((listener) => listener(next));
114
- }
115
-
116
- offset.removeListener(subscription);
117
- });
118
-
119
- onSwipeStart?.();
120
- return;
121
- }
122
- }
123
- };
124
-
125
- const addEnterListener = useLatestCallback((listener: Listener) => {
126
- listenersRef.current.push(listener);
127
-
128
- return () => {
129
- const index = listenersRef.current.indexOf(listener);
130
-
131
- if (index > -1) {
132
- listenersRef.current.splice(index, 1);
133
- }
134
- };
135
- });
136
-
137
- const memoizedPosition = React.useMemo(
138
- () => Animated.add(position, offset),
139
- [offset, position]
8
+ export const PagerViewAdapter: typeof PagerViewAdapterType = () => {
9
+ throw new Error(
10
+ `'PagerViewAdapter' is not supported on web. Use 'PanResponderAdapter' or 'ScrollViewAdapter' instead.`
140
11
  );
141
-
142
- return children({
143
- position: memoizedPosition,
144
- addEnterListener,
145
- jumpTo,
146
- render: (children) => (
147
- <AnimatedViewPager
148
- {...rest}
149
- ref={pagerRef}
150
- style={[styles.container, style]}
151
- initialPage={index}
152
- keyboardDismissMode={
153
- keyboardDismissMode === 'auto' ? 'on-drag' : keyboardDismissMode
154
- }
155
- onPageScroll={Animated.event(
156
- [
157
- {
158
- nativeEvent: {
159
- position: position,
160
- offset: offset,
161
- },
162
- },
163
- ],
164
- { useNativeDriver }
165
- )}
166
- onPageSelected={(e) => {
167
- const index = e.nativeEvent.position;
168
- indexRef.current = index;
169
- onIndexChange(index);
170
- onTabSelect?.({ index });
171
- }}
172
- onPageScrollStateChanged={onPageScrollStateChanged}
173
- scrollEnabled={swipeEnabled}
174
- >
175
- {children}
176
- </AnimatedViewPager>
177
- ),
178
- });
179
- }
180
-
181
- const styles = StyleSheet.create({
182
- container: {
183
- flex: 1,
184
- },
185
- });
12
+ };