feat:add confirm of modal for Android and iOS
This commit is contained in:
@@ -108,4 +108,51 @@ public class ModalPlugin extends DoricJavaPlugin {
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DoricMethod(name = "confirm", thread = ThreadMode.UI)
|
||||
public void confirm(JSDecoder decoder, final DoricPromise promise) {
|
||||
try {
|
||||
JSObject jsObject = decoder.decode().asObject();
|
||||
JSValue titleVal = jsObject.getProperty("title");
|
||||
JSValue msgVal = jsObject.getProperty("msg");
|
||||
JSValue okBtn = jsObject.getProperty("okLabel");
|
||||
JSValue cancelBtn = jsObject.getProperty("cancelLabel");
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getDoricContext().getContext(), R.style.Theme_Doric_Modal_Alert);
|
||||
if (titleVal.isString()) {
|
||||
builder.setTitle(titleVal.asString().value());
|
||||
}
|
||||
String okLabel = getDoricContext().getContext().getString(android.R.string.ok);
|
||||
if (okBtn.isString()) {
|
||||
okLabel = okBtn.asString().value();
|
||||
}
|
||||
String cancelLabel = getDoricContext().getContext().getString(android.R.string.cancel);
|
||||
if (cancelBtn.isString()) {
|
||||
cancelLabel = cancelBtn.asString().value();
|
||||
}
|
||||
builder.setMessage(msgVal.asString().value())
|
||||
.setPositiveButton(okLabel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
promise.resolve();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(cancelLabel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
promise.reject();
|
||||
}
|
||||
});
|
||||
builder.setCancelable(false);
|
||||
try {
|
||||
builder.show();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (ArchiveException e) {
|
||||
e.printStackTrace();
|
||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user