typescript - React Navigation modal V6 with expo
问题描述
美好的一天,我尝试使用 react-navigation 6 来显示模式,使用docs上指定的presentation: "modal" 。但它没有给我想要的输出。模态不会显示为模态,而是显示为正常的导航屏幕。下面我以简单的方式重新创建了相同的问题。提前致谢 :)。
import React, { FC } from "react";
import { View, Text, TouchableOpacity, Button } from "react-native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { createMaterialBottomTabNavigator } from "@react-navigation/material-bottom-tabs";
interface Props {
// navigation :
}
const Tab = createMaterialBottomTabNavigator();
const Stack = createNativeStackNavigator();
const Home: FC = ({ navigation }) => {
return (
<View>
<Text>Welcome Home</Text>
<TouchableOpacity onPress={() => navigation.navigate("Details")}>
<Text>Move to Details without tabs</Text>
</TouchableOpacity>
</View>
);
};
const Details: FC = ({ navigation }) => {
return (
<View>
<Text>Welcome Details</Text>
<Button
onPress={() => navigation.navigate("MyModal")}
title="Open Modal"
/>
</View>
);
};
const ViewDetails: FC = (props: Props) => {
return (
<View>
<Text>Welcome ViewDetails</Text>
</View>
);
};
const Feed: FC = (props: Props) => {
return (
<View>
<Text>Welcome Feed</Text>
</View>
);
};
const Profile: FC = (props: Props) => {
return (
<View>
<Text>Welcome Profile</Text>
</View>
);
};
const HomeTab: FC = (props: Props) => {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Feed" component={Feed} />
<Tab.Screen name="Profile" component={Profile} />
</Tab.Navigator>
);
};
function ModalScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text style={{ fontSize: 30 }}>This is a modal!</Text>
<Button onPress={() => navigation.goBack()} title="Dismiss" />
</View>
);
}
const RootStackNavigator = (props: Props) => {
return (
<Stack.Navigator>
<Stack.Screen name="HomeTab" component={HomeTab} />
<Stack.Screen name="Details" component={Details} />
<Stack.Screen name="ViewDetails" component={ViewDetails} />
<Stack.Group screenOptions={{ presentation: "modal" }}>
<Stack.Screen name="MyModal" component={ModalScreen} />
</Stack.Group>
</Stack.Navigator>
);
};
export default RootStackNavigator;
please ignore the types as I purposely omitted them to quickly recreate this code snippet.
解决方案
我发现,如果你想创建完全隐藏标签栏的完整模式屏幕,你必须将它们分组到一个新组中。例如,
<Stack.Group screenOptions={{presentation: 'fullScreenModal'}}>
<Stack.Screen name="Modal" component={ModalScreen} />
</Stack.Group>
这个名为 Modalscreen 的特定屏幕将显示为一个完整的模式屏幕,为您隐藏标签栏。
推荐阅读
- php - 我正在尝试在启动时编写自定义 Laravel 函数,但出现错误
- c - 在 C 中释放具有清理属性的二维数组的通用函数
- python - 二维列表的总和
- windows-7 - 在 Windows 7 上运行 Postman 时出现黑窗
- php - 为什么我不能从管理员视图更新帖子元?
- javascript - 破解 AngularJS 表单元素以更改值
- javascript - 如何使用 chrome 配置文件“managed_javascript_blocked_for_urls”阻止第三方 JS
- r - 指定要在留一法(jack-knife)交叉验证中使用的选定数据范围,以便在 caret::train 函数中使用
- assembly - 大会 8086:如何通过循环和视频存储器表示感谢
- python-3.x - OSError: [WinError 10013] 在 PyCharm 环境中运行时,尝试以访问权限禁止的方式访问套接字