react native Modal 使用详解

Modal 是可以覆盖在原生视图上。
属性:

animationType:显示和隐藏的动画

  • slide:从底部弹出
  • fade:渐隐渐显
  • none:无

onRequestClose:android 按返回键时回调。
onShow:modal显示时回调。
transparent:背景是否透明,默认为白色。
visible:是否显示。

/**
 * Created by on 2017/5/8.
 */
import React, {Component} from 'react';
import {
    StyleSheet,
    View,
    Modal,
    Button,
    Alert,
} from 'react-native';

export default class ModalDemo extends Component {

    static navigationOptions = {
        title: 'Modal',
    };

    state = {
        visible: false,
        transparent: true,
    }

    render() {
        return (
            <View style={{flex:1}}>

                <Button title='显示Modal' onPress={()=>{this.setState({visible:true})}}/>
                <Modal
                    visible={this.state.visible}
                    transparent={this.state.transparent}
                    onRequestClose={()=>{
                        Alert.alert("Modal has been closed.");
                    }}
                    onShow={()=>{
                        Alert.alert("Modal has been show.");
                    }}>
                    <View
                        style={{flex:1,justifyContent:'center',alignItems:'center',backgroundColor:'rgba(0, 0, 0, 0.3)'}}>
                        <View style={{height:200,width:275,backgroundColor:'white'}}>
                            <Button title='关闭Modal' onPress={()=>{this.setState({visible:false})}}/>
                            <Button title={this.state.transparent?'不透明':'透明'} onPress={()=>{this.setState({transparent:!this.state.transparent})}}/>
                        </View>
                    </View>
                </Modal>
            </View>
        );
    }
}

这里写图片描述

github下载地址

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老孟Flutter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值