diff --git a/StatusPoC/App.js b/StatusPoC/App.js index bd4a931..76613a7 100644 --- a/StatusPoC/App.js +++ b/StatusPoC/App.js @@ -9,6 +9,7 @@ import React, { Component } from 'react' import { Platform, StyleSheet, Button, Text, View } from 'react-native' import ToastExample from './ToastExample' +import CustomDialog from './CustomDialog' const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', @@ -18,7 +19,8 @@ const instructions = Platform.select({ }); function showNativeDialog() { - ToastExample.show('Example toast', ToastExample.LONG) + ToastExample.show('Showing native dialog', ToastExample.SHORT) + CustomDialog.show() } type Props = {}; diff --git a/StatusPoC/CustomDialog.js b/StatusPoC/CustomDialog.js new file mode 100644 index 0000000..97ce28b --- /dev/null +++ b/StatusPoC/CustomDialog.js @@ -0,0 +1,10 @@ +/** + * This exposes the native ToastExample module as a JS module. This has a + * function 'show' which takes the following parameters: + * + * 1. String message: A string with the text to toast + * 2. int duration: The duration of the toast. May be ToastExample.SHORT or + * ToastExample.LONG + */ +import {NativeModules} from 'react-native'; +module.exports = NativeModules.CustomDialog; \ No newline at end of file diff --git a/StatusPoC/android/app/src/main/java/com/statuspoc/CustomDialogModule.java b/StatusPoC/android/app/src/main/java/com/statuspoc/CustomDialogModule.java new file mode 100644 index 0000000..dd958e5 --- /dev/null +++ b/StatusPoC/android/app/src/main/java/com/statuspoc/CustomDialogModule.java @@ -0,0 +1,24 @@ +// CustomDialogModule.java + +package com.statuspoc; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; + +public class CustomDialogModule extends ReactContextBaseJavaModule { + + public CustomDialogModule(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + public String getName() { + return "CustomDialog"; + } + + @ReactMethod + public void show() { + new FireMissilesDialogFragment().show(getReactApplicationContext().getCurrentActivity().getFragmentManager(), ""); + } +} diff --git a/StatusPoC/android/app/src/main/java/com/statuspoc/CustomDialogPackage.java b/StatusPoC/android/app/src/main/java/com/statuspoc/CustomDialogPackage.java new file mode 100644 index 0000000..fbc41a1 --- /dev/null +++ b/StatusPoC/android/app/src/main/java/com/statuspoc/CustomDialogPackage.java @@ -0,0 +1,30 @@ + +// CustomDialogPackage.java + +package com.statuspoc; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class CustomDialogPackage implements ReactPackage { + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules( + ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); + + modules.add(new CustomDialogModule(reactContext)); + + return modules; + } +} diff --git a/StatusPoC/android/app/src/main/java/com/statuspoc/FireMissilesDialogFragment.java b/StatusPoC/android/app/src/main/java/com/statuspoc/FireMissilesDialogFragment.java new file mode 100644 index 0000000..7e38191 --- /dev/null +++ b/StatusPoC/android/app/src/main/java/com/statuspoc/FireMissilesDialogFragment.java @@ -0,0 +1,28 @@ +package com.statuspoc; + +import android.app.AlertDialog; +import android.app.DialogFragment; +import android.app.Dialog; +import android.content.DialogInterface; +import android.os.Bundle; + +public class FireMissilesDialogFragment extends DialogFragment { + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use the Builder class for convenient dialog construction + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage("Fire missiles?") + .setPositiveButton("Fire!", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // FIRE ZE MISSILES! + } + }) + .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog + } + }); + // Create the AlertDialog object and return it + return builder.create(); + } +} \ No newline at end of file diff --git a/StatusPoC/android/app/src/main/java/com/statuspoc/MainApplication.java b/StatusPoC/android/app/src/main/java/com/statuspoc/MainApplication.java index 187ebaf..ebd5d08 100644 --- a/StatusPoC/android/app/src/main/java/com/statuspoc/MainApplication.java +++ b/StatusPoC/android/app/src/main/java/com/statuspoc/MainApplication.java @@ -23,6 +23,7 @@ public class MainApplication extends Application implements ReactApplication { protected List getPackages() { return Arrays.asList( new MainReactPackage(), + new CustomDialogPackage(), new CustomToastPackage() ); }