GithubHelp home page GithubHelp logo

react-native-popupwindow's Introduction

react-native-popupwindow npm version

Android used PopupWindow implementation of the iOS-style dialog box

Method

showPopupWindow(options,callback)

options : must be not null

  • windowColor : background color,default #50000000
  • style : show in activity center or bottom,default 0
  • 0 : show in center
  • 1 : show in bottom
  • margin : the distance from the screen
  • title : dialog title,default hide,only show when set value and style=0
  • titleTextSize : dialog title text size,default 17sp,only show when set value and style=0
  • titleTextColor : dialog title text color,only show when set value and style=0
  • single : only show when set value and style=0,default false
  • false : has two button(positive and negative)
  • true : single button(only has positive)
  • message : dialog message
  • messageTextSize : dialog message text size
  • messageTextColor : dialog message text color
  • positive : when style=0 and single=false,is left button、when single=true,only has this button; when style=1,is above button
  • positiveTextSize : positive button text size
  • positiveTextColor : positive button text color
  • negative : when style=0 and single=false,is right button、when single=true,this button will be hidden; when style=1,is below button
  • negativeTextSize : negative button text size
  • negativeTextColor : negative button text color

callback(err,action,button)

  • err : err message
  • action : return "buttonClicked"
  • button : return "positive" or "negative"

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

react-native-popupwindow's People

Contributors

shexiaoheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-popupwindow's Issues

新版本React Native里ReactActivity没有了getPackages方法

转移到了ReactApplication里的
public ReactNativeHost getReactNativeHost();
通过重载ReactNativeHost里的getPackages方法来加入包,比如

public class MainApplication implements ReactApplication {
...
    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        protected boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.asList(
                    new MainReactPackage(),
                    new XXXPackage()
            );
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }
...
}

然而这样就无法传递MainActivity的上下文。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.