我是初学者,我需要为 tabBarButton 制作组件,我成功了。
问题是导航现在不起作用,因为我不知道如何编写 onPress 函数以使其起作用!
有人可以帮我解决这个问题吗?
这是我的组件,我在我的Tab.Navigator:
import React from 'react';
import {StyleSheet, TouchableOpacity, View} from 'react-native';
import Text from '../Text/Text';
interface Props {}
const NavBottomButton: React.FC<Props> = (props) => {
const {children} = props;
return (
<TouchableOpacity onPress={() => {}} style={styles.navButton}>
<View>
<Text>{children}</Text>
</View>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
navButton: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
});
export default NavBottomButton;
Run Code Online (Sandbox Code Playgroud)
这是我使用组件的方式:
<Tab.Navigator
tabBarOptions={someStyles}>
<Tab.Screen
name="Matches"
component={Matches}
options={{
tabBarButton: (props) => (
<NavBottomButton …Run Code Online (Sandbox Code Playgroud) 我有带有 的侧边栏组件Links,并且我需要Link在打开特定 URL 时更改颜色。
React 中最好的解决方案是什么?