react-native Modal使用

import {
Modal,
Text,
Image,
TouchableHighlight,
View,
StyleSheet,
ScrollView,
TouchableOpacity
} from 'react-native';

var width = require("Dimensions").get('window').width;
var height = require("Dimensions").get('window').height;

export default class ModalExample extends Component {

constructor(props) {
super(props);
this.state = {
modalVisible: false
};
}

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

render() {
return (
<View style={styles.container}>

    <Modal animationType={"slide"} transparent={true} //false彈出整頁(yè)/true彈出浮出窗口
      visible={this.state.modalVisible} onRequestClose={() => {
      alert("Modal has been closed.")
    }}>
      <View style={styles.tView}>
        <View style={styles.Viewone}>
          <View style={styles.ttextView}>
            <Text style={styles.text}>請(qǐng)選擇</Text>
          </View>

          <TouchableHighlight onPress={() => {
            this.setModalVisible(!this.state.modalVisible)
          }} style={styles.textView}>
            <Text style={styles.text}>打開(kāi)相機(jī)</Text>

          </TouchableHighlight>

          <TouchableHighlight onPress={() => {
            this.setModalVisible(!this.state.modalVisible)
          }} style={styles.textView}>
            <Text style={styles.text}>打開(kāi)相冊(cè)</Text>

          </TouchableHighlight>

          <TouchableHighlight onPress={() => {
            this.setModalVisible(!this.state.modalVisible)
          }} style={styles.textView}>
            <Text style={styles.text}>取消</Text>

          </TouchableHighlight>

        </View>
      </View>
    </Modal>

    <ScrollView>
      <View style={styles.photoView}>
        <TouchableOpacity style={styles.imageView} onPress={() => {
          this.setModalVisible(true)
        }}>
          <View style={styles.ImageView}>
            <Image source={require('../image/sczp.png')} style={styles.Image}/>
          </View>
          <Text style={styles.photoTxte}>上傳照片</Text>
        </TouchableOpacity>
      </View>
    </ScrollView>

  </View>
);

}
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff', //#F0F0F0
},
tView: {
width: width,
height: 300,
marginTop: 200,
backgroundColor: "#999"
},
Viewone: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
},
ttextView: {
marginBottom: 30
},
text: {
fontSize: 20
},
textView: {
width: width0.6,
height: 60,
borderTopWidth: 1,
borderColor: "#999",
borderStyle: "solid",
alignItems: "center",
justifyContent: "center"
},
//相冊(cè)整塊View
photo: {
flexDirection: "row",
flexWrap: "wrap",
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "space-between", //space-around
},
//相冊(cè)單個(gè)View
photoView: {
marginBottom: 1,
backgroundColor: "#F0F0F0"
},
imageView: {
width: width
0.994 / 3,
height: 120,
borderColor: "#999",
borderStyle: "dashed", //solid-dashed-dotted
borderWidth: 1,
alignItems: "center",
justifyContent: "center"
},
//相冊(cè)圖片
photoImage: {
width: width*0.994 / 3,
height: 120,
alignItems: "center",
justifyContent: "center"
},
ImageView: {
width: 60,
height: 60,
borderRadius: 5,
alignItems: "center",
},
//上傳照片圖片
Image: {
width: 50,
height: 50,
borderRadius: 5,
alignItems: "center",
justifyContent: "center"
},
//上傳照片文字
photoTxte: {
color: "#999",
fontSize: 12
}
});

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 前言 學(xué)習(xí)本系列內(nèi)容需要具備一定 HTML 開(kāi)發(fā)基礎(chǔ),沒(méi)有基礎(chǔ)的朋友可以先轉(zhuǎn)至 HTML快速入門(mén)(一) 學(xué)習(xí) 本人...
    珍此良辰閱讀 4,662評(píng)論 2 19
  • 在React-Native中使用flexbox規(guī)則來(lái)指定某個(gè)組件的子元素的布局。Flexbox可以在不同屏幕尺寸上...
    Coder_Answer閱讀 1,637評(píng)論 1 2
  • 前言 學(xué)習(xí)本系列內(nèi)容需要具備一定 HTML 開(kāi)發(fā)基礎(chǔ),沒(méi)有基礎(chǔ)的朋友可以先轉(zhuǎn)至 HTML快速入門(mén)(一) 學(xué)習(xí) 本人...
    珍此良辰閱讀 20,822評(píng)論 15 16
  • 1、ReactNative中能使用的css樣式 "alignItems","alignSelf","backfac...
    babybus_superdo閱讀 1,059評(píng)論 0 1
  • 琉璃燈火,守十年亡魂,塵囂猶在,誰(shuí)又能傲視蒼生。 茶未涼,墨未干,你離去的身影,又能走多遠(yuǎn)。 浮生一幕,黃粱一夢(mèng),...
    何起弦月閱讀 517評(píng)論 0 0

友情鏈接更多精彩內(nèi)容