React Native Android module to use Android's AlertDialog - same idea of AlertIOS
npm install react-native-simpledialog-android


``bash`
npm install react-native-simpledialog-android --save
* In android/settings.gradle
`gradle`
...
include ':RNSimpleAlertDialogModule', ':app'
project(':RNSimpleAlertDialogModule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-simpledialog-android/android')
* In android/app/build.gradle
`gradle`
...
dependencies {
...
compile project(':RNSimpleAlertDialogModule')
}
* Register Module >= 0.17 && <= 0.29(in `MainActivity.java`)`
* NOTE: >= RN 29 split MainActivity.java` into `MainActivity.java` and`
MainApplication.java`. So make modifications below to `MainApplication.java`
`java
import com.burnweb.rnsimplealertdialog.RNSimpleAlertDialogPackage; // <--- import
public class MainApplication extends Application implements ReactApplication {
......
@Override
protected List
return Arrays.
new MainReactPackage(),
new RNSimpleAlertDialogPackage()); // <------ add this line to your MainApplication class
}
......
}
`
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.
javascript
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 },
]
);
``