Added examples for implemented features
This commit is contained in:
parent
2fb53a34b1
commit
faf2f5f047
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* @providesModule DialogAndroid
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var { NativeModules } = require('react-native');
|
||||
|
||||
var callbackNames = [
|
||||
'onPositive',
|
||||
'onNegative',
|
||||
'onNeutral',
|
||||
'onAny',
|
||||
'itemsCallback',
|
||||
'itemsCallbackSingleChoice',
|
||||
'itemsCallbackMultiChoice',
|
||||
'showListener',
|
||||
'cancelListener',
|
||||
'dismissListener',
|
||||
];
|
||||
|
||||
class DialogAndroid {
|
||||
constructor() {
|
||||
this.options = {};
|
||||
}
|
||||
|
||||
set(obj) {
|
||||
Object.assign(this.options, obj);
|
||||
}
|
||||
|
||||
show() {
|
||||
var finalOptions = Object.assign({}, this.options);
|
||||
|
||||
var callbacks = {
|
||||
error: (err, op) => console.error(err, op),
|
||||
}
|
||||
|
||||
callbackNames.forEach(cb => {
|
||||
if (cb in finalOptions) {
|
||||
callbacks[cb] = finalOptions[cb];
|
||||
finalOptions[cb] = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Handle special case of input separately
|
||||
if ('input' in finalOptions) {
|
||||
finalOptions.input = Object.assign({}, finalOptions.input);
|
||||
var inputCallback = finalOptions.input.callback || (x => console.log(x));
|
||||
finalOptions.input.callback = true;
|
||||
}
|
||||
|
||||
// Parse the result form multiple choice dialog
|
||||
if ('itemsCallbackMultiChoice' in callbacks) {
|
||||
var originalCallback = callbacks.itemsCallbackMultiChoice;
|
||||
callbacks.itemsCallbackMultiChoice = selected => {
|
||||
var indices = selected.split(',').map(x => parseInt(x));
|
||||
var elements = indices.map(ind => (finalOptions.items || [])[ind]);
|
||||
|
||||
originalCallback(indices, elements);
|
||||
}
|
||||
}
|
||||
|
||||
var callbackFunc = (cb, ...rest) => callbacks[cb](...rest);
|
||||
|
||||
NativeModules.DialogAndroid.show(finalOptions, callbackFunc);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DialogAndroid;
|
|
@ -2,7 +2,7 @@ package com.aakashns.reactnativedialogs;
|
|||
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import com.aakashns.reactnativedialogs.modules.SimpleDialogModule;
|
||||
import com.aakashns.reactnativedialogs.modules.DialogAndroid;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
|
@ -23,7 +23,7 @@ public class ReactNativeDialogsPackage implements ReactPackage {
|
|||
public List<NativeModule> createNativeModules(
|
||||
ReactApplicationContext reactContext) {
|
||||
List<NativeModule> modules = new ArrayList<>();
|
||||
modules.add(new SimpleDialogModule(reactContext, mActivity));
|
||||
modules.add(new DialogAndroid(reactContext, mActivity));
|
||||
return modules;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,361 @@
|
|||
package com.aakashns.reactnativedialogs.modules;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.ReadableMapKeySeyIterator;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
import com.facebook.react.bridge.WritableNativeArray;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class DialogAndroid extends ReactContextBaseJavaModule {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "DialogAndroid";
|
||||
}
|
||||
|
||||
FragmentActivity mActivity;
|
||||
|
||||
public DialogAndroid(
|
||||
ReactApplicationContext reactContext,
|
||||
FragmentActivity fragmentActivity) {
|
||||
super(reactContext);
|
||||
mActivity = fragmentActivity;
|
||||
}
|
||||
|
||||
// static Set<String> blacklist = new HashSet<>(Arrays.<String>asList(
|
||||
// "items",
|
||||
// "itemsCallback",
|
||||
// "choice",
|
||||
// "selectedIndex"
|
||||
// ));
|
||||
|
||||
|
||||
private MaterialDialog.Builder applyOptions(
|
||||
MaterialDialog.Builder builder,
|
||||
ReadableMap options
|
||||
) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
ReadableMapKeySeyIterator iterator = options.keySetIterator();
|
||||
while(iterator.hasNextKey()) {
|
||||
String key = iterator.nextKey();
|
||||
|
||||
switch (key) {
|
||||
case "title":
|
||||
builder.title(options.getString("title"));
|
||||
break;
|
||||
case "content":
|
||||
builder.content(options.getString("content"));
|
||||
break;
|
||||
case "positiveText":
|
||||
builder.positiveText(options.getString("positiveText"));
|
||||
break;
|
||||
case "negativeText":
|
||||
builder.negativeText(options.getString("negativeText"));
|
||||
break;
|
||||
case "neutralText":
|
||||
builder.neutralText(options.getString("neutralText"));
|
||||
break;
|
||||
case "items":
|
||||
ReadableArray arr = options.getArray("items");
|
||||
String[] items = new String[arr.size()];
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
items[i] = arr.getString(i);
|
||||
}
|
||||
builder.items(items);
|
||||
break;
|
||||
case "autoDismiss":
|
||||
builder.autoDismiss(options.getBoolean("autoDismiss"));
|
||||
break;
|
||||
case "forceStacking":
|
||||
builder.forceStacking(options.getBoolean("forceStacking"));
|
||||
break;
|
||||
case "alwaysCallSingleChoiceCallback":
|
||||
if (options.getBoolean("alwaysCallSingleChoiceCallback")) {
|
||||
builder.alwaysCallSingleChoiceCallback();
|
||||
}
|
||||
break;
|
||||
case "alwaysCallMultiChoiceCallback":
|
||||
if (options.getBoolean("alwaysCallMultiChoiceCallback")) {
|
||||
builder.alwaysCallMultiChoiceCallback();
|
||||
}
|
||||
break;
|
||||
case "alwaysCallInputCallback":
|
||||
if (options.getBoolean("alwaysCallInputCallback")) {
|
||||
builder.alwaysCallInputCallback();
|
||||
}
|
||||
break;
|
||||
case "cancelable":
|
||||
builder.cancelable(options.getBoolean("cancelable"));
|
||||
break;
|
||||
case "progressIndeterminateStyle": // true for horizontal, DO NOT USE
|
||||
builder.progressIndeterminateStyle(
|
||||
options.getBoolean("progressIndeterminateStyle"));
|
||||
break;
|
||||
case "progress":
|
||||
ReadableMap progress = options.getMap("progress");
|
||||
boolean indeterminate = progress.hasKey("indeterminate") &&
|
||||
progress.getBoolean("indeterminate");
|
||||
|
||||
if (indeterminate) {
|
||||
builder.progress(true, 0);
|
||||
boolean horizontal = progress.hasKey("style") &&
|
||||
progress.getString("style").equals("horizontal");
|
||||
if (horizontal) builder.progressIndeterminateStyle(horizontal);
|
||||
} else {
|
||||
// Determinate progress bar not supported currently
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void show(ReadableMap options, final Callback callback) {
|
||||
MaterialDialog.Builder builder = new MaterialDialog.Builder(mActivity);
|
||||
try {
|
||||
applyOptions(builder, options);
|
||||
} catch (Exception e) {
|
||||
callback.invoke("error", e.getMessage(), options.toString());
|
||||
}
|
||||
|
||||
if (options.hasKey("onPositive")) {
|
||||
builder.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
callback.invoke("onPositive");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("onNegative")) {
|
||||
builder.onNegative(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
callback.invoke("onNegative");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("onNeutral")) {
|
||||
builder.onNeutral(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
callback.invoke("onNeutral");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("onAny")) {
|
||||
builder.onAny(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
callback.invoke("onAny");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("itemsCallback")) {
|
||||
builder.itemsCallback(new MaterialDialog.ListCallback() {
|
||||
@Override
|
||||
public void onSelection(MaterialDialog materialDialog, View view, int i,
|
||||
CharSequence charSequence) {
|
||||
callback.invoke("itemsCallback", i, charSequence.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("itemsCallbackSingleChoice")) {
|
||||
int selectedIndex = options.hasKey("selectedIndex") ?
|
||||
options.getInt("selectedIndex") : -1;
|
||||
builder.itemsCallbackSingleChoice(selectedIndex,
|
||||
new MaterialDialog.ListCallbackSingleChoice() {
|
||||
@Override
|
||||
public boolean onSelection(MaterialDialog materialDialog, View view, int i,
|
||||
CharSequence charSequence) {
|
||||
callback.invoke("itemsCallbackSingleChoice", i, charSequence.toString());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("itemsCallbackMultiChoice")) {
|
||||
Integer[] selectedIndices = null;
|
||||
if (options.hasKey("selectedIndices")) {
|
||||
ReadableArray arr = options.getArray("selectedIndices");
|
||||
selectedIndices = new Integer[arr.size()];
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
selectedIndices[i] = arr.getInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
builder.itemsCallbackMultiChoice(selectedIndices,
|
||||
new MaterialDialog.ListCallbackMultiChoice() {
|
||||
@Override
|
||||
public boolean onSelection(MaterialDialog materialDialog,
|
||||
Integer[] integers, CharSequence[] charSequences) {
|
||||
StringBuilder selected = new StringBuilder("");
|
||||
for (int i = 0; i < integers.length - 1; i++) {
|
||||
selected.append(integers[i]).append(",");
|
||||
}
|
||||
if (integers.length > 0) {
|
||||
selected.append(integers[integers.length - 1]);
|
||||
}
|
||||
|
||||
callback.invoke("itemsCallbackMultiChoice", selected.toString());
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (options.hasKey("multiChoiceClearButton") &&
|
||||
options.getBoolean("multiChoiceClearButton")) {
|
||||
builder.neutralText("Clear").onNeutral(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
materialDialog.clearSelectedIndices();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (options.hasKey("showListener")) {
|
||||
builder.showListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
callback.invoke("showListener");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("cancelListener")) {
|
||||
builder.cancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
callback.invoke("cancelListener");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("dismissListener")) {
|
||||
builder.dismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
callback.invoke("dismissListener");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (options.hasKey("input")) {
|
||||
ReadableMap input = options.getMap("input");
|
||||
String hint = input.hasKey("hint") ? input.getString("hint") : null;
|
||||
String prefill = input.hasKey("prefill") ? input.getString("prefill") : null;
|
||||
boolean allowEmptyInput = !input.hasKey("allowEmptyInput") ||
|
||||
input.getBoolean("allowEmptyInput");
|
||||
|
||||
if (input.hasKey("type")) {
|
||||
builder.inputType(input.getInt("type"));
|
||||
}
|
||||
|
||||
int minLength = input.hasKey("minLength") ? input.getInt("minLength") : 0;
|
||||
int maxLength = input.hasKey("maxLength") ? input.getInt("maxLength") : -1;
|
||||
|
||||
builder.inputRange(minLength, maxLength);
|
||||
|
||||
builder.input(hint, prefill, allowEmptyInput, new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
|
||||
callback.invoke("input", charSequence.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
builder.show();
|
||||
}
|
||||
|
||||
// @ReactMethod
|
||||
// public void showItemsDialog(
|
||||
// ReadableMap options,
|
||||
// final Callback itemsCallback,
|
||||
// final Callback errorCallback) {
|
||||
// MaterialDialog.Builder builder = new MaterialDialog.Builder(mActivity);
|
||||
// try {
|
||||
// builder = applyOptions(builder, options);
|
||||
// boolean choice = options.hasKey("choice") && options.getBoolean("choice");
|
||||
//
|
||||
// int selectedIndex = options.hasKey("selectedIndex") ?
|
||||
// options.getInt("selectedIndex") : -1;
|
||||
//
|
||||
// if (itemsCallback != null) {
|
||||
// if (choice) {
|
||||
// builder.itemsCallbackSingleChoice(selectedIndex,
|
||||
// new MaterialDialog.ListCallbackSingleChoice() {
|
||||
// @Override
|
||||
// public boolean onSelection(MaterialDialog materialDialog, View view, int i,
|
||||
// CharSequence charSequence) {
|
||||
// itemsCallback.invoke(i);
|
||||
// return true;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// errorCallback.invoke(e.getMessage(), options.toString());
|
||||
// }
|
||||
// builder.show();
|
||||
// }
|
||||
//
|
||||
// @ReactMethod
|
||||
// public void showBasicDialog(
|
||||
// ReadableMap options,
|
||||
// final Callback positiveCallback,
|
||||
// final Callback negativeCallback,
|
||||
// final Callback errorCallback) {
|
||||
// MaterialDialog.Builder builder = new MaterialDialog.Builder(mActivity);
|
||||
//
|
||||
// try {
|
||||
// builder = applyOptions(builder, options);
|
||||
// if (positiveCallback != null) {
|
||||
// builder.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
// @Override
|
||||
// public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
// positiveCallback.invoke();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// if (negativeCallback != null) {
|
||||
// builder.onNegative(new MaterialDialog.SingleButtonCallback() {
|
||||
// @Override
|
||||
// public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
// negativeCallback.invoke();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// if (errorCallback != null) {
|
||||
// errorCallback.invoke(e.getMessage(), options.toString());
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// builder.show();
|
||||
// }
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
package com.aakashns.reactnativedialogs.modules;
|
||||
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||
import com.facebook.react.bridge.ReactMethod;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.bridge.ReadableMapKeySeyIterator;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class SimpleDialogModule extends ReactContextBaseJavaModule {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SimpleDialog";
|
||||
}
|
||||
|
||||
FragmentActivity mActivity;
|
||||
|
||||
public SimpleDialogModule(
|
||||
ReactApplicationContext reactContext,
|
||||
FragmentActivity fragmentActivity) {
|
||||
super(reactContext);
|
||||
mActivity = fragmentActivity;
|
||||
}
|
||||
|
||||
static Set<String> blacklist = new HashSet<>(Arrays.<String>asList(
|
||||
"items",
|
||||
"itemsCallback",
|
||||
"choice",
|
||||
"selectedIndex"
|
||||
));
|
||||
|
||||
private MaterialDialog.Builder applyOptions(
|
||||
MaterialDialog.Builder builder,
|
||||
ReadableMap options
|
||||
) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
|
||||
|
||||
|
||||
Method[] allMethods = builder.getClass().getDeclaredMethods();
|
||||
ReadableMapKeySeyIterator iterator = options.keySetIterator();
|
||||
|
||||
while(iterator.hasNextKey()) {
|
||||
String key = iterator.nextKey();
|
||||
if (blacklist.contains(key)) continue;
|
||||
Method method = MaterialDialog.Builder.class
|
||||
.getMethod(key, new Class[]{CharSequence.class});
|
||||
method.invoke(builder, options.getString(key));
|
||||
}
|
||||
|
||||
if (options.hasKey("items")) {
|
||||
ReadableArray arr = options.getArray("items");
|
||||
String[] items = new String[arr.size()];
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
items[i] = arr.getString(i);
|
||||
}
|
||||
builder.items(items);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void showItemsDialog(
|
||||
ReadableMap options,
|
||||
final Callback itemsCallback,
|
||||
final Callback errorCallback) {
|
||||
MaterialDialog.Builder builder = new MaterialDialog.Builder(mActivity);
|
||||
try {
|
||||
builder = applyOptions(builder, options);
|
||||
boolean choice = options.hasKey("choice") && options.getBoolean("choice");
|
||||
|
||||
int selectedIndex = options.hasKey("selectedIndex") ?
|
||||
options.getInt("selectedIndex") : -1;
|
||||
|
||||
if (itemsCallback != null) {
|
||||
if (choice) {
|
||||
builder.itemsCallbackSingleChoice(selectedIndex, new MaterialDialog.ListCallbackSingleChoice() {
|
||||
@Override
|
||||
public boolean onSelection(MaterialDialog materialDialog, View view, int i, CharSequence charSequence) {
|
||||
itemsCallback.invoke(i);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
errorCallback.invoke(e.getMessage(), options.toString());
|
||||
}
|
||||
builder.show();
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void showBasicDialog(
|
||||
ReadableMap options,
|
||||
final Callback positiveCallback,
|
||||
final Callback negativeCallback,
|
||||
final Callback errorCallback) {
|
||||
MaterialDialog.Builder builder = new MaterialDialog.Builder(mActivity);
|
||||
|
||||
try {
|
||||
builder = applyOptions(builder, options);
|
||||
if (positiveCallback != null) {
|
||||
builder.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
positiveCallback.invoke();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (negativeCallback != null) {
|
||||
builder.onNegative(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(MaterialDialog materialDialog, DialogAction dialogAction) {
|
||||
negativeCallback.invoke();
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (errorCallback != null) {
|
||||
errorCallback.invoke(e.getMessage(), options.toString());
|
||||
}
|
||||
return;
|
||||
}
|
||||
builder.show();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
import { ToastAndroid } from 'react-native';
|
||||
|
||||
|
||||
var toastCallback = (id, text) => ToastAndroid.show(id + ": " + text, ToastAndroid.SHORT);
|
||||
|
||||
var socialNetworks = [
|
||||
"Twitter",
|
||||
"Google+",
|
||||
"Instagram",
|
||||
"Facebook"
|
||||
];
|
||||
|
||||
var socialNetworksLong = [
|
||||
"Twitter is an online social networking service that enables users to send and read short 140-character messages called \"tweets\"",
|
||||
"Google+ is an interest-based social network that is owned and operated by Google Inc. The service is Google\'s fourth foray into social networking.",
|
||||
"Instagram is an online mobile photo-sharing, video-sharing and social networking service that enables its users to take pictures and videos, and share them on a variety of social networking platforms.",
|
||||
"Google+ is an interest-based social network that is owned and operated by Google Inc. The service is Google\'s fourth foray into social networking.",
|
||||
"Instagram is an online mobile photo-sharing, video-sharing and social networking service that enables its users to take pictures and videos, and share them on a variety of social networking platforms.",
|
||||
"Facebook is an online social networking service headquartered in Menlo Park, California. Its website was launched on February 4, 2004, by Mark Zuckerberg with friends."
|
||||
];
|
||||
|
||||
export default [
|
||||
{
|
||||
"sectionTitle": "Basic",
|
||||
"dialogs": [
|
||||
{
|
||||
"buttonText": "Basic (No Title)",
|
||||
"data": {
|
||||
"content": "This app wants to access your location.",
|
||||
"positiveText": "Agree",
|
||||
"negativeText": "Disagree"
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Basic",
|
||||
"data": {
|
||||
"title": "Use Google's Location Services?",
|
||||
"content": "Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.",
|
||||
"positiveText": "Agree",
|
||||
"negativeText": "Disagree"
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Basic (Long Content)",
|
||||
"data": {
|
||||
"title": "Use Google's Location Services?",
|
||||
"content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur vitae metus nec sapien elementum interdum ac mollis tortor. Nunc porttitor metus placerat orci auctor, sed dictum magna dapibus. Morbi a lacus ante. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin posuere nisl imperdiet lectus elementum accumsan. Etiam lacinia nisi ut nulla fermentum tempus. Integer ornare lacinia diam non maximus. Vestibulum iaculis urna eu elementum scelerisque. Etiam nisl erat, bibendum vitae magna nec, convallis malesuada erat. Cras non porttitor nibh. Pellentesque rhoncus sem luctus felis tincidunt bibendum. Pellentesque vulputate eros at nulla sollicitudin volutpat. Pellentesque laoreet est sit amet erat laoreet, id molestie nulla efficitur. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed varius nisl at imperdiet facilisis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur vitae metus nec sapien elementum interdum ac mollis tortor. Nunc porttitor metus placerat orci auctor, sed dictum magna dapibus. Morbi a lacus ante. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Proin posuere nisl imperdiet lectus elementum accumsan. Etiam lacinia nisi ut nulla fermentum tempus. Integer ornare lacinia diam non maximus. Vestibulum iaculis urna eu elementum scelerisque. Etiam nisl erat, bibendum vitae magna nec, convallis malesuada erat. Cras non porttitor nibh. Pellentesque rhoncus sem luctus felis tincidunt bibendum. Pellentesque vulputate eros at nulla sollicitudin volutpat. Pellentesque laoreet est sit amet erat laoreet, id molestie nulla efficitur. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed varius nisl at imperdiet facilisis.",
|
||||
"positiveText": "Agree",
|
||||
"negativeText": "Disagree"
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Basic (Icon)"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"sectionTitle": "Action Buttons",
|
||||
"dialogs": [
|
||||
{
|
||||
"buttonText": "Stacked Buttons",
|
||||
"data": {
|
||||
"title": "Use Google's Location Services?",
|
||||
"content": "Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.",
|
||||
"positiveText": "Turn On Speed Boost Now",
|
||||
"negativeText": "No Thanks",
|
||||
"forceStacking": true,
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Neutral Button",
|
||||
"data": {
|
||||
"title": "Use Google's Location Services?",
|
||||
"content": "Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.",
|
||||
"positiveText": "Agree",
|
||||
"negativeText": "Disagree",
|
||||
"neutralText": "More Info"
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Callbacks",
|
||||
"data": {
|
||||
"title": "Use Google's Location Services?",
|
||||
"content": "Let Google help apps determine location. This means sending anonymous location data to Google, even when no apps are running.",
|
||||
"positiveText": "Agree",
|
||||
"negativeText": "Disagree",
|
||||
"neutralText": "More Info",
|
||||
"onPositive": () => {
|
||||
ToastAndroid.show("POSITIVE!", ToastAndroid.SHORT);
|
||||
},
|
||||
"onNegative": () => {
|
||||
ToastAndroid.show("NEGATIVE!", ToastAndroid.SHORT);
|
||||
},
|
||||
"onNeutral": () => {
|
||||
ToastAndroid.show("NEUTRAL!", ToastAndroid.SHORT);
|
||||
},
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"sectionTitle": "Basic Lists",
|
||||
"dialogs": [
|
||||
{
|
||||
"buttonText": "Basic List (No Title)",
|
||||
"data": {
|
||||
items: socialNetworks,
|
||||
itemsCallback: toastCallback
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Basic List",
|
||||
"data": {
|
||||
"items": socialNetworks,
|
||||
"title": "Social Networks",
|
||||
itemsCallback: toastCallback
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Basic List(Long)",
|
||||
"data": {
|
||||
"items": [
|
||||
'Alabama',
|
||||
'Alaska',
|
||||
'American Samoa',
|
||||
'Arizona',
|
||||
'Arkansas',
|
||||
'California',
|
||||
'Colorado',
|
||||
'Connecticut',
|
||||
'Delaware',
|
||||
'District Of Columbia',
|
||||
'Federated States Of Micronesia',
|
||||
'Florida',
|
||||
'Georgia',
|
||||
'Guam',
|
||||
'Hawaii',
|
||||
'Idaho',
|
||||
'Illinois',
|
||||
'Indiana',
|
||||
'Iowa',
|
||||
'Kansas',
|
||||
'Kentucky',
|
||||
'Louisiana',
|
||||
'Maine',
|
||||
'Marshall Islands',
|
||||
'Maryland',
|
||||
'Massachusetts',
|
||||
'Michigan',
|
||||
'Minnesota',
|
||||
'Mississippi',
|
||||
'Missouri',
|
||||
'Montana',
|
||||
'Nebraska',
|
||||
'Nevada',
|
||||
'New Hampshire',
|
||||
'New Jersey',
|
||||
'New Mexico',
|
||||
'New York',
|
||||
'North Carolina',
|
||||
'North Dakota',
|
||||
'Northern Mariana Islands',
|
||||
'Ohio',
|
||||
'Oklahoma',
|
||||
'Oregon',
|
||||
'Palau',
|
||||
'Pennsylvania',
|
||||
'Puerto Rico',
|
||||
'Rhode Island',
|
||||
'South Carolina',
|
||||
'South Dakota',
|
||||
'Tennessee',
|
||||
'Texas',
|
||||
'Utah',
|
||||
'Vermont',
|
||||
'Virgin Islands',
|
||||
'Virginia',
|
||||
'Washington',
|
||||
'West Virginia',
|
||||
'Wisconsin',
|
||||
'Wyoming'
|
||||
],
|
||||
itemsCallback: toastCallback,
|
||||
"negativeText": "Cancel",
|
||||
"title": "State"
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Basic List (Long Items)",
|
||||
"data": {
|
||||
items: socialNetworksLong,
|
||||
title: "Social Networks",
|
||||
itemsCallback: (id, text) => toastCallback,
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
sectionTitle: "Choice Lists",
|
||||
dialogs: [
|
||||
{
|
||||
"buttonText": "Single Choice",
|
||||
"data": {
|
||||
items: socialNetworks,
|
||||
positiveText: "Choose",
|
||||
title: "Social Networks",
|
||||
itemsCallbackSingleChoice: toastCallback
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Single Choice (Long Items)",
|
||||
"data": {
|
||||
items: socialNetworksLong,
|
||||
positiveText: "Choose",
|
||||
title: "Social Networks",
|
||||
itemsCallbackSingleChoice: toastCallback
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Multi Choice",
|
||||
"data": {
|
||||
items: socialNetworks,
|
||||
positiveText: "Choose",
|
||||
title: "Social Networks",
|
||||
itemsCallbackMultiChoice: toastCallback,
|
||||
positiveCallback: () => 23,
|
||||
"multiChoiceClearButton": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"buttonText": "Multi Choice (Long Items)",
|
||||
"data": {
|
||||
items: socialNetworksLong,
|
||||
positiveText: "Choose",
|
||||
title: "Social Networks",
|
||||
itemsCallbackMultiChoice: toastCallback
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
];
|
|
@ -1,10 +1,4 @@
|
|||
/**
|
||||
* Sample React Native App
|
||||
* https://github.com/facebook/react-native
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var React = require('react-native');
|
||||
import React from 'react-native';
|
||||
var {
|
||||
AppRegistry,
|
||||
StyleSheet,
|
||||
|
@ -14,15 +8,22 @@ var {
|
|||
TouchableNativeFeedback,
|
||||
} = React;
|
||||
|
||||
import DialogAndroid from 'react-native-dialogs';
|
||||
|
||||
import dialogData from './dialogData.js';
|
||||
|
||||
|
||||
class ExampleApp extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {selected: 0};
|
||||
}
|
||||
handleClick() {
|
||||
|
||||
NativeModules.SimpleDialog.showItemsDialog({
|
||||
handleClick() {
|
||||
var dialog = new DialogAndroid();
|
||||
|
||||
dialog.set({
|
||||
title: "Country",
|
||||
items: [
|
||||
"India",
|
||||
|
@ -30,15 +31,45 @@ class ExampleApp extends React.Component {
|
|||
"China",
|
||||
"Russia",
|
||||
],
|
||||
choice: true,
|
||||
positiveText: "Hola",
|
||||
selectedIndex: this.state.selected,
|
||||
},
|
||||
(i) => this.setState({selected: i}),
|
||||
(x, op) => console.log(x, op)
|
||||
);
|
||||
itemsCallbackSingleChoice: (i) => this.setState({selected: i}),
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
showDialog(options) {
|
||||
var dialog = new DialogAndroid();
|
||||
dialog.set(options);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
var dialogs = dialogData.map((section, i) => {
|
||||
var sectionDialogNodes = section.dialogs.map((op, j) =>
|
||||
<TouchableNativeFeedback
|
||||
key={j}
|
||||
background={TouchableNativeFeedback.SelectableBackground()}
|
||||
onPress={c => this.showDialog(
|
||||
op.data || { title: "NOT IMPLEMENTED!! :-(", positiveText: "OK"})}>
|
||||
<View>
|
||||
<Text>
|
||||
{op.buttonText}
|
||||
</Text>
|
||||
</View>
|
||||
</TouchableNativeFeedback>
|
||||
);
|
||||
|
||||
return (
|
||||
<View key={i}>
|
||||
<Text style={styles.welcome}>{section.sectionTitle}</Text>
|
||||
{sectionDialogNodes}
|
||||
</View>
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.welcome}>
|
||||
|
@ -54,11 +85,15 @@ class ExampleApp extends React.Component {
|
|||
<Text style={styles.instructions}>
|
||||
{"Selected : " + this.state.selected}
|
||||
</Text>
|
||||
{dialogs}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
|
@ -79,3 +114,5 @@ var styles = StyleSheet.create({
|
|||
});
|
||||
|
||||
AppRegistry.registerComponent('ExampleApp', () => ExampleApp);
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"start": "node_modules/react-native/packager/packager.sh"
|
||||
},
|
||||
"dependencies": {
|
||||
"react-native": "^0.13.2"
|
||||
"react-native": "^0.13.2",
|
||||
"react-native-dialogs": "file:///Users/aakashns/workspace/opensource/react-native-dialogs"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue