@momo-kits/tab-view 0.79.6 → 0.80.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.
package/index.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, {FC, useRef, useState} from 'react';
1
+ import React, {FC, useCallback, useRef, useState} from 'react';
2
2
  import {LayoutChangeEvent, View} from 'react-native';
3
3
  import {Tab, TabViewProps} from './types';
4
4
  import TabBar from './tabBar/TabBar';
@@ -22,7 +22,6 @@ const TabView: FC<TabViewProps> = ({
22
22
  const isCardTab = type === 'card';
23
23
  const pagerRef = useRef<PagerView>(null);
24
24
  const [scrollX, setScrollX] = useState(0);
25
-
26
25
  const _onPressTabItem = (index: number) => {
27
26
  pagerRef.current?.setPage(index);
28
27
  onPressTabItem?.(index);
@@ -49,6 +48,14 @@ const TabView: FC<TabViewProps> = ({
49
48
  const {position, offset} = e.nativeEvent;
50
49
  setScrollX(position + offset);
51
50
  };
51
+
52
+ const renderScreen = useCallback(
53
+ (tab: Tab) => {
54
+ return <View>{tab.component}</View>;
55
+ },
56
+ [tabs],
57
+ );
58
+
52
59
  return (
53
60
  <View onLayout={onLayout} style={[styles.tabView, {flex: 1}]}>
54
61
  <View>
@@ -68,14 +75,12 @@ const TabView: FC<TabViewProps> = ({
68
75
  onPageSelected={onPageSelected}
69
76
  style={styles.pagerView}
70
77
  initialPage={startPage}>
71
- {tabs.map((i, index) => {
72
- i.component.key = `Tab View Screen ${i.title}-${index}`;
73
- return i.component;
74
- })}
78
+ {tabs.map(tab => renderScreen(tab))}
75
79
  </PagerView>
76
80
  </View>
77
81
  );
78
82
  };
79
83
 
80
84
  export default TabView;
85
+ export {CardTabBar, ScrollableTabBar, TabBar};
81
86
  export type {TabViewProps, Tab};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/tab-view",
3
- "version": "0.79.6",
3
+ "version": "0.80.1",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "dependencies": {},
@@ -1,5 +1,5 @@
1
- import React, {FC, useContext, useEffect, useRef} from 'react';
2
- import {Animated, Platform, View} from 'react-native';
1
+ import React, {FC, useContext} from 'react';
2
+ import {Platform, View} from 'react-native';
3
3
  import {TabBarProps} from '../types';
4
4
  import styles from '../styles';
5
5
  import {
@@ -1,5 +1,5 @@
1
1
  import React, {FC} from 'react';
2
- import {TouchableOpacity, View} from 'react-native';
2
+ import {TouchableOpacity} from 'react-native';
3
3
  import {TabItemProps} from '../types';
4
4
  import styles from '../styles';
5
5
  import {Image, Spacing, Text} from '@momo-kits/foundation';
package/types.ts CHANGED
@@ -2,34 +2,117 @@ import {ReactElement} from 'react';
2
2
  import {PagerViewProps} from 'react-native-pager-view';
3
3
 
4
4
  export type Tab = {
5
+ /**
6
+ * The title of the tab.
7
+ */
5
8
  title: string;
9
+
10
+ /**
11
+ * Optional. The icon associated with the tab, usually represented by a string referencing the icon's name or path.
12
+ */
6
13
  icon?: string;
14
+
15
+ /**
16
+ * Optional. Specifies the layout direction for the tab's content, either in a row or column format.
17
+ */
7
18
  direction?: 'row' | 'column';
19
+
20
+ /**
21
+ * The main component or content to be displayed when this tab is active.
22
+ */
8
23
  component: ReactElement;
24
+
25
+ /**
26
+ * Optional. If `true`, shows a dot indicator on the tab, often used to signal notifications or updates.
27
+ */
9
28
  showDot?: boolean;
29
+
30
+ /**
31
+ * Optional. Specifies the size of the dot indicator, either 'small' or 'large'.
32
+ */
10
33
  dotSize?: 'small' | 'large';
11
34
  };
12
35
 
13
36
  export type TabItemProps = {
37
+ /**
38
+ * The Tab object containing the details and content of this tab item.
39
+ */
14
40
  tab: Tab;
41
+
42
+ /**
43
+ * Indicates if this tab item is currently active or selected.
44
+ */
15
45
  active: boolean;
46
+
47
+ /**
48
+ * Optional. A callback function that is triggered when this tab item is pressed.
49
+ */
16
50
  onPressTabItem?: () => void;
51
+
52
+ /**
53
+ * Optional. Specifies the width of the tab item. Useful for customizing layout and appearance.
54
+ */
17
55
  width?: number;
18
56
  };
19
57
 
20
58
  export type TabViewProps = {
59
+ /**
60
+ * Optional. If `true`, allows the tab bar to be scrollable, useful for a large number of tabs.
61
+ */
21
62
  scrollable?: boolean;
63
+
64
+ /**
65
+ * An array of Tab objects representing each tab in the view.
66
+ */
22
67
  tabs: Tab[];
68
+
69
+ /**
70
+ * Optional. A callback function that is triggered when a tab item is pressed, receiving the index of the tab as a parameter.
71
+ */
23
72
  onPressTabItem?: (index: number) => void;
73
+
74
+ /**
75
+ * Optional. Specifies the visual style of the tab view, such as 'default' or 'card'.
76
+ */
24
77
  type?: 'default' | 'card';
78
+
79
+ /**
80
+ * Optional. Specifies the initial page or tab to be displayed.
81
+ */
25
82
  initialPage?: number;
83
+
84
+ /**
85
+ * Optional. Additional properties to pass to the underlying pager view component.
86
+ */
26
87
  pagerProps?: PagerViewProps;
27
88
  };
28
89
 
90
+ /**
91
+ * Properties for the TabBar component, which displays the navigation tabs.
92
+ */
29
93
  export type TabBarProps = {
94
+ /**
95
+ * An array of Tab objects representing each tab in the tab bar.
96
+ */
30
97
  tabs: Tab[];
98
+
99
+ /**
100
+ * The index of the currently selected or active tab.
101
+ */
31
102
  selectedIndex: number;
103
+
104
+ /**
105
+ * Optional. A callback function that is triggered when a tab item is pressed, receiving the index of the tab as a parameter.
106
+ */
32
107
  onPressTabItem?: (index: number) => void;
108
+
109
+ /**
110
+ * The width of the container in which the tab bar is placed. Useful for layout calculations.
111
+ */
33
112
  containerWidth: number;
113
+
114
+ /**
115
+ * Represents the horizontal scroll position in a scrollable tab bar.
116
+ */
34
117
  scrollX: number;
35
118
  };