Hi,
I've a custom WkWebViewRenderer which has height calculated based on WebView.ScrollView:
public class CustomWebViewRenderer : WkWebViewRenderer
{
CustomWebView webView;
protected override void OnElementChanged( VisualElementChangedEventArgs e )
{
base.OnElementChanged( e );
if (e.NewElement != null)
{
webView = Element as CustomWebView;
this.NavigationDelegate = new NavigationDelegate( webView );
this.ScrollView.Bounces = false;
this.ScrollView.ScrollEnabled = false;
}
}
}
public class NavigationDelegate : WKNavigationDelegate
{
CustomWebView wv;
public NavigationDelegate(CustomWebView wv)
{
this.wv = wv;
}
public override void DidFinishNavigation( WKWebView webView, WKNavigation navigation )
{
wv.HeightRequest = (double)webView.ScrollView.ContentSize.Height;
}
}
When I place this custom WebView inside CarouselView then height is not correct:
<CarouselView
ItemsSource="{Binding Emails}"
Loop="False"
CurrentItemChanged="carousel_CurrentItemChanged">
<CarouselView.ItemsLayout>
<LinearItemsLayout
Orientation="Horizontal"
SnapPointsType="MandatorySingle"
SnapPointsAlignment="Start" />
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<ScrollView>
<StackLayout>
<Label Text="{Binding subject}"/>
<ctrl:CustomWebView x:Name="webView">
<WebView.Source>
<HtmlWebViewSource Html="{Binding html}" />
</WebView.Source>
</ctrl:CustomWebView>
</StackLayout>
</ScrollView>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
On Android (also custom WebView with calculated height) height is calculated perfectly, in iOS depending where I place VerticalOptions="FillAndExpand" it's either ~3 times the actual content, or cut of. I've tried setting VerticalOptions on everything - CarouselView, StackLayouts, ScrollView, WebView etc. nothing works.
Any idea how to fix this? I've no clue how everything calculated in Xamarin so having hard time trying to find a solution.