react-native - react-native:是否有可能为网站提供 react-native 侧边栏?
问题描述
我使用 Drawer.Navigator 测试了一个导航示例,例如带有 react-native 的侧边栏
例子:
<Drawer.Navigator
drawerContentOptions={{
activeTintColor: '#e91e63',
itemStyle: { marginVertical: 5 },
}}
drawerContent={(props) => <CustomSidebarMenu {...props} />}>
<Drawer.Screen
name="FirstPage"
options={{ drawerLabel: 'First page Option' }}
component={firstScreenStack}
/>
<Drawer.Screen
name="SecondPage"
options={{ drawerLabel: 'Second page Option' }}
component={secondScreenStack}
/>
</Drawer.Navigator>
我的自定义边栏:
import React from 'react';
import {
SafeAreaView,
View,
StyleSheet,
Image,
Text,
Linking,
} from 'react-native';
import {
DrawerContentScrollView,
DrawerItemList,
DrawerItem,
} from '@react-navigation/drawer';
const CustomSidebarMenu = (props) => {
const BASE_PATH =
'https://raw.githubusercontent.com/AboutReact/sampleresource/master/';
const proileImage = 'react_logo.png';
return (
<SafeAreaView style={{ flex: 1 }}>
{/*Top Large Image */}
<Image
source={{ uri: BASE_PATH + proileImage }}
style={styles.sideMenuProfileIcon}
/>
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<DrawerItem
label="Visit Us"
onPress={() => Linking.openURL('https://aboutreact.com/')}
/>
<View style={styles.customItem}>
<Text
onPress={() => {
Linking.openURL('https://aboutreact.com/');
}}>
Rate Us
</Text>
<Image
source={{ uri: BASE_PATH + 'star_filled.png' }}
style={styles.iconStyle}
/>
</View>
</DrawerContentScrollView>
<Text style={{ fontSize: 16, textAlign: 'center', color: 'grey' }}>
www.aboutreact.com
</Text>
</SafeAreaView>
);
};
如果我为 web 构建,结果对 web 不利。
我找不到在 web.xml 中调整它的解决方案。在同一索引中打开侧边栏。这不是一个好的做法,但也许这是不可能的。有人有同样的问题吗?
提前致谢
解决方案
React Navigation 让您可以选择使用组件中的drawerType 属性来决定您想要哪种类型的抽屉Drawer
。
您可以添加一些逻辑来更改drawerType
基于平台的值,您应该能够实现您想要的
推荐阅读
- java - 我的问题是当我按下清除按钮时,它只是清除文本字段而不是之前按下的数字的数据
- jquery - EJS MongoDb 拉取数组中的项目
- assembly - 为什么 %cl 是 sal 操作将接受作为参数的唯一寄存器?
- elasticsearch - Elasticsearch 查询嵌套文档并在聚合期间使用嵌套文档分数进行排序
- vba - 删除自动创建的附加换行符
- python - Tkinter:如何使用单独的窗口通过按钮要求用户输入并将该值返回给原始函数
- java - 使用 oauth2Login 添加基本身份验证
- api - 在 API-REST/Kubernetes 场景中,如何以面向消息代理的方式处理订阅中的事件传入?
- c++ - 在 C++ 中,调用派生构造函数是否会创建一个基对象?
- python - 二进制 DataFrame 到字典