react-native实现popwindow

本文介绍了如何利用React-native的modal组件实现popwindow和dialog效果。通过封装modal组件,详细阐述了创建过程,并提供了相关应用的实践说明。
摘要由CSDN通过智能技术生成

react实现popwindw,dialog效果都是通过一个modal组件来完成的,之前有写过关于modal的文章react-native modal链接,这篇只是对上一篇的应用.

1:首先封装modal组价

/**
 * Created by xq on 16/12/6.
 */
import React, { Component ,PropTypes} from 'react';
import {
    Text,
    View,
    TouchableOpacity,
    StyleSheet,
    Platform,
    Dimensions,
    Image,
    Modal,
    TextInput,
    InteractionManager
} from 'react-native';


export default class AlertModal extends Component{

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

    componentWillReceiveProps(props) {
        this.setState({ visible: props.visible });
    }

    close=()=>{
        requestAnimationFrame(()=>{
        if(this.props.close){
            // console.log("close","执行了父组件的close方法")
            this.props.close();
        }else{
            // console.log("close","执行本组件方法")
            this.setState({ visible: false });
        }
        })
    };

    renderContent=()=>{
        return (this.props.contentView);
    };

    render(){
        return(
            <Modal
                animationType={this.props.animation?this.props.animation:'slide'}//进场动画 fade
                onRequestClose={() => this.close()}
                visible={this.state.visible}//是否可见
                transparent={true} //背景透明
                 >
                <TouchableOpacity style={
  {flex:1}} activeOpacity={1} onPress={this.close}//点击灰色区域消失
                >
                <View style={[styles.container,this.props.customerlayout]}>
                    {this.renderContent()}
                </View>
                </TouchableOpacity>
            </Modal>
        )
    }
}

const styles = StyleSheet.create({
    container:{
        flex:1,
        backgroundColor: 'rgba(0, 0, 0, 0.25)',
        position: 'absolute',
        top: 0,
        bottom: 0,
        left: 0,
        right: 0,
        justifyContent:'center',
        alignItems:'center'
    },
    background: {
        backgroundColor: COLOR_BACKGROUND_GRAY,
        justifyContent: 'center',
        alignItems: 'center'
    }

})

2:使用封装好的组件

import React, { Component ,PropTypes} from 'react';
import {
    Alert,
    Text,
    View,
    TouchableOpacity,
    Navigator,
    StyleSheet,
    Platform,
    Dimensions,
    Image,
    ScrollView,
    TextInput,
    StatusBar
} from 'react-native';
import AppImage from "legentzest-appimage";
import HttpRequest from "legentzest-http_request";
import {Actions} from 'legendzest-flux';
import GraySplitLineView from "legentzest-graySplitLineView";
import Spinner from 'react-native-loading-spinner-overlay';
import Toast from 'react-native-root-toast';
import DeviceInfo from 'react-native-device-info';
import AlertModal from '../../common/AlertModal'; //引入modal组件
export default class SystemSetting extends Component{


    constructor(props){
        super(props);
        this.state = {
            visible:false,
            imageSetting:false,
            info:null,
        }
    }


    componentDidMount() {
        READ_CACHE("ispush",(res)=>{


           this.setState({
               is_push:res,
           })
        });


        READ_CACHE(&
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值