/// <summary> /// Handles the <see cref="E:ElementPropertyChanged" /> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param> protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { // Xamarin will changed the renderer attached to a view so it is possible that // an old renderer gets a property updated. In this case the Element will be null. // In that case, try to clear the property event handler and exit. if (Element == null) { HybridWebView wv = sender as HybridWebView; if (wv != null) { wv.PropertyChanged -= this.OnElementPropertyChanged; } return; } base.OnElementPropertyChanged(sender, e); if (e.PropertyName == HybridWebView.UriProperty.PropertyName) { this.Load(this.Element.Uri); } else if (e.PropertyName == HybridWebView.SourceProperty.PropertyName) { LoadSource(); } else if (e.PropertyName == HybridWebView.CleanupProperty.PropertyName) { HandleCleanup(); } }
public WebHybridTestPage() { var stack = new StackLayout { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; var hwv = new HybridWebView { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand }; stack.Children.Add(hwv); this.Content = stack; hwv.Uri = new Uri("http://test.padrose.co.uk/hvw/test1.html"); hwv.RegisterCallback("dataCallback", t => Device.BeginInvokeOnMainThread(() => { /**********************************/ //THIS WILL WORK FOR PAGE 1 ONLY /*********************************/ System.Diagnostics.Debug.WriteLine("!!!!!!!!!!!!!!!!! dataCallback: " + t); }) ); hwv.LoadFinished += (s, e) => { /***********************************/ //THIS WILL WORK FOR PAGE 1 ONLY //WEAK REFERENCE LOST??? /***********************************/ System.Diagnostics.Debug.WriteLine("(!!!!!!!!!!!!!!!!!!!! LoadFinished"); }; }
public WebHybridSamplePage() { this.Content = this.hybrid = new HybridWebView { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand, BackgroundColor = Color.White }; this.hybrid.RegisterCallback("dataCallback", t => Device.BeginInvokeOnMainThread(() => { this.DisplayAlert("Data callback", t, "OK"); }) ); this.hybrid.RegisterCallback("sendObject", s => { var serializer = Resolver.Resolve<IJsonSerializer>(); var o = serializer.Deserialize<SendObject>(s); this.DisplayAlert("Object", string.Format("JavaScript sent x: {0}, y: {1}", o.X, o.Y), "OK"); }); this.hybrid.RegisterNativeFunction("funcCallback", t => new object[] { "From Func callback: " + t }); }
private void Unbind(HybridWebView oldElement) { if (oldElement != null) { oldElement.JavaScriptLoadRequested -= OnInjectRequest; oldElement.LoadFromContentRequested -= LoadFromContent; oldElement.LoadContentRequested -= LoadContent; oldElement.PropertyChanged -= this.OnElementPropertyChanged; } }
private void Unbind(HybridWebView oldElement) { if (oldElement != null) { oldElement.JavaScriptLoadRequested -= OnInjectRequest; oldElement.LoadFromContentRequested -= LoadFromContent; oldElement.LoadContentRequested -= LoadContent; oldElement.Navigating -= this.OnNavigating; } }
public WebPageLoadSample() { this.pages = new List<Uri>(new[] { new Uri("http://www.openstreetmap.org "), new Uri("https://www.google.pl/maps"), new Uri("https://www.bing.com/maps/ "), }); this.Padding = new Thickness(0, 20, 0, 0); this.hybrid = new HybridWebView() { BackgroundColor = Color.Red, HorizontalOptions = LayoutOptions.FillAndExpand, StyleId = "HybridWebView", }; var mainLayout = new RelativeLayout { StyleId = "MainLayout", }; this.addressLabel = new Label() { StyleId = "UrlLoaded", FontSize = 8 }; var labelHeight = Device.OnPlatform(10, 10, 20); mainLayout.Children.Add(this.addressLabel, Constraint.Constant(0), Constraint.Constant(0), Constraint.RelativeToParent(p => p.Width), Constraint.Constant(labelHeight)); mainLayout.Children.Add(this.hybrid, Constraint.Constant(0), Constraint.RelativeToView(addressLabel, (p, v) => v.Y + v.Height), Constraint.RelativeToParent(p => { return p.Width; }), Constraint.RelativeToView(addressLabel, (p, v) => p.Height - v.Height)); this.Content = mainLayout; }
public View loadPinGrid() { hwv = new HybridWebView(new JsonSerializer()) { }; #if __ANDROID__ NavigationPage.SetHasNavigationBar(this, false); #endif try { //removal of functions so no errors on the onappearing happening more than once hwv.RemoveAllFunctions(); //register the pingrid generation function hwv.RegisterNativeFunction("getPinGridValues", input => { return getPinGridValues(input); }); } catch (Exception ex) { Console.WriteLine(ex.Message + " " + ex.InnerException + " " + ex.StackTrace); } hwv.VerticalOptions = LayoutOptions.FillAndExpand; hwv.HorizontalOptions = LayoutOptions.FillAndExpand; Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); htmlStack = new StackLayout() { Children = { hwv }, BackgroundColor = Color.White, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; Content = htmlStack; return Content; }
public HybridPage() { var jsonSerializer = Resolver.Resolve<IJsonSerializer>(); this.hybrid = new HybridWebView(jsonSerializer) { BackgroundColor = Color.Blue }; var buttonHeight = Device.OnPlatform(100, 100, 100); var layout = new RelativeLayout(); layout.Children.Add(this.hybrid, Constraint.Constant(0), Constraint.Constant(20), Constraint.RelativeToParent(p => p.Width), Constraint.RelativeToParent(p => p.Height - buttonHeight)); this.Content = layout; }
partial void LoadContent(object sender, HybridWebView.LoadContentEventArgs contentArgs);