Skip to content

Commit

Permalink
Fix Issue ClaasBrueggemann#23: no cancel event
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Liventsev committed Jul 18, 2018
1 parent 2e87faa commit 3227730
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/android/InAppBrowserXwalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.plugin.InAppBrowserXwalk.BrowserDialog;

import android.content.DialogInterface;
import android.content.res.Resources;
import org.apache.cordova.*;
import org.apache.cordova.PluginManager;
Expand All @@ -14,7 +15,7 @@
import org.xwalk.core.XWalkView;
import org.xwalk.core.XWalkResourceClient;
import org.xwalk.core.internal.XWalkViewInternal;
import org.xwalk.core.internal.XWalkCookieManager;
import org.xwalk.core.XWalkCookieManager;

import android.view.View;
import android.view.Window;
Expand Down Expand Up @@ -161,6 +162,21 @@ public void onClick(View v) {
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
dialog.setCancelable(true);

dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface dialog) {
try {
JSONObject obj = new JSONObject();
obj.put("type", "cancel");
PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
} catch (JSONException e) {
e.printStackTrace();
}
}
});

LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
dialog.addContentView(main, layoutParams);
if(!openHidden) {
Expand Down
3 changes: 3 additions & 0 deletions www/inappbrowserxwalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ var callback = function(event) {
if (event.type === "exit" && callbacks['exit'] !== undefined) {
callbacks['exit']();
}
if (event.type === "cancel" && callbacks['cancel'] !== undefined) {
callbacks['cancel']();
}
}

module.exports = {
Expand Down

0 comments on commit 3227730

Please sign in to comment.