【发布时间】:2020-09-07 22:48:11
【问题描述】:
我正在使用 React Navigation 5 和 @react-navigation/bottom-tabs 的 createBottomTabNavigator 创建自定义标签栏,
问题:红色图标只能在标签栏范围内点击,一旦我越过了标签栏的灰线,我就无法点击该图标。
我已经使用以下代码为标签屏幕创建了它
<Tab.Screen
name="Scan"
component={Scan}
options={({ navigation }) => {
return {
tabBarIcon: () => <MiddleIcon navigation={navigation} />,
};
}}
/>
我已经尝试将整个视图包裹在可触摸的不透明度中,但它仍然只能在标签栏的范围内触摸
MiddleIcon 组件:
const MiddleIcon = ({ navigation }) => {
return (
<TouchableOpacity
onPress={() => navigation.navigate('Scan')}
style={styles.container}>
<View style={styles.imageContainer}>
<Image
source={require('../../../assets/images/shared/scan_icon.png')}
/>
</View>
</TouchableOpacity>
);
};
export default MiddleIcon;
const styles = StyleSheet.create({
container: {
position: 'absolute',
bottom: 20,
height: 58,
width: 58,
borderRadius: 58,
backgroundColor: colors.primaryColor,
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.29,
shadowRadius: 4.65,
elevation: 7,
flex: 1,
},
icon: {
width: 40,
height: 40,
tintColor: '#fff',
alignContent: 'center',
},
imageContainer: {
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
width: 30,
height: 30,
},
});
问题:如何让它在底部标签栏的边界之外可以点击?
【问题讨论】:
-
你找到解决办法了吗?
-
@AliAkbarAzizi 还没有
-
我尝试自定义标签栏,并且使用 React.fragment 包装器可以做到。因为片段将元素放在父容器中。看这里gist.github.com/abuinitski/5c805972f40e0e5e47c352bc1390dab3
标签: react-native react-navigation react-navigation-bottom-tab