Hello,
Welcome to Microsoft Q&A!
Create Custom Renderer for HybridWebView
and implement on each platform .
Android
[assembly: ExportRenderer(typeof(HybridWebView), typeof(MyRenderer))]
namespace FormsApp.Droid
{
public class MyRenderer : WebViewRenderer
{
Context _context;
public MyRenderer(Context context) : base(context)
{
_context = context;
}
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
Control.SetWebViewClient(new MyViewClient(this));
}
}
}
public class MyViewClient : FormsWebViewClient
{
MyRenderer _renderer;
public MyViewClient(MyRenderer renderer) : base(renderer)
{
_renderer = renderer;
}
public override void OnPageFinished(Android.Webkit.WebView view, string url)
{
base.OnPageFinished(view, url);
HybridWebView webview = _renderer.Element as HybridWebView;
webview.IsLoggedIn = true;
}
}
}
iOS
[assembly: ExportRenderer(typeof(HybridWebView), typeof(MyRenderer))]
namespace FormsApp.iOS
{
class MyRenderer : WkWebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if(e.NewElement != null)
{
this.NavigationDelegate = new MyDelegate(this);
}
}
}
class MyDelegate : WKNavigationDelegate
{
MyRenderer _renderer;
public MyDelegate(MyRenderer renderer)
{
_renderer = renderer;
}
public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
{
base.DidFinishNavigation(webView, navigation);
HybridWebView webview = _renderer.Element as HybridWebView;
webview.IsLoggedIn = true;
}
}
}
Best Regards,
Cole Xia
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.