Skip to content

Commit 3f2b05b

Browse files
author
Felipe Vieira
committed
checkbox prompt support for picker
1 parent 8dcd016 commit 3f2b05b

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ dependencies {
3131
compile 'com.facebook.react:react-native:+'
3232
compile fileTree(include: ['*.jar'], dir: 'libs')
3333
testCompile 'junit:junit:4.12'
34-
compile 'com.afollestad.material-dialogs:commons:0.8.6.2'
34+
compile 'com.afollestad.material-dialogs:commons:0.9.0.1'
3535
}

android/src/main/java/com/aakashns/reactnativedialogs/modules/DialogAndroid.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ else if( tg.equals("end") )
163163
builder.btnStackedGravity(GravityEnum.START);
164164
}
165165
break;
166+
case "checkBoxPrompt":
167+
ReadableMap checkBoxPrompt = options.getMap("checkBoxPrompt");
168+
boolean initiallyChecked = checkBoxPrompt.hasKey("initiallyChecked") &&
169+
checkBoxPrompt.getBoolean("initiallyChecked");
170+
builder.checkBoxPrompt(checkBoxPrompt.getString("text"), initiallyChecked, null);
171+
break;
166172
case "progress":
167173
ReadableMap progress = options.getMap("progress");
168174
boolean indeterminate = progress.hasKey("indeterminate") &&
@@ -275,7 +281,8 @@ public boolean onSelection(MaterialDialog materialDialog, View view, int i,
275281
if (!mCallbackConsumed) {
276282
mCallbackConsumed = true;
277283
charSequence = charSequence == null ? "" : charSequence;
278-
callback.invoke("itemsCallbackSingleChoice", i, charSequence.toString());
284+
boolean isPromptCheckBoxChecked = materialDialog.isPromptCheckBoxChecked();
285+
callback.invoke("itemsCallbackSingleChoice", i, charSequence.toString(), isPromptCheckBoxChecked);
279286
}
280287
return true;
281288
}
@@ -407,7 +414,18 @@ public void run() {
407414
MaterialDialog simple;
408415
@ReactMethod
409416
public void list(ReadableMap options, final Callback callback) {
410-
final MaterialSimpleListAdapter simpleListAdapter = new MaterialSimpleListAdapter(getCurrentActivity());
417+
final MaterialSimpleListAdapter simpleListAdapter = new MaterialSimpleListAdapter(new MaterialSimpleListAdapter.Callback() {
418+
@Override
419+
public void onMaterialListItemSelected(int index, MaterialSimpleListItem item) {
420+
if (!mCallbackConsumed) {
421+
mCallbackConsumed = true;
422+
callback.invoke(index, item.getContent());
423+
}
424+
if (simple != null) {
425+
simple.dismiss();
426+
}
427+
}
428+
});
411429

412430
ReadableArray arr = options.getArray("items");
413431
for(int i = 0; i < arr.size(); i++){
@@ -418,18 +436,7 @@ public void list(ReadableMap options, final Callback callback) {
418436

419437
final MaterialDialog.Builder adapter = new MaterialDialog.Builder(getCurrentActivity())
420438
.title(options.hasKey("title") ? options.getString("title") : "")
421-
.adapter(simpleListAdapter, new MaterialDialog.ListCallback() {
422-
@Override
423-
public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
424-
if (!mCallbackConsumed) {
425-
mCallbackConsumed = true;
426-
callback.invoke(which, text);
427-
}
428-
if (simple != null) {
429-
simple.dismiss();
430-
}
431-
}
432-
})
439+
.adapter(simpleListAdapter, null)
433440
.autoDismiss(true);
434441

435442
UiThreadUtil.runOnUiThread(new Runnable() {

0 commit comments

Comments
 (0)