Hi,
I want to set height of Android WebViewRenderer to full height of it's content so it doesn't scroll. In iOS it works fine by setting ScrollView.ScrollEnabled = false and HeightRequest to ScrollView.ContentSize.Height, but on Android while height is set correctly, there is no content outside screen height, just blank space. Any idea why Android doesn't fill content to it's height?
This is my code for Android WebView renderer:
public class CustomWebViewRenderer : WebViewRenderer
{
static CustomWebView _xwebView = null;
WebView _webView;
public CustomWebViewRenderer( Context context ) : base( context )
{
}
class CustomWebViewClient : Android.Webkit.WebViewClient
{
public override async void OnPageFinished( WebView view, string url )
{
if (_xwebView != null)
{
int i = 10;
while (view.ContentHeight == 0 && i-- > 0)
await System.Threading.Tasks.Task.Delay( 100 );
_xwebView.HeightRequest = view.ContentHeight;
}
base.OnPageFinished( view, url );
}
}
protected override void OnElementChanged( ElementChangedEventArgs<Xamarin.Forms.WebView> e )
{
base.OnElementChanged( e );
_xwebView = e.NewElement as CustomWebView;
_webView = Control;
if (e.OldElement == null)
{
_webView.SetWebViewClient( new CustomWebViewClient() );
}
}
Edit: worked out that this code works fine, problem happens only if I put custom webview inside ScrollView, then it only loads content for the height of screen, the rest is blank.
<ScrollView>
<ctrl:CustomWebView>
<WebView.Source>
<HtmlWebViewSource Html="{Binding Email.html}" />
</WebView.Source>
</ctrl:CustomWebView>
</ScrollView>
If I move it outside ScrollView then it loads fine, but I also want to have some labels above WebView and whole page should scroll. Any idea why ScrollView cuts WebView contents?
By the way, same XAML works fine with custom iOS WkWebViewRenderer, it loads full html content. Something strange happens with Android.