From 73a02241a1df8b1697e91732861020efda9d6724 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 21 Oct 2010 18:37:11 -0700 Subject: [PATCH] Fix for ticket #2170: calling Ti.App.fireEvent() from a web view context was broken on Android. The bindings for Ti.App in the webview had been creating a private AppModule instance to put event listeners on. This worked since each AppModule instance added itself to a list of proxies that accepted application-global events, and the AppModule had had its fireEvent() method overridden to instead dispatch events to whatever was in that list of proxies. Commit 7926eda7aad2fa2073aad2849f4ed890c5807e00 removed that overridden fireEvent method (probably because of other changes in the framework), leaving the webview sending events just to itself. :) I changed the webview's bindings to pull up the actual live 'App' module instance instead of creating its own, so it just uses the standard event system. It appears to work in my testing updating StatusNet Mobile for the new 1.5 code; we send events back and forth between the main context and a web view to render a rich custom view, and to trigger actions from the HTML UI bits. --- .../modules/titanium/ui/widget/webview/TiWebViewBinding.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/modules/ui/src/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java b/android/modules/ui/src/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java index 50aaaa31b9c..330a4298cb4 100644 --- a/android/modules/ui/src/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java +++ b/android/modules/ui/src/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java @@ -17,6 +17,7 @@ import org.appcelerator.kroll.KrollMethod; import org.appcelerator.kroll.KrollReflectionProperty; import org.appcelerator.kroll.KrollProxy; +import org.appcelerator.titanium.kroll.KrollBridge; import org.appcelerator.titanium.TiContext; import org.appcelerator.titanium.util.Log; import org.json.JSONException; @@ -163,7 +164,7 @@ private class AppBinding public AppBinding(TiContext context) { - module = new AppModule(context); + module = (AppModule)((KrollBridge)context.getJSContext()).getModule("App"); } public void fireEvent(String event, String json)