Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

javascript - React Native Navigation TopBar图标未显示(React Native Navigation TopBar Icons Are Not Showing)

Just started learning React Native with Expo, trying to implement a top bar navigation.(刚刚开始通过Expo学习React Native,试图实现顶部栏导航。)

// screens/Home.tsx function Home() { return ( <View style={styles.container}> <Text>Home Screen!</Text> </View> ) } export default Home // nav/MainTabNavigator.tsx import {Ionicons} from '@expo/vector-icons' import HomeScreen from '../screens/Home' const HomeStack = createStackNavigator( { Home: HomeScreen } ) HomeStack.navigationOptions = { tabBarIcon: ({focused}) => { <Ionicons focused={focused} name='md-information-circle' size={26} style={{marginBottom: -3}} color='green' /> } } HomeStack.path = '' const tabNavigator = createMaterialTopTabNavigator({ HomeStack, }, { tabBarPosition: 'top', swipeEnabled: true, tabBarOptions: { showIcon: true, showLabel: true, activeTintColor: 'white', style: { backgroundColor: 'red' } } }) export default tabNavigator // AppNavigator.tsx import {createAppContainer, createSwitchNavigator} from 'react-navigation'; import MainTabNavigator from './MainTabNavigator' const AppNavigator = createSwitchNavigator({ Main: MainTabNavigator }) export default createAppContainer(AppNavigator) The problem is icons are not showing.(问题是图标未显示。) Imgur Link(图片链接) Please help.(请帮忙。) ================================================================(================================================== ==============) Stack: Expo, TypeScript, React-native-navigation, React-native-vector-icons, @expo/vector-icons(堆栈:Expo,TypeScript,React-native-navigation,React-native-vector-icons,@ expo / vector-icons)   ask by Rario translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to return a component from navigationOptions tabBarIcon.(您需要从navigationOptions tabBarIcon返回一个组件。)

HomeStack.navigationOptions = { tabBarIcon: ({focused}) => { return <TabBarIcon focused={focused} name='md-information-circle' /> } } or(要么) HomeStack.navigationOptions = { tabBarIcon: ({focused}) => (<TabBarIcon focused={focused} name='md-information-circle' />) }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...