reactjs - React Native Drawer Navigator,如何添加图标和图像?
问题描述
所以我刚刚在 react-native 应用程序中创建了一个抽屉导航器。
现在看起来像这样: IMAGE
现在我想在文本之前和之后添加前导和尾随图标。
我还想在顶部添加标题图片,在底部添加文字。
我怎样才能做到这一点?有什么帮助吗?
这是我的 App.js 代码:
import 'react-native-gesture-handler';
import * as React from 'react';
import { Button, View, Text, TouchableOpacity, Image } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createDrawerNavigator } from '@react-navigation/drawer';
import FirstPage from './pages/FirstPage';
import SecondPage from './pages/SecondPage';
import ThirdPage from './pages/ThirdPage';
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
const NavigationDrawerStructure = (props)=> {
//Structure for the navigatin Drawer
const toggleDrawer = () => {
//Props to open/close the drawer
props.navigationProps.toggleDrawer();
};
return (
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity onPress={()=> toggleDrawer()}>
{/*Donute Button Image */}
<Image
source={{uri: 'https://raw.githubusercontent.com/AboutReact/sampleresource/master/drawerWhite.png'}}
style={{ width: 25, height: 25, marginLeft: 5 }}
/>
</TouchableOpacity>
</View>
);
}
function firstScreenStack({ navigation }) {
return (
<Stack.Navigator initialRouteName="FirstPage">
<Stack.Screen
name="FirstPage"
component={FirstPage}
options={{
title: 'First Page', //Set Header Title
headerLeft: ()=> <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#f4511e', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}
/>
</Stack.Navigator>
);
}
function secondScreenStack({ navigation }) {
return (
<Stack.Navigator initialRouteName="SecondPage">
<Stack.Screen
name="SecondPage"
component={SecondPage}
options={{
title: 'Second Page', //Set Header Title
headerLeft: ()=> <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#f4511e', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}
/>
</Stack.Navigator>
);
}
function thirdScreenStack({ navigation }) {
return (
<Stack.Navigator initialRouteName="ThirdPage">
<Stack.Screen
name="ThirdPage"
component={ThirdPage}
options={{
title: 'Third Page', //Set Header Title
headerLeft: ()=> <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#f4511e', //Set Header color
},
headerTintColor: '#fff', //Set Header text color
headerTitleStyle: {
fontWeight: 'bold', //Set Header text style
},
}}
/>
</Stack.Navigator>
);
}
function App() {
return (
<NavigationContainer>
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: '#e91e63',
itemStyle: { marginVertical: 5 },
}}>
<Drawer.Screen
name="FirstPage"
options={{ drawerLabel: 'First page Option' }}
component={firstScreenStack} />
<Drawer.Screen
name="SecondPage"
options={{ drawerLabel: 'Second page Option' }}
component={secondScreenStack} />
<Drawer.Screen
name="ThirdPage"
options={{ drawerLabel: 'Third page Option' }}
component={thirdScreenStack} />
</Drawer.Navigator>
</NavigationContainer>
);
}
export default App;
如果有人帮助我,将非常感激:)
解决方案
推荐阅读
- mysql - MySQL:UNION 加 JOIN
- reactjs - 使用 create-react-app 创建的 React 应用程序无法启动,返回错误
- excel - 在没有 Exit Sub 的情况下无法进入下一个
- python - 为什么在 django 中测试视图时会出现 404?
- excel - 比较不同工作表中的值(VBA/公式)
- model-view-controller - 如何使用 MVC 包装器将 TreeList 绑定到 MVC 模型类
- java - 网络文档的数字签名
- vue.js - v-for loop only array correspond to the dynamic page number
- neo4j - Neo4j var-length 路径搜索慢
- python - python 测试用例要模拟什么?