Skip to content

React Native Android module to use Android's AlertDialog - same idea of AlertIOS

Notifications You must be signed in to change notification settings

wookiem/react-native-simpledialog-android

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-simpledialog-android

React Native Android module to use Android's AlertDialog - same idea of AlertIOS

npm version npm downloads npm licence

Installation

npm install react-native-simpledialog-android --save

Add it to your android project

  • In android/setting.gradle
...
include ':RNSimpleAlertDialogModule', ':app'
project(':RNSimpleAlertDialogModule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-simpledialog-android')
  • In android/app/build.gradle
...
dependencies {
    ...
    compile project(':RNSimpleAlertDialogModule')
}
  • Register Module >= 0.17 (in MainActivity.java)
import com.burnweb.rnsimplealertdialog.RNSimpleAlertDialogPackage;  // <--- import

public class MainActivity extends ReactActivity {
  ......

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new RNSimpleAlertDialogPackage()); // <------ add this line to your MainActivity class
  }

  ......

}

Usage

This module are very similar to AlertIOS native module, and only works with alert method (prompt method aren't implemented yet).

The main difference are in the way that you declare buttons. In Android you can declare up to 3 buttons and in this module you have to declare what type the button is. A button can be SimpleAlert.POSITIVE_BUTTON, SimpleAlert.NEGATIVE_BUTTON or SimpleAlert.NEUTRAL_BUTTON.

Example

var SimpleAlert = require('react-native-simpledialog-android');

function _onPress(event) {
    console.log(event);
};

SimpleAlert.alert(
    'Please read me!',
    'Want a warning alert?', [
      { type: SimpleAlert.POSITIVE_BUTTON, text: 'Yes', onPress: _onPress },
      { type: SimpleAlert.NEGATIVE_BUTTON, text: 'No', onPress: _onPress },
      { type: SimpleAlert.NEUTRAL_BUTTON, text: 'Neutral', onPress: _onPress },
    ]
);

License

MIT

About

React Native Android module to use Android's AlertDialog - same idea of AlertIOS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 73.0%
  • JavaScript 27.0%