Skip to content

Commit 9e3b348

Browse files
committed
fix(Tab): 修复在android手机上被遮挡
1 parent f400bdc commit 9e3b348

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

example/examples/src/routes/Tabs/index.tsx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {Component} from 'react';
2-
import {StyleSheet, View} from 'react-native';
2+
import {StyleSheet, View, Text} from 'react-native';
33
import Layout, {Container} from '../../Layout';
44
import {Tabs, IconsName} from '@uiw/react-native';
55
import {ComProps} from '../../routes';
@@ -43,12 +43,36 @@ export default class Index extends Component<IndexProps, IndexState> {
4343
<Header title={title} description={description} />
4444
<Body>
4545
<Tabs value={this.state.flag} onChange={value => this.setState({flag: value})}>
46-
<Tabs.Item title="喜欢" />
47-
<Tabs.Item title="关注" />
48-
<Tabs.Item title="兴趣" />
49-
<Tabs.Item title="爱好" />
50-
<Tabs.Item title="gitlabl" />
51-
<Tabs.Item title="github" />
46+
<Tabs.Item title="喜欢">
47+
<View>
48+
<Text>喜欢</Text>
49+
</View>
50+
</Tabs.Item>
51+
<Tabs.Item title="关注">
52+
<View>
53+
<Text>关注</Text>
54+
</View>
55+
</Tabs.Item>
56+
<Tabs.Item title="兴趣">
57+
<View>
58+
<Text>喜欢</Text>
59+
</View>
60+
</Tabs.Item>
61+
<Tabs.Item title="爱好">
62+
<View>
63+
<Text>爱好</Text>
64+
</View>
65+
</Tabs.Item>
66+
<Tabs.Item title="gitlabl">
67+
<View>
68+
<Text>gitlabl</Text>
69+
</View>
70+
</Tabs.Item>
71+
<Tabs.Item title="github">
72+
<View>
73+
<Text>github</Text>
74+
</View>
75+
</Tabs.Item>
5276
</Tabs>
5377

5478
<View style={styles.divider} />

packages/core/src/Tabs/TabsItem.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
1+
import React, { useCallback, useEffect, useMemo, useRef, useImperativeHandle } from 'react';
22
import { View, StyleSheet, Text, TouchableOpacity, Animated } from 'react-native';
33

44
import Icon, { IconsName } from '../Icon';
@@ -38,10 +38,11 @@ export interface TabsItemProps {
3838
onChange?: (value: number) => void;
3939
index?: number;
4040
defaultColor?: string;
41+
children?: React.ReactNode;
4142
}
4243

4344
function TabsItem(props: TabsItemProps) {
44-
const { activeColor, icon, index, value, onChange, defaultColor } = props;
45+
const { activeColor, icon, index, value, onChange, defaultColor, children } = props;
4546
const opacity = useRef(new Animated.Value(0)).current;
4647

4748
useEffect(() => {
@@ -126,14 +127,16 @@ function TabsItem(props: TabsItemProps) {
126127
}, [value]);
127128

128129
return (
129-
<View style={styles.TabsItemContainer}>
130-
<TouchableOpacity onPress={() => (index === 0 || index) && onChange?.(index)}>
131-
<Animated.View style={[styles.titleBox, { ...style().titleBoxStyle }]}>
132-
{IconDom}
133-
<Text style={[styles.title, { ...style().titleStyle }]}>{props.title}</Text>
134-
</Animated.View>
135-
{BorderDom}
136-
</TouchableOpacity>
130+
<View>
131+
<View style={styles.TabsItemContainer}>
132+
<TouchableOpacity onPress={() => (index === 0 || index) && onChange?.(index)}>
133+
<Animated.View style={[styles.titleBox, { ...style().titleBoxStyle }]}>
134+
{IconDom}
135+
<Text style={[styles.title, { ...style().titleStyle }]}>{props.title}</Text>
136+
</Animated.View>
137+
{BorderDom}
138+
</TouchableOpacity>
139+
</View>
137140
</View>
138141
);
139142
}

packages/core/src/Tabs/index.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Tabs(props: TabsProps) {
3737
}
3838

3939
return (
40-
<SafeAreaView style={styles.container}>
40+
<SafeAreaView>
4141
<View style={[styles.TabsContainer, style]}>
4242
<ScrollView horizontal showsHorizontalScrollIndicator={false}>
4343
{children &&
@@ -58,23 +58,27 @@ function Tabs(props: TabsProps) {
5858
})}
5959
</ScrollView>
6060
</View>
61+
{children &&
62+
React.Children.toArray(children).map((child, index) => {
63+
if (!React.isValidElement(child)) {
64+
return;
65+
}
66+
if (value === index) {
67+
return child.props?.children;
68+
}
69+
})}
6170
</SafeAreaView>
6271
);
6372
}
6473

6574
const styles = StyleSheet.create({
66-
container: {
67-
flex: 1,
68-
marginTop: StatusBar.currentHeight || 0,
69-
},
7075
TabsContainer: {
7176
backgroundColor: '#fff',
7277
maxWidth: 1 * MainWidth,
7378
display: 'flex',
7479
justifyContent: 'space-between',
7580
alignItems: 'center',
76-
paddingTop: 15,
77-
paddingBottom: 20,
81+
paddingVertical: 15,
7882
},
7983
});
8084

0 commit comments

Comments
 (0)