mirror of
https://github.com/status-im/poc-core-secure-react-native.git
synced 2025-02-19 21:38:27 +00:00
Show native dialog
This commit is contained in:
parent
5f76085a3c
commit
183a4a2ffb
@ -9,6 +9,7 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Platform, StyleSheet, Button, Text, View } from 'react-native'
|
import { Platform, StyleSheet, Button, Text, View } from 'react-native'
|
||||||
import ToastExample from './ToastExample'
|
import ToastExample from './ToastExample'
|
||||||
|
import CustomDialog from './CustomDialog'
|
||||||
|
|
||||||
const instructions = Platform.select({
|
const instructions = Platform.select({
|
||||||
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
|
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
|
||||||
@ -18,7 +19,8 @@ const instructions = Platform.select({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function showNativeDialog() {
|
function showNativeDialog() {
|
||||||
ToastExample.show('Example toast', ToastExample.LONG)
|
ToastExample.show('Showing native dialog', ToastExample.SHORT)
|
||||||
|
CustomDialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
type Props = {};
|
type Props = {};
|
||||||
|
10
StatusPoC/CustomDialog.js
Normal file
10
StatusPoC/CustomDialog.js
Normal file
@ -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;
|
@ -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(), "");
|
||||||
|
}
|
||||||
|
}
|
@ -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<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<NativeModule> createNativeModules(
|
||||||
|
ReactApplicationContext reactContext) {
|
||||||
|
List<NativeModule> modules = new ArrayList<>();
|
||||||
|
|
||||||
|
modules.add(new CustomDialogModule(reactContext));
|
||||||
|
|
||||||
|
return modules;
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ public class MainApplication extends Application implements ReactApplication {
|
|||||||
protected List<ReactPackage> getPackages() {
|
protected List<ReactPackage> getPackages() {
|
||||||
return Arrays.<ReactPackage>asList(
|
return Arrays.<ReactPackage>asList(
|
||||||
new MainReactPackage(),
|
new MainReactPackage(),
|
||||||
|
new CustomDialogPackage(),
|
||||||
new CustomToastPackage()
|
new CustomToastPackage()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user