ReactNative-Modal(模态窗口)类似Android中PopupWindow弹窗

ReactNative中的Modal组件Android IOS都可使用

这里写图片描述

主要属性

  • visible 设置是否显示

  • animationType设置显示是的动画
    slide 从下往上滑动出现
    fade 慢慢显示
    none 没有动画 默认

  • transparent 设置是否透明默认是不透明

  • onRequestClose 关闭时调用此方法

  • onShow 显示时调用

/**
 * Created by Administrator on 2016/9/7.
 */
import React, {Component} from 'react';
import {
    AppRegistry,
    StyleSheet,
    View,
    Modal,
    Text,
} from 'react-native'

class ModalG extends Component {

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

    render() {
        return (
            <View style={{flex: 1, backgroundColor: 'green'}}>
                <Modal
                    visible={this.state.modalVisible}
                    //显示是的动画默认none
                    //从下面向上滑动slide
                    //慢慢显示fade
                    animationType = {'slide'}
                    //是否透明默认是不透明 false
                    transparent = {true}
                    //关闭时调用
                    onRequestClose={()=> this.onRequestClose()}
                >
                    <View style={{marginTop:100, marginLeft:100, width:100, height:100, backgroundColor:'red'}}>
                        <Text onPress={()=> this.setState({modalVisible: false})}>点击关闭Modal</Text>
                    </View>
                </Modal>

                <Text onPress={() => this.showModal()}>点击显示Modal</Text>

            </View>
        )
    }

    showModal() {
        this.setState({
            modalVisible: true
        })
    }

    onRequestClose() {
        this.setState({
            modalVisible: flase
        })
    }
}
module.exports = ModalG;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值