internal void OnScriptNotify(object sender, NotifyEventArgs e) { JObject call = JsonConvert.DeserializeObject <JObject>(e.Value); Debug.WriteLine("OnScriptNotify: " + call); string messageType = call.Value <string>("type"); JObject jdata = null; try { call.Value <string>("data"); jdata = new JObject(); } catch (InvalidCastException) { jdata = call.Value <JObject>("data"); } if (messageType == "CallHandler") { string target = "self"; string handlerName = call.Value <string>("handlerName"); // handlerName might be target.handlerName which means to call it on another view string[] targetAndHandler = handlerName.Split(".".ToCharArray(), 2); if (targetAndHandler != null && targetAndHandler.Length > 1) { target = targetAndHandler[0]; handlerName = targetAndHandler[1]; } JavaScriptBridge targetbridge = this; if (!target.Equals("self")) { Controls.SectionViewPage sectionViewPage = NavigationSectionManager.Instance.getSectionViewPage(target); if (sectionViewPage != null) { targetbridge = sectionViewPage.getJSBridge(); } } targetbridge.callNativeHandler(handlerName, jdata, call.Value <string>("callbackId")); } else if (messageType == "CallCallback") { this.callNativeCallback(call.Value <string>("callbackId"), jdata); } }
internal JavascriptCallback(JavaScriptBridge bridge, string callbackId) { this.callbackId = callbackId; this.bridge = new WeakReference <JavaScriptBridge>(bridge); }