Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize WebView defined in Xamarin.Forms Core library on screen rotate event

I have web page defined in the core library as view to fill whole screen:

Content = new WebView
{
    VerticalOptions = LayoutOptions.FillAndExpand,
    HorizontalOptions = LayoutOptions.FillAndExpand,
    Source = "https://google.com",
};

Unfortunately on screen rotate it's not resized (please see below):

enter image description here enter image description here

How can I make sure that screen is resized on screen rotation.

like image 481
Alexey Strakh Avatar asked Jul 23 '15 17:07

Alexey Strakh


1 Answers

If it's iOS, then make a custom WebView renderer (http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/):

protected override void OnElementChanged (VisualElementChangedEventArgs e)
{
    base.OnElementChanged(e);

    AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
    ScalesPageToFit = true;
}

public override void LayoutSubviews()
{
    base.LayoutSubviews();

    NativeView.Bounds = UIKit.UIScreen.MainScreen.Bounds;
}
like image 66
Daniel Luberda Avatar answered Sep 21 '22 15:09

Daniel Luberda