kunder-lab / cl.kunder.webview

This cordova plugin enables you to open a second webview
Apache License 2.0
40 stars 39 forks source link

Android: No multiple webviews #3

Open litiobat opened 9 years ago

litiobat commented 9 years ago

Hi! In iOS I can create and destroy multiple webviews without problem. But in Android, I can create multiple webviews but only destroy the latest. What I need to change to create/destroy multiple webviews in Android? Thank you for your plugin!

arturokunder commented 9 years ago

@litiobat You are right, there is a bug when you try to show 3 or more webviews on android. The problem originates in this line: https://github.com/kunder-lab/cl.kunder.webview/blob/12a0e5851098e9b316d06b8c06411e47383fe4cb/src/android/cl/kunder/webview/WebViewPlugin.java#L41

private static Dialog webViewDialog;

The created webview gets stored at this variable. We needed to make a static variable so it should be available to all instances of the class (so you could close the new webview from the parent webview). What you would have to make is change the variable for an arraylist (or similar). and then update the hide ans show method.

litiobat commented 9 years ago

Hi! Thank you for guide me to find the solution. (¿hablas español? he visto tus comentarios en el java) I've changed code and now it's working multiple webviews. Here's the changes (sorry, first time in github, maybe here is not the site, I don't know the rules...). Hugs!

---LINE 40 changed to: private static ArrayList

webViewDialog = new ArrayList();

---FROM LINE 172: webViewDialog.add(new Dialog(activity, android.R.style.Theme_NoTitleBar)); int indiceArray = webViewDialog.size(); indiceArray-=1; webViewDialog.get(indiceArray).getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
webViewDialog.get(indiceArray).requestWindowFeature(Window.FEATURE_NO_TITLE);
webViewDialog.get(indiceArray).setCancelable(true); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(webViewDialog.get(indiceArray).getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; webViewDialog.get(indiceArray).setContentView(root); webViewDialog.get(indiceArray).show(); webViewDialog.get(indiceArray).getWindow().setAttributes(lp);

---FROM LINE 208: int indiceArray = webViewDialog.size() -1; if(webViewDialog.get(indiceArray) != null && webViewDialog.get(indiceArray).isShowing()) { webViewDialog.get(indiceArray).dismiss(); webViewDialog.remove(indiceArray); webView.destroy(); }

arturokunder commented 9 years ago

@litiobat hablo español ;) La solución para android es justamente como dices. Para subir el cambio, la forma de trabajar es que tu hagas un fork del repositorio, realices todos los cambios y despues hagas un pull request de los cambios. Esto nos da la ventaja de que se pueden probar los cambios, github nos muestra el detalle de los cambios y mientras no se haga el merge, tu puedes ocupar tu repositorio como fuente del plugin. Avísame si necesitas ayuda