Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

react-native-materialdialog-android

An AlertDialog for Android,followed Material Design,native code here.

Installation

npm install --save react-native-materialdialog-android

Add it to your android project

  • In android/setting.gradle
...
include ':app'
include ':AlertAndroid'
project(':AlertAndroid').projectDir =newFile(rootProject.projectDir, '../node_modules/react-native-materialdialog-android')
  • In android/app/build.gradle
...
dependencies {
...
compile project(':AlertAndroid')
}
  • register module (in MainActivity.java)
importcom.github.marsprince.alertAndroid.AlertAndroidPackage;; // <--- importpublicclassMainActivityextendsActivityimplementsDefaultHardwareBackBtnHandler {
......
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = newReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(newMainReactPackage())
.addPackage(newAlertAndroidPackage(this)) // <------ add here
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);
setContentView(mReactRootView);
}
......
}

Example

  • Basic:
varalert=require('react-native-materialdialog-android')alert.show("title","message","OK","Cancel")
  • More flexible:
varalert=require('react-native-materialdialog-android')varconfig={title:"title",message:"message",positiveButton:"OK",negativeButton:"Cancel",canceledOnTouchOutside:true}alert.showWithConfig(config)
  • Event listen:

There are some listeners which can be used:

positiveButtonClick

negativeButtonClick

onDismissListener

example:

DeviceEventEmitter.addListener('positiveButtonClick',function(e: Event){ToastAndroid.show("positiveButtonClick",ToastAndroid.SHORT)// handle event.});DeviceEventEmitter.addListener('negativeButtonClick',function(e: Event){ToastAndroid.show("negativeButtonClick",ToastAndroid.SHORT)// handle event.});DeviceEventEmitter.addListener('onDismissListener',function(e: Event){ToastAndroid.show("dismiss",ToastAndroid.SHORT)// handle event.});

Version

v1.0.0

License

MIT

About

A React Native materialDialog for Android.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages