javascript - React Native - 浮动(或弹出)屏幕问题
问题描述
我正在尝试做类似最后一张图片的操作,该图片具有要添加到购物车且背景模糊的产品详细信息
有没有办法在反应导航中制作浮动屏幕?
我正在寻找可能与它相似的东西,我并不真正关心其中的内容,只是一般的屏幕弹出窗口
我不知道它是怎么称呼的,所以给我指明一个研究方向或只是命名它,这样我就可以谷歌了,非常感谢
解决方案
它叫做 Modal,你可以使用 React Native 的组件来呈现它。检查官方文档https://reactnative.dev/docs/modal
对于模糊部分,您可以使用此库https://github.com/Kureev/react-native-blur
这是显示模态的示例代码:
import React, { useState } from "react";
import { Alert, Modal, StyleSheet, Text, Pressable, View } from "react-native";
const App = () => {
const [modalVisible, setModalVisible] = useState(false);
return (
<View style={styles.centeredView}>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert("Modal has been closed.");
setModalVisible(!modalVisible);
}}
>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Text style={styles.modalText}>Hello World!</Text>
<Pressable
style={[styles.button, styles.buttonClose]}
onPress={() => setModalVisible(!modalVisible)}
>
<Text style={styles.textStyle}>Hide Modal</Text>
</Pressable>
</View>
</View>
</Modal>
<Pressable
style={[styles.button, styles.buttonOpen]}
onPress={() => setModalVisible(true)}
>
<Text style={styles.textStyle}>Show Modal</Text>
</Pressable>
</View>
);
};
const styles = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: "center",
alignItems: "center",
marginTop: 22
},
modalView: {
margin: 20,
backgroundColor: "white",
borderRadius: 20,
padding: 35,
alignItems: "center",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5
},
button: {
borderRadius: 20,
padding: 10,
elevation: 2
},
buttonOpen: {
backgroundColor: "#F194FF",
},
buttonClose: {
backgroundColor: "#2196F3",
},
textStyle: {
color: "white",
fontWeight: "bold",
textAlign: "center"
},
modalText: {
marginBottom: 15,
textAlign: "center"
}
});
export default App;
推荐阅读
- python-3.x - 使用动态整数进行循环分页
- javascript - 几秒钟后手风琴项目消失
- mysql - MySQL 检查数据是否存在
- php - 尝试执行 PHP 请求时出现 Google Webmaster Tool API 错误
- python - 运行更新时的Python Sqlite3 OperationalError
- html - SAS、ODS HTML、重置 ODS
- c++ - 在构建 boost 时静态链接 openssl
- java - 直接使用 Java NIO 和 Netty 的 Heroku H15 错误
- javascript - 如何使图像隐藏然后在特定时间出现
- javascript - 向 Google 表格中的自定义函数添加多个参数