@momo-kits/tab-view 0.151.1-test.4 → 0.151.2-beta.2
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 +10 -19
- package/package.json +1 -1
package/index.tsx
CHANGED
|
@@ -8,8 +8,8 @@ import React, {
|
|
|
8
8
|
useRef,
|
|
9
9
|
useState,
|
|
10
10
|
} from 'react';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import {Animated, LayoutChangeEvent, View} from 'react-native';
|
|
12
|
+
import {Tab, TabViewProps, TabViewRef} from './types';
|
|
13
13
|
import TabBar from './tabBar/TabBar';
|
|
14
14
|
import styles from './styles';
|
|
15
15
|
import CardTabBar from './tabBar/CardTabBar';
|
|
@@ -49,11 +49,9 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
49
49
|
const pagerRef = useRef<PagerView>(null);
|
|
50
50
|
const scrollX = useRef(new Animated.Value(startPage));
|
|
51
51
|
const lazy = useRef([selectedIndex]).current;
|
|
52
|
-
const {
|
|
52
|
+
const {theme} = useContext(ApplicationContext);
|
|
53
53
|
const app = useContext<any>(MiniAppContext);
|
|
54
54
|
const screen = useContext<any>(ScreenContext);
|
|
55
|
-
let scrollEnabled = useRef(false);
|
|
56
|
-
|
|
57
55
|
const componentName = 'TabView';
|
|
58
56
|
|
|
59
57
|
const componentId = useMemo(() => {
|
|
@@ -79,7 +77,7 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
79
77
|
};
|
|
80
78
|
|
|
81
79
|
const onPageSelected = (e: PagerViewOnPageSelectedEvent) => {
|
|
82
|
-
const {
|
|
80
|
+
const {position} = e.nativeEvent;
|
|
83
81
|
if (!lazy.includes(position)) {
|
|
84
82
|
lazy.push(position);
|
|
85
83
|
}
|
|
@@ -94,7 +92,7 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
const onPageScroll = (e: PagerViewOnPageScrollEvent) => {
|
|
97
|
-
const {
|
|
95
|
+
const {position, offset} = e.nativeEvent;
|
|
98
96
|
scrollX.current.setValue(position + offset);
|
|
99
97
|
pagerProps?.onPageScroll?.(e);
|
|
100
98
|
};
|
|
@@ -116,9 +114,8 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
116
114
|
return (
|
|
117
115
|
<View
|
|
118
116
|
onLayout={onLayout}
|
|
119
|
-
style={[styles.tabView, {
|
|
120
|
-
accessibilityLabel={componentId}
|
|
121
|
-
>
|
|
117
|
+
style={[styles.tabView, {flex: 1}]}
|
|
118
|
+
accessibilityLabel={componentId}>
|
|
122
119
|
<Animated.View style={style}>
|
|
123
120
|
<TabBarComponent
|
|
124
121
|
onPressTabItem={_onPressTabItem}
|
|
@@ -137,15 +134,9 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
137
134
|
{...pagerProps}
|
|
138
135
|
onPageScroll={onPageScroll}
|
|
139
136
|
ref={pagerRef}
|
|
140
|
-
scrollEnabled={scrollEnabled.current}
|
|
141
|
-
onLayout={e => {
|
|
142
|
-
pagerProps?.onLayout?.(e);
|
|
143
|
-
scrollEnabled.current = pagerProps?.scrollEnabled ?? false;
|
|
144
|
-
}}
|
|
145
137
|
onPageSelected={onPageSelected}
|
|
146
138
|
style={styles.pagerView}
|
|
147
|
-
initialPage={startPage}
|
|
148
|
-
>
|
|
139
|
+
initialPage={startPage}>
|
|
149
140
|
{tabs.map((tab, index) => renderScreen(tab, index))}
|
|
150
141
|
</PagerView>
|
|
151
142
|
</View>
|
|
@@ -154,5 +145,5 @@ const TabComponent: ForwardRefRenderFunction<TabViewRef, TabViewProps> = (
|
|
|
154
145
|
|
|
155
146
|
const TabView = forwardRef(TabComponent);
|
|
156
147
|
|
|
157
|
-
export {
|
|
158
|
-
export type {
|
|
148
|
+
export {CardTabBar, ScrollableTabBar, TabBar, TabView};
|
|
149
|
+
export type {TabViewProps, TabViewRef, Tab};
|