gpt4 book ai didi

javascript - 如何在 react native 中单击按钮打开 react native 模式?

转载 作者:太空宇宙 更新时间:2023-11-04 15:25:21 25 4
gpt4 key购买 nike

我是 native react 新手,我正在尝试在单击按钮时打开模式。我正在尝试使用以下代码打开模式:-

  openHeaderModal = () => {
<ModalDropdown
options={["H1", "H2", "H3"]}
dropdownStyle={{
borderRadius: 6,
backgroundColor: "#26344a",
shadowColor: "rgba(0, 0, 0, 0.2)",
shadowOffset: {
width: 0,
height: 5
},
shadowRadius: 20,
shadowOpacity: 1,
padding: 8
}}
dropdownTextStyle={{
fontFamily: "poppins-500",
fontSize: 16,
fontStyle: "normal",
letterSpacing: 0,
textAlign: "left",
color: "#ffffff",
backgroundColor: "#26344a"
}}
>
</ModalDropdown>
}

我正在使用react-native-modal-dropdown作为模式。以下是我的按钮 jsx 代码:-

  <Button onPress={() => this.openHeaderModal()} vertical>
<Image
style={{ marginTop: 20 }}
source={require("../assets/heading.png")}
/>
</Button>

感谢任何帮助和支持。谢谢。

最佳答案

我认为在react-native中打开一个Modal非常简单,简单的例子:

import React, {Component} from 'react';
import {Modal, Text, TouchableHighlight, View} from 'react-native';

class ModalExample extends Component {
state = {
modalVisible: false,
};

setModalVisible(visible) {
this.setState({modalVisible: visible});
}

render() {
return (
<View style={{marginTop: 22}}>
<Modal
animationType="slide"
transparent={false}
visible={this.state.modalVisible}
onRequestClose={() => {
alert('Modal has been closed.');
}}>
<View style={{marginTop: 22}}>
<View>
<Text>Hello World!</Text>

<TouchableHighlight
onPress={() => {
this.setModalVisible(!this.state.modalVisible);
}}>
<Text>Hide Modal</Text>
</TouchableHighlight>
</View>
</View>
</Modal>

<TouchableHighlight
onPress={() => {
this.setModalVisible(true);
}}>
<Text>Show Modal</Text>
</TouchableHighlight>
</View>
);
}
}

链接:https://facebook.github.io/react-native/docs/modal.html#docsNav

如果你想使用库:https://github.com/react-native-community/react-native-modal

关于javascript - 如何在 react native 中单击按钮打开 react native 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50941538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com