public SplashViewModel1(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider) { HasNavigationBar = false; Title = "SplashViewModel1"; this.serviceDispatcher = serviceDispatcher; this.platformProvider = platformProvider; Task.Delay(1500).ContinueWith(t => platformProvider.ExecuteOnUIThread(() => serviceDispatcher.Dispatch <INavigationService>(ShellNames.SplashScreen, n => n.Push <SplashViewModel2>(replace: true)))); }
public SplashViewModel2(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider) { HasNavigationBar = false; Title = "SplashViewModel2"; this.serviceDispatcher = serviceDispatcher; this.platformProvider = platformProvider; Task.Delay(1500).ContinueWith(t => platformProvider.ExecuteOnUIThread(() => { serviceDispatcher.Dispatch <IShellNavigationService>(n => n.Push <StackShellViewModel>(new { Name = ShellNames.Stack })); serviceDispatcher.Dispatch <INavigationService>(ShellNames.Stack, n => n.Push <ViewModel1>(replace: true)); })); }
public WebBrowserPage(IServiceDispatcher serviceDispatcher, IPlatformProvider platformProvider) { webView = new ShellWebView(); eventRegistrations = new ConcurrentDictionary <string, EventRegistration>(); webView.RegisterCallback("initialize", args => { platformProvider.ExecuteOnUIThread(() => webView.InjectJavaScript(string.Format("serviceDispatcher._initializeCallback({0});", JsonConvert.SerializeObject(serviceDispatcher.Services)))); }); webView.RegisterCallback("dispatch", args => { DispatchData dispatchData = JsonConvert.DeserializeObject <DispatchData>(args); string result = string.IsNullOrEmpty(dispatchData.InstanceName) ? JsonConvert.SerializeObject(serviceDispatcher.Dispatch(dispatchData.ServiceName, dispatchData.MethodName, dispatchData.Arguments)) : JsonConvert.SerializeObject(serviceDispatcher.Dispatch(dispatchData.ServiceName, dispatchData.InstanceName, dispatchData.MethodName, dispatchData.Arguments)); if (dispatchData.CallbackId != null) { platformProvider.ExecuteOnUIThread(() => webView.InjectJavaScript(string.Format("serviceDispatcher._dispatchCallback('{0}', {1});", dispatchData.CallbackId, result))); } }); webView.RegisterCallback("subscribeEvent", args => { SubscribeEventData subscribeEventData = JsonConvert.DeserializeObject <SubscribeEventData>(args); EventRegistration eventRegistration = serviceDispatcher.SubscribeEvent(subscribeEventData.ServiceName, subscribeEventData.EventName, this, (s, e) => { if (subscribeEventData.CallbackId != null) { platformProvider.ExecuteOnUIThread(() => webView.InjectJavaScript(string.Format("serviceDispatcher._eventCallback('{0}', '{1}');", subscribeEventData.CallbackId, JsonConvert.SerializeObject(e)))); } }); eventRegistrations.AddOrUpdate(subscribeEventData.CallbackId, eventRegistration, (k, e) => e); }); webView.RegisterCallback("unsubscribeEvent", args => { UnsubscribeEventData unsubscribeEventData = JsonConvert.DeserializeObject <UnsubscribeEventData>(args); EventRegistration eventRegistration = null; if (eventRegistrations.TryRemove(unsubscribeEventData.CallbackId, out eventRegistration)) { serviceDispatcher.UnsubscribeEvent(unsubscribeEventData.ServiceName, eventRegistration); } }); Content = webView; SetBinding(UrlProperty, new Binding("Url")); SetBinding(HtmlProperty, new Binding("Html")); webView.NavigationCompleted += (s, e) => { if (webView.Source is UrlWebViewSource) { Url = e; } }; }