css - React-Native 中的双模态?
问题描述
我在尝试实现“双模态”时遇到了很多困难,即同时实现两个模态。
我正在使用“react-native-elements”库中的 Overlay 来实现模态效果,但是,将它们中的两个放在一个视图中是行不通的,因为它只会显示第一个。我还发现直接设置叠加层的高度没有任何效果。
然后我考虑创建一个自定义组件,但不知道如何使用 CSS 使背景变暗。
解决方案
如果需要,请将您的元素模式更改为 react-native-modal。继续尝试并执行以下代码。我希望它对你有用。
import Modal from 'react-native-modal';
const [isModalVisible, setModalVisible] = useState(false);
const toggleModal = () => {
setModalVisible(!isModalVisible);
};
<TouchableOpacity onPress={toggleModal}>
<Text>Button Text</Text>
<Modal
isVisible={isModalVisible}
onBackdropPress={() => setModalVisible(false)}>
<View style={{ backgroundColor: 'white', padding: 20, height:250 }}>
<Text>First box content appear here</Text>
</View>
<View style={{ backgroundColor: 'white', padding: 20, height:100, marginTop: 30 }}>
<Text>Second box content appear here</Text>
</View>
</Modal>
</TouchableOpacity>
推荐阅读
- oracle - oracle 工资单中按国家/地区的个人付款方式的银行详细信息
- firebase - 我可以在 firebase 文档字段中添加多个详细信息吗?
- ansible - 如何使用 Ansible consul_kv 向 Consul 添加新的键值对?
- android - Android Google Maps 卫星类型未加载
- mysql - MYSQL 存储过程未按预期运行
- r - 使用 rollRegres 中的 roll_regres 时出错:“宽度”上的断言失败
- elasticsearch - ElasticSearch - 按文档列值提升
- vue.js - 访问网络主机域不是ip
- c# - 控制器导致招摇的内部错误
- html - 工具提示仅在悬停时不显示