@react-native-ohos/react-native-tab-view 4.0.11-rc.1

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 (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.OpenSource +11 -0
  3. package/README.md +9 -0
  4. package/lib/module/Pager.android.js +4 -0
  5. package/lib/module/Pager.android.js.map +1 -0
  6. package/lib/module/Pager.ios.js +4 -0
  7. package/lib/module/Pager.ios.js.map +1 -0
  8. package/lib/module/Pager.js +4 -0
  9. package/lib/module/Pager.js.map +1 -0
  10. package/lib/module/PagerViewAdapter.js +126 -0
  11. package/lib/module/PagerViewAdapter.js.map +1 -0
  12. package/lib/module/PanResponderAdapter.js +200 -0
  13. package/lib/module/PanResponderAdapter.js.map +1 -0
  14. package/lib/module/PlatformPressable.js +59 -0
  15. package/lib/module/PlatformPressable.js.map +1 -0
  16. package/lib/module/SceneMap.js +24 -0
  17. package/lib/module/SceneMap.js.map +1 -0
  18. package/lib/module/SceneView.js +73 -0
  19. package/lib/module/SceneView.js.map +1 -0
  20. package/lib/module/TabBar.js +472 -0
  21. package/lib/module/TabBar.js.map +1 -0
  22. package/lib/module/TabBarIndicator.js +122 -0
  23. package/lib/module/TabBarIndicator.js.map +1 -0
  24. package/lib/module/TabBarItem.js +218 -0
  25. package/lib/module/TabBarItem.js.map +1 -0
  26. package/lib/module/TabBarItemLabel.js +33 -0
  27. package/lib/module/TabBarItemLabel.js.map +1 -0
  28. package/lib/module/TabView.js +140 -0
  29. package/lib/module/TabView.js.map +1 -0
  30. package/lib/module/index.js +8 -0
  31. package/lib/module/index.js.map +1 -0
  32. package/lib/module/package.json +1 -0
  33. package/lib/module/types.js +4 -0
  34. package/lib/module/types.js.map +1 -0
  35. package/lib/module/useAnimatedValue.js +12 -0
  36. package/lib/module/useAnimatedValue.js.map +1 -0
  37. package/lib/typescript/package.json +1 -0
  38. package/lib/typescript/src/Pager.android.d.ts +2 -0
  39. package/lib/typescript/src/Pager.android.d.ts.map +1 -0
  40. package/lib/typescript/src/Pager.d.ts +2 -0
  41. package/lib/typescript/src/Pager.d.ts.map +1 -0
  42. package/lib/typescript/src/Pager.ios.d.ts +2 -0
  43. package/lib/typescript/src/Pager.ios.d.ts.map +1 -0
  44. package/lib/typescript/src/PagerViewAdapter.d.ts +15 -0
  45. package/lib/typescript/src/PagerViewAdapter.d.ts.map +1 -0
  46. package/lib/typescript/src/PanResponderAdapter.d.ts +16 -0
  47. package/lib/typescript/src/PanResponderAdapter.d.ts.map +1 -0
  48. package/lib/typescript/src/PlatformPressable.d.ts +13 -0
  49. package/lib/typescript/src/PlatformPressable.d.ts.map +1 -0
  50. package/lib/typescript/src/SceneMap.d.ts +10 -0
  51. package/lib/typescript/src/SceneMap.d.ts.map +1 -0
  52. package/lib/typescript/src/SceneView.d.ts +16 -0
  53. package/lib/typescript/src/SceneView.d.ts.map +1 -0
  54. package/lib/typescript/src/TabBar.d.ts +32 -0
  55. package/lib/typescript/src/TabBar.d.ts.map +1 -0
  56. package/lib/typescript/src/TabBarIndicator.d.ts +15 -0
  57. package/lib/typescript/src/TabBarIndicator.d.ts.map +1 -0
  58. package/lib/typescript/src/TabBarItem.d.ts +19 -0
  59. package/lib/typescript/src/TabBarItem.d.ts.map +1 -0
  60. package/lib/typescript/src/TabBarItemLabel.d.ts +11 -0
  61. package/lib/typescript/src/TabBarItemLabel.d.ts.map +1 -0
  62. package/lib/typescript/src/TabView.d.ts +30 -0
  63. package/lib/typescript/src/TabView.d.ts.map +1 -0
  64. package/lib/typescript/src/index.d.ts +11 -0
  65. package/lib/typescript/src/index.d.ts.map +1 -0
  66. package/lib/typescript/src/types.d.ts +70 -0
  67. package/lib/typescript/src/types.d.ts.map +1 -0
  68. package/lib/typescript/src/useAnimatedValue.d.ts +3 -0
  69. package/lib/typescript/src/useAnimatedValue.d.ts.map +1 -0
  70. package/package.json +79 -0
  71. package/src/Pager.android.tsx +1 -0
  72. package/src/Pager.ios.tsx +1 -0
  73. package/src/Pager.tsx +1 -0
  74. package/src/PagerViewAdapter.tsx +182 -0
  75. package/src/PanResponderAdapter.tsx +339 -0
  76. package/src/PlatformPressable.tsx +75 -0
  77. package/src/SceneMap.tsx +30 -0
  78. package/src/SceneView.tsx +107 -0
  79. package/src/TabBar.tsx +729 -0
  80. package/src/TabBarIndicator.tsx +190 -0
  81. package/src/TabBarItem.tsx +305 -0
  82. package/src/TabBarItemLabel.tsx +42 -0
  83. package/src/TabView.tsx +195 -0
  84. package/src/index.tsx +15 -0
  85. package/src/types.tsx +87 -0
  86. package/src/useAnimatedValue.tsx +12 -0
@@ -0,0 +1,15 @@
1
+ import * as React from 'react';
2
+ import { type StyleProp, type ViewStyle } from 'react-native';
3
+ import type { LocaleDirection, NavigationState, Route, SceneRendererProps } from './types';
4
+ export type GetTabWidth = (index: number) => number;
5
+ export type Props<T extends Route> = SceneRendererProps & {
6
+ navigationState: NavigationState<T>;
7
+ width: 'auto' | `${number}%` | number;
8
+ getTabWidth: GetTabWidth;
9
+ direction: LocaleDirection;
10
+ style?: StyleProp<ViewStyle>;
11
+ gap?: number;
12
+ children?: React.ReactNode;
13
+ };
14
+ export declare function TabBarIndicator<T extends Route>({ getTabWidth, layout, navigationState, position, width, direction, gap, style, children, }: Props<T>): import("react/jsx-runtime").JSX.Element;
15
+ //# sourceMappingURL=TabBarIndicator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TabBarIndicator.d.ts","sourceRoot":"","sources":["../../../src/TabBarIndicator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAIL,KAAK,SAAS,EAEd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,KAAK,EACL,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAGjB,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;AAEpD,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,IAAI,kBAAkB,GAAG;IACxD,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,GAAG,GAAG,MAAM,GAAG,GAAG,MAAM,CAAC;IACtC,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,eAAe,CAAC;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AA2CF,wBAAgB,eAAe,CAAC,CAAC,SAAS,KAAK,EAAE,EAC/C,WAAW,EACX,MAAM,EACN,eAAe,EACf,QAAQ,EACR,KAAK,EACL,SAAS,EACT,GAAG,EACH,KAAK,EACL,QAAQ,GACT,EAAE,KAAK,CAAC,CAAC,CAAC,2CAiGV"}
@@ -0,0 +1,19 @@
1
+ import { Animated, type LayoutChangeEvent, type PressableAndroidRippleConfig, type StyleProp, type ViewStyle } from 'react-native';
2
+ import type { NavigationState, Route, TabDescriptor } from './types';
3
+ export type Props<T extends Route> = TabDescriptor<T> & {
4
+ position: Animated.AnimatedInterpolation<number>;
5
+ route: T;
6
+ navigationState: NavigationState<T>;
7
+ activeColor?: string;
8
+ inactiveColor?: string;
9
+ pressColor?: string;
10
+ pressOpacity?: number;
11
+ onLayout?: (event: LayoutChangeEvent) => void;
12
+ onPress: () => void;
13
+ onLongPress: () => void;
14
+ defaultTabWidth?: number;
15
+ style: StyleProp<ViewStyle>;
16
+ android_ripple?: PressableAndroidRippleConfig;
17
+ };
18
+ export declare function TabBarItem<T extends Route>(props: Props<T>): import("react/jsx-runtime").JSX.Element;
19
+ //# sourceMappingURL=TabBarItem.d.ts.map
@@ -0,0 +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;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,cAAc,CAAC,EAAE,4BAA4B,CAAC;CAC/C,CAAC;AA+NF,wBAAgB,UAAU,CAAC,CAAC,SAAS,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,2CAsB1D"}
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { StyleProp, ViewStyle } from 'react-native';
3
+ interface TabBarItemLabelProps {
4
+ color: string;
5
+ label?: string;
6
+ style: StyleProp<ViewStyle>;
7
+ icon: React.ReactNode;
8
+ }
9
+ export declare const TabBarItemLabel: React.MemoExoticComponent<({ color, label, style, icon }: TabBarItemLabelProps) => import("react/jsx-runtime").JSX.Element | null>;
10
+ export {};
11
+ //# sourceMappingURL=TabBarItemLabel.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
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'> & {
5
+ onIndexChange: (index: number) => void;
6
+ navigationState: NavigationState<T>;
7
+ renderLazyPlaceholder?: (props: {
8
+ route: T;
9
+ }) => React.ReactNode;
10
+ renderTabBar?: (props: SceneRendererProps & {
11
+ navigationState: NavigationState<T>;
12
+ options: Record<string, TabDescriptor<T>> | undefined;
13
+ }) => React.ReactNode;
14
+ tabBarPosition?: 'top' | 'bottom';
15
+ initialLayout?: Partial<Layout>;
16
+ lazy?: ((props: {
17
+ route: T;
18
+ }) => boolean) | boolean;
19
+ lazyPreloadDistance?: number;
20
+ direction?: LocaleDirection;
21
+ pagerStyle?: StyleProp<ViewStyle>;
22
+ style?: StyleProp<ViewStyle>;
23
+ renderScene: (props: SceneRendererProps & {
24
+ route: T;
25
+ }) => React.ReactNode;
26
+ options?: Record<string, TabDescriptor<T>>;
27
+ commonOptions?: TabDescriptor<T>;
28
+ };
29
+ export declare function TabView<T extends Route>({ onIndexChange, 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;
30
+ //# sourceMappingURL=TabView.d.ts.map
@@ -0,0 +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,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,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,CAAC,CAAA;KAAE,KAAK,OAAO,CAAC,GAAG,OAAO,CAAC;IACpD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,WAAW,EAAE,CAAC,KAAK,EAAE,kBAAkB,GAAG;QAAE,KAAK,EAAE,CAAC,CAAA;KAAE,KAAK,KAAK,CAAC,SAAS,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,eAAe,EACf,WAAW,EACX,aAAa,EACb,mBAA4B,EAC5B,IAAY,EACZ,mBAAuB,EACvB,YAAY,EACZ,UAAU,EACV,qBAAoD,EAEpD,YAA+C,EAC/C,UAAU,EACV,KAAK,EACL,SAA4D,EAC5D,YAAmB,EACnB,cAAsB,EACtB,gBAAuB,EACvB,cAAc,EACd,OAAO,EAAE,YAAY,EACrB,aAAa,GACd,EAAE,KAAK,CAAC,CAAC,CAAC,2CAqHV"}
@@ -0,0 +1,11 @@
1
+ export { SceneMap } from './SceneMap';
2
+ export type { Props as TabBarProps } from './TabBar';
3
+ export { TabBar } from './TabBar';
4
+ export type { Props as TabBarIndicatorProps } from './TabBarIndicator';
5
+ export { TabBarIndicator } from './TabBarIndicator';
6
+ export type { Props as TabBarItemProps } from './TabBarItem';
7
+ export { TabBarItem } from './TabBarItem';
8
+ export type { Props as TabViewProps } from './TabView';
9
+ export { TabView } from './TabView';
10
+ export type { NavigationState, Route, SceneRendererProps, TabDescriptor, } from './types';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,WAAW,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,YAAY,EAAE,KAAK,IAAI,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,KAAK,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,eAAe,EACf,KAAK,EACL,kBAAkB,EAClB,aAAa,GACd,MAAM,SAAS,CAAC"}
@@ -0,0 +1,70 @@
1
+ import type { Animated, StyleProp, TextStyle, ViewStyle } from 'react-native';
2
+ import type { PagerViewProps } from 'react-native-pager-view';
3
+ export type TabDescriptor<T extends Route> = {
4
+ accessibilityLabel?: string;
5
+ accessible?: boolean;
6
+ testID?: string;
7
+ labelText?: string;
8
+ labelAllowFontScaling?: boolean;
9
+ href?: string;
10
+ label?: (props: {
11
+ route: T;
12
+ labelText?: string;
13
+ focused: boolean;
14
+ color: string;
15
+ allowFontScaling?: boolean;
16
+ style?: StyleProp<TextStyle>;
17
+ }) => React.ReactNode;
18
+ labelStyle?: StyleProp<TextStyle>;
19
+ icon?: (props: {
20
+ route: T;
21
+ focused: boolean;
22
+ color: string;
23
+ size: number;
24
+ }) => React.ReactNode;
25
+ badge?: (props: {
26
+ route: T;
27
+ }) => React.ReactElement;
28
+ sceneStyle?: StyleProp<ViewStyle>;
29
+ };
30
+ export type LocaleDirection = 'ltr' | 'rtl';
31
+ export type Route = {
32
+ key: string;
33
+ icon?: string;
34
+ title?: string;
35
+ accessible?: boolean;
36
+ accessibilityLabel?: string;
37
+ testID?: string;
38
+ };
39
+ export type Event = {
40
+ defaultPrevented: boolean;
41
+ preventDefault(): void;
42
+ };
43
+ export type Scene<T extends Route> = {
44
+ route: T;
45
+ };
46
+ export type NavigationState<T extends Route> = {
47
+ index: number;
48
+ routes: T[];
49
+ };
50
+ export type Layout = {
51
+ width: number;
52
+ height: number;
53
+ };
54
+ export type Listener = (value: number) => void;
55
+ export type SceneRendererProps = {
56
+ layout: Layout;
57
+ position: Animated.AnimatedInterpolation<number>;
58
+ jumpTo: (key: string) => void;
59
+ };
60
+ export type EventEmitterProps = {
61
+ addEnterListener: (listener: Listener) => () => void;
62
+ };
63
+ export type PagerProps = Omit<PagerViewProps, 'initialPage' | 'scrollEnabled' | 'onPageScroll' | 'onPageSelected' | 'onPageScrollStateChanged' | 'keyboardDismissMode' | 'children'> & {
64
+ keyboardDismissMode?: 'none' | 'on-drag' | 'auto';
65
+ swipeEnabled?: boolean;
66
+ animationEnabled?: boolean;
67
+ onSwipeStart?: () => void;
68
+ onSwipeEnd?: () => void;
69
+ };
70
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.tsx"],"names":[],"mappings":"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"}
@@ -0,0 +1,3 @@
1
+ import { Animated } from 'react-native';
2
+ export declare function useAnimatedValue(initialValue: number): Animated.Value;
3
+ //# sourceMappingURL=useAnimatedValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAnimatedValue.d.ts","sourceRoot":"","sources":["../../../src/useAnimatedValue.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAOzB,QAAQ,CAAC,KAAK,CACzC"}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@react-native-ohos/react-native-tab-view",
3
+ "description": "Tab view component for React Native",
4
+ "version": "4.0.11-rc.1",
5
+ "keywords": [
6
+ "react-native-component",
7
+ "react-component",
8
+ "react-native",
9
+ "ios",
10
+ "android",
11
+ "tab",
12
+ "swipe",
13
+ "scrollable",
14
+ "coverflow"
15
+ ],
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://gitcode.com/openharmony-sig/rntpc_react-navigation.git",
20
+ "directory": "packages/react-native-tab-view"
21
+ },
22
+ "source": "./src/index.tsx",
23
+ "main": "./lib/module/index.js",
24
+ "types": "./lib/typescript/src/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./lib/typescript/src/index.d.ts",
28
+ "default": "./lib/module/index.js"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "src",
34
+ "lib",
35
+ "!**/__tests__"
36
+ ],
37
+ "sideEffects": false,
38
+ "scripts": {
39
+ "prepack": "bob build",
40
+ "clean": "del lib"
41
+ },
42
+ "dependencies": {
43
+ "use-latest-callback": "^0.2.1"
44
+ },
45
+ "devDependencies": {
46
+ "@jest/globals": "^29.7.0",
47
+ "@testing-library/react-native": "^12.8.1",
48
+ "del-cli": "^5.1.0",
49
+ "react": "18.3.1",
50
+ "react-native": "0.76.2",
51
+ "react-native-builder-bob": "^0.40.0",
52
+ "react-native-pager-view": "6.5.1",
53
+ "react-test-renderer": "18.2.0",
54
+ "typescript": "^5.5.2"
55
+ },
56
+ "peerDependencies": {
57
+ "react": ">= 18.2.0",
58
+ "react-native": "*",
59
+ "react-native-pager-view": ">= 6.0.0"
60
+ },
61
+ "react-native-builder-bob": {
62
+ "source": "src",
63
+ "output": "lib",
64
+ "targets": [
65
+ [
66
+ "module",
67
+ {
68
+ "esm": true
69
+ }
70
+ ],
71
+ [
72
+ "typescript",
73
+ {
74
+ "project": "tsconfig.build.json"
75
+ }
76
+ ]
77
+ ]
78
+ }
79
+ }
@@ -0,0 +1 @@
1
+ export { PagerViewAdapter as Pager } from './PagerViewAdapter';
@@ -0,0 +1 @@
1
+ export { PagerViewAdapter as Pager } from './PagerViewAdapter';
package/src/Pager.tsx ADDED
@@ -0,0 +1 @@
1
+ export { PanResponderAdapter as Pager } from './PanResponderAdapter';
@@ -0,0 +1,182 @@
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
+ 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
+ navigationState: NavigationState<T>;
22
+ children: (
23
+ props: EventEmitterProps & {
24
+ // Animated value which represents the state of current index
25
+ // It can include fractional digits as it represents the intermediate value
26
+ position: Animated.AnimatedInterpolation<number>;
27
+ // Function to actually render the content of the pager
28
+ // The parent component takes care of rendering
29
+ render: (children: React.ReactNode) => React.ReactNode;
30
+ // Callback to call when switching the tab
31
+ // The tab switch animation is performed even if the index in state is unchanged
32
+ jumpTo: (key: string) => void;
33
+ }
34
+ ) => React.ReactElement;
35
+ };
36
+
37
+ const useNativeDriver = Platform.OS !== 'web';
38
+
39
+ export function PagerViewAdapter<T extends Route>({
40
+ keyboardDismissMode = 'auto',
41
+ swipeEnabled = true,
42
+ navigationState,
43
+ onIndexChange,
44
+ onSwipeStart,
45
+ onSwipeEnd,
46
+ children,
47
+ style,
48
+ animationEnabled,
49
+ ...rest
50
+ }: Props<T>) {
51
+ const { index } = navigationState;
52
+
53
+ const listenersRef = React.useRef<Listener[]>([]);
54
+
55
+ const pagerRef = React.useRef<ViewPager>(null);
56
+ const indexRef = React.useRef<number>(index);
57
+ const navigationStateRef = React.useRef(navigationState);
58
+
59
+ const position = useAnimatedValue(index);
60
+ const offset = useAnimatedValue(0);
61
+
62
+ React.useEffect(() => {
63
+ navigationStateRef.current = navigationState;
64
+ });
65
+
66
+ const jumpTo = useLatestCallback((key: string) => {
67
+ const index = navigationStateRef.current.routes.findIndex(
68
+ (route: { key: string }) => route.key === key
69
+ );
70
+
71
+ if (animationEnabled) {
72
+ pagerRef.current?.setPage(index);
73
+ } else {
74
+ pagerRef.current?.setPageWithoutAnimation(index);
75
+ position.setValue(index);
76
+ }
77
+
78
+ onIndexChange(index);
79
+ });
80
+
81
+ React.useEffect(() => {
82
+ if (keyboardDismissMode === 'auto') {
83
+ Keyboard.dismiss();
84
+ }
85
+
86
+ if (indexRef.current !== index) {
87
+ if (animationEnabled) {
88
+ pagerRef.current?.setPage(index);
89
+ } else {
90
+ pagerRef.current?.setPageWithoutAnimation(index);
91
+ position.setValue(index);
92
+ }
93
+ }
94
+ }, [keyboardDismissMode, index, animationEnabled, position]);
95
+
96
+ const onPageScrollStateChanged = (
97
+ state: PageScrollStateChangedNativeEvent
98
+ ) => {
99
+ const { pageScrollState } = state.nativeEvent;
100
+
101
+ switch (pageScrollState) {
102
+ case 'idle':
103
+ onSwipeEnd?.();
104
+ return;
105
+ case 'dragging': {
106
+ const subscription = offset.addListener(({ value }) => {
107
+ const next =
108
+ index + (value > 0 ? Math.ceil(value) : Math.floor(value));
109
+
110
+ if (next !== index) {
111
+ listenersRef.current.forEach((listener) => listener(next));
112
+ }
113
+
114
+ offset.removeListener(subscription);
115
+ });
116
+
117
+ onSwipeStart?.();
118
+ return;
119
+ }
120
+ }
121
+ };
122
+
123
+ const addEnterListener = useLatestCallback((listener: Listener) => {
124
+ listenersRef.current.push(listener);
125
+
126
+ return () => {
127
+ const index = listenersRef.current.indexOf(listener);
128
+
129
+ if (index > -1) {
130
+ listenersRef.current.splice(index, 1);
131
+ }
132
+ };
133
+ });
134
+
135
+ const memoizedPosition = React.useMemo(
136
+ () => Animated.add(position, offset),
137
+ [offset, position]
138
+ );
139
+
140
+ return children({
141
+ position: memoizedPosition,
142
+ addEnterListener,
143
+ jumpTo,
144
+ render: (children) => (
145
+ <AnimatedViewPager
146
+ {...rest}
147
+ ref={pagerRef}
148
+ style={[styles.container, style]}
149
+ initialPage={index}
150
+ keyboardDismissMode={
151
+ keyboardDismissMode === 'auto' ? 'on-drag' : keyboardDismissMode
152
+ }
153
+ onPageScroll={Animated.event(
154
+ [
155
+ {
156
+ nativeEvent: {
157
+ position: position,
158
+ offset: offset,
159
+ },
160
+ },
161
+ ],
162
+ { useNativeDriver }
163
+ )}
164
+ onPageSelected={(e) => {
165
+ const index = e.nativeEvent.position;
166
+ indexRef.current = index;
167
+ onIndexChange(index);
168
+ }}
169
+ onPageScrollStateChanged={onPageScrollStateChanged}
170
+ scrollEnabled={swipeEnabled}
171
+ >
172
+ {children}
173
+ </AnimatedViewPager>
174
+ ),
175
+ });
176
+ }
177
+
178
+ const styles = StyleSheet.create({
179
+ container: {
180
+ flex: 1,
181
+ },
182
+ });