Home

Awesome

react-native-popupwindow npm version

Android used PopupWindow implementation of the iOS-style dialog box

简体中文

Method

showPopupWindow(options,callback)

options : must be not null

callback(err,action,button)

Install And Use

Npm Install

$ npm install --save react-native-popupwindow

Add Link

$ react-native link react-native-popupwindow

Use

import React, { Component } from 'react';

import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  ToastAndroid
} from 'react-native';

import MyPop from 'react-native-popupwindow';

let options = {
};

class PopupWindow extends Component {
  center(){
    options.style = 0;
    MyPop.showPopupWindow(options,(err,action,button) =>{
          if(err){
            ToastAndroid.show(err,ToastAndroid.SHORT);
          }else{
            if(action === 'buttonClicked'){
                if(button === 'positive'){
                  ToastAndroid.show('click ok',ToastAndroid.SHORT);
                }else if(button === 'negative'){
                  ToastAndroid.show('click cancel',ToastAndroid.SHORT);
                }
            }
          }
      });
  }
  bottom(){
    options.style = 1;
    MyPop.showPopupWindow(options,(err,action,button) =>{
          if(err){
            ToastAndroid.show(err,ToastAndroid.SHORT);
          }else{
            if(action === 'buttonClicked'){
                if(button === 'positive'){
                  ToastAndroid.show('click ok',ToastAndroid.SHORT);
                }else if(button === 'negative'){
                  ToastAndroid.show('click cancel',ToastAndroid.SHORT);
                }
            }
          }
      });
  }
  render() {
    return (
        <View style={styles.container}>
          <Text style={styles.welcome} onPress={this.center}>
              show in center
           </Text>
          <Text style={styles.welcome} onPress={this.bottom}>
              show in bottom
          </Text>
        </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

AppRegistry.registerComponent('PopupWindow', () => PopupWindow);

Run Renderings

rendering