Skip to content

marsprince/react-native-materialDialogAndroid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 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 = new File(rootProject.projectDir, '../node_modules/react-native-materialdialog-android')
  • In android/app/build.gradle
...
dependencies {
    ...
    compile project(':AlertAndroid')
}
  • register module (in MainActivity.java)
import com.github.marsprince.alertAndroid.AlertAndroidPackage;;  // <--- import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
  ......

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mReactRootView = new ReactRootView(this);

    mReactInstanceManager = ReactInstanceManager.builder()
      .setApplication(getApplication())
      .setBundleAssetName("index.android.bundle")
      .setJSMainModuleName("index.android")
      .addPackage(new MainReactPackage())
      .addPackage(new AlertAndroidPackage(this))            // <------ add here
      .setUseDeveloperSupport(BuildConfig.DEBUG)
      .setInitialLifecycleState(LifecycleState.RESUMED)
      .build();

    mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);

    setContentView(mReactRootView);
  }

  ......

}

Example

  • Basic:
var alert=require('react-native-materialdialog-android')

alert.show("title","message","OK","Cancel")
  • More flexible:
var alert=require('react-native-materialdialog-android')

var config={
            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

License

Stars

Watchers

Forks

Releases

No releases published

Packages