Bug 30047 - WebViewRenderer on iOS doesn't lay out properly in response to device rotation
Summary: WebViewRenderer on iOS doesn't lay out properly in response to device rotation
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 1.4.2
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Rui Marinho
: 30297 ()
Depends on:
Reported: 2015-05-13 15:00 UTC by Adam Kemp
Modified: 2016-06-22 12:59 UTC (History)
20 users (show)

Tags: ios webview ac functionality
Is this bug a regression?: ---
Last known good build:

Example application (210.13 KB, application/zip)
2015-05-13 15:00 UTC, Adam Kemp
UIWebView example that behaves correctly (7.72 KB, application/zip)
2015-05-13 15:01 UTC, Adam Kemp
CustomWebView + -Renderer source (3.34 KB, application/x-zip-compressed)
2015-11-18 09:19 UTC, Michael Rumpler
iOS emulator after rotating (22.47 KB, image/png)
2016-06-21 20:16 UTC, christine.blanda

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Adam Kemp 2015-05-13 15:00:05 UTC
Created attachment 11189 [details]
Example application

If you subclass WebViewRenderer and set ScalesPageToFit to true then the page should automatically adapt as the size of the web view changes. An app with a full screen web view should then show the web page always fitting the screen, even as the device rotates.

This doesn't work correctly with WebViewRenderer, but it does work with a stock usage of UIWebView. I'm not exactly sure what's wrong, but I am suspicious of this code:

		public override void LayoutSubviews()
			this.ScrollView.Frame = this.Bounds;
Comment 1 Adam Kemp 2015-05-13 15:01:06 UTC
Created attachment 11190 [details]
UIWebView example that behaves correctly

This example shows a normal UIWebView that behaves correctly.
Comment 2 Chris King 2015-05-19 17:30:07 UTC
Indeed. Expected rotation fill screen but actually fails to fill screen on iOS. My Android device shows no repro.
Comment 3 Anthony 2015-07-29 11:39:21 UTC
I am also experiencing this issue. Will it be looked into?
Comment 4 Rui Marinho 2015-08-24 11:55:46 UTC
*** Bug 30297 has been marked as a duplicate of this bug. ***
Comment 5 Hines Vaughan III 2015-09-16 09:41:40 UTC
Just wanted to see if there was an update on this. The status is still set to In Progress but a Xamarin person on the forum thread below said that it had in fact been fixed. Thanks.

Comment 6 Hines Vaughan III 2015-09-16 09:42:11 UTC
The actual post where they said it was fixed is here:

Comment 7 Rui Marinho 2015-09-16 11:34:23 UTC
Hi, seems the fix isn't that trivial, and it's still being reviewed before being merged. 

We will update with more information here when it would be ready for release.
Comment 8 Michael Rumpler 2015-09-24 02:40:24 UTC
I made a CustomWebViewRenderer based on ViewRenderer<CustomWebView, UIWebView> as David Dancy described in bug #33500. The main differency is, that the ViewRenderer adds the UIWebView as a subview, it is no UIWebView itself.
This works. ScalesPageToFit works, there are no black areas scrolled in and no horizontal scrolling even after rotation.

But I wouldn't use my solution widely because I needed to write my own CustomWebView (not based on X.F.WebView), CustomWebViewRenderer and CustomWebViewRendererDelegate). In the XF code is so much internal that I couldn't use it. That shouldn't be a problem when you integrate it in XF though.
Comment 9 Mikael Nensén 2015-10-08 06:20:14 UTC
Michael, can you post the code that has a working CustomWebViewRenderer?
Comment 10 Michael Rumpler 2015-11-18 09:19:36 UTC
Created attachment 13864 [details]
CustomWebView + -Renderer source

As I said I only got the solution from David Dancy and he didn't want to give me his code because he got it out from Xamarins dlls. But with his description I was able to do the same.
However, now it's been two months since Ruis last comment and it's still not fixed, so I decided to give you my code. If Xamarin feels this violates their rights, then they can just delete the attachment again.

Most of the code was taken from Xamarins dlls using dotPeek with the changes I already explained in comment 8.
Comment 11 Rui Marinho 2015-11-18 10:54:57 UTC
Hi @Michael the problem with that approach is it will break the API and people that were using the Renderer.
Comment 12 david 2015-11-18 14:07:57 UTC
The only thing it breaks is subclasses of the stock renderer.

However the stock renderer is itself broken (doesn't rotate properly, per this bug). So it has to change anyway.

The new API proposed in Michael's and my work both fixes the rotation issue and makes it easier to subclass the renderer.

What's not to like?
Comment 13 Adam 2016-02-11 04:06:15 UTC
Since this is marked as IN_PROGRESS, does anyone have any time frame or release number we can expect the fix in?
Comment 14 jhnc 2016-03-21 18:13:21 UTC
Good afternoon I'm trying to use the ScalesPageToFit to True, but does not work for me , is it because of this bug ? anyone have any predictions or statuz how to walk?
Comment 15 Rui Marinho 2016-04-27 04:00:55 UTC
Should be fixed in 2.2.0
Comment 16 christine.blanda 2016-06-21 20:15:19 UTC
This is not fixed, in fact is it worse now than it was before.  Do you need more information?
Comment 17 christine.blanda 2016-06-21 20:16:44 UTC
Created attachment 16429 [details]
iOS emulator after rotating

Rotated from horizontal to vertical
Comment 18 Adam 2016-06-22 00:02:10 UTC
Christine what version of XF are you using? I can confirm that this issue was fixed for me. Feel free to jump over to the forums and tag me in @AdamP if you wanted to show your code and work through it.
Comment 19 christine.blanda 2016-06-22 12:59:26 UTC
I am testing with 2.3.0.  I explored some more and found that by removing the setting this.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; from the iOS Custom Renderer the webview behaved as expected.