Я пытаюсь добавить свой веб-просмотр customrenderer в просмотр списка, но после корректного рендеринга некоторых первых элементов, он появляется с большим пустым пространством внизу. Даже когда я go вернулся к некоторому элементу, который уже правильно отображался, появилось пустое пространство. Вот мой код в xaml и customrenderer в android проекте
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell >
<Frame BackgroundColor="#f3f3f3" Padding="5,10,5,5">
<Frame Margin="5, 0, 5, 0" CornerRadius="15" Padding="15">
<StackLayout>
<Label Text="{Binding Title}" TextColor="Black" FontSize="20" FontAttributes="Bold"/>
<FlexLayout Margin="0,5,0,0" JustifyContent="SpaceBetween">
<StackLayout Orientation="Horizontal">
<Frame VerticalOptions="Center" HeightRequest="35" WidthRequest="35" Padding="0" CornerRadius="100">
<Frame VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" HeightRequest="32" WidthRequest="32" Padding="0" CornerRadius="100" BackgroundColor="red" IsClippedToBounds="True">
<ffloadingImage:CachedImage HeightRequest="32" WidthRequest="32" Source="{Binding Avatar}" Aspect="Fill"/>
</Frame>
</Frame>
<FlexLayout Direction="Column" Margin="10,0,0,0" JustifyContent="Start" HeightRequest="40" WidthRequest="150" AlignItems="Stretch">
<Label Text="{Binding FullName, Converter={converter:ShortenDisplayNameConverter}}" TextColor="Black" FontAttributes="Bold"/>
<Label Text="{Binding ActiveTime, Converter={converter:RelativeDateTimeConvertor}}" TextColor="{StaticResource grayColor}" FontSize="11"/>
</FlexLayout>
</StackLayout>
<Frame FlexLayout.AlignSelf="Start" Margin="0,0,20,0" Padding="12,3,12,3"
BackgroundColor="{StaticResource mainColor}" HasShadow="False" CornerRadius="50">
<Label Text="{Binding Mon}" FontSize="11" TextColor="White" FontAttributes="Bold"/>
</Frame>
</FlexLayout>
<BoxView Margin="10,0,10,0" HeightRequest="1" BackgroundColor="{StaticResource grayColor}" Opacity=".2"/>
<!--<Label Margin="12,0,12,0" Text="{Binding Description}" FontSize="14" TextColor="Black"/>-->
<uc:ExtendedWebViewForComment Navigating="OnNavigating" x:Name="webview" HeightRequest="120" WidthRequest="200" HorizontalOptions="FillAndExpand">
<uc:ExtendedWebViewForComment.Source>
<HtmlWebViewSource Html="{Binding Body}"/>
</uc:ExtendedWebViewForComment.Source>
</uc:ExtendedWebViewForComment>
А вот код в android
public class ExtendedWebViewForCommentRenderer: WebViewRenderer
{
WebView _webView;
public ExtendedWebViewForCommentRenderer(Context context) : base(context)
{
}
class ExtendedWebViewForCommentClient : Android.Webkit.WebViewClient
{
ExtendedWebViewForCommentRenderer _renderer;
private readonly ExtendedWebViewForComment _xWebView;
string _lastUrlNotOverridden;
public ExtendedWebViewForCommentClient(ExtendedWebViewForCommentRenderer renderer, ExtendedWebViewForComment xWebView)
{
_renderer = renderer ?? throw new ArgumentNullException("renderer");
_xWebView = xWebView;
}
public override async void OnPageFinished(WebView view, string url)
{
if (_xWebView != null)
{
int i = 10;
while (view.ContentHeight == 0 && i-- > 0) // wait here till content is rendered
await System.Threading.Tasks.Task.Delay(10);
await System.Threading.Tasks.Task.Delay(200);
_xWebView.HeightRequest = view.ContentHeight;
//Console.WriteLine(view.ContentDescription);
await System.Threading.Tasks.Task.Delay(100);
(_xWebView.Parent.Parent.Parent.Parent as ViewCell).ForceUpdateSize();
view.Settings.TextZoom = 90;
}
base.OnPageFinished(view, url);
var source = new UrlWebViewSource { Url = url };
var args = new WebNavigatedEventArgs(WebNavigationEvent.NewPage, source, url, WebNavigationResult.Success);
_renderer.ElementController.SendNavigated(args);
}
public override void OnPageStarted(WebView view, string url, Bitmap favicon)
{
base.OnPageStarted(view, url, favicon);
var args = new WebNavigatingEventArgs(WebNavigationEvent.NewPage, new UrlWebViewSource { Url = url }, url);
_renderer.ElementController.SendNavigating(args);
}
public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
{
_lastUrlNotOverridden = null;
if (_renderer?.Element == null || request?.Url == null)
return true;
var url = request.Url.ToString();
if (url == WebViewRenderer.AssetBaseUrl)
return false;
var args = new WebNavigatingEventArgs(WebNavigationEvent.NewPage, new UrlWebViewSource { Url = url }, url);
_renderer.ElementController.SendNavigating(args);
_lastUrlNotOverridden = args.Cancel ? null : url;
return args.Cancel;
}
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
_webView = Control;
if (e.OldElement == null)
{
Control.SetWebViewClient(new ExtendedWebViewForCommentClient(this, e.NewElement as ExtendedWebViewForComment));
var nativeWebView = Control;
nativeWebView.Settings.JavaScriptEnabled = true;
}
}
}