Missing Control in WebView renderer for iOS

When I create renderers for Android, then I can use
if (Control != null)
inside
OnElementChanged(ElementChangedEventArgs e)

But in iOS project I was able to find only
OnElementChanged(VisualElementChangedEventArgs e)

And Control is missing in WebViewRenderer for iOS

Tagged:

Best Answer

  • programmerhammerprogrammerhammer BY ✭✭
    edited June 2017 Accepted Answer

    I'v deside to set native control with:

    public class CustomViewRenderer : ViewRenderer<CustomWebView, UIWebView>
    {
    
        protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
        {
            base.OnElementChanged(e);
    
            if (Control == null)
            {
                UIWebView webView = new UIWebView();
                SetNativeControl(webView);
            }
    

    ......

Answers

  • programmerhammerprogrammerhammer BYMember ✭✭
    edited June 2017 Accepted Answer

    I'v deside to set native control with:

    public class CustomViewRenderer : ViewRenderer<CustomWebView, UIWebView>
    {
    
        protected override void OnElementChanged(ElementChangedEventArgs<CustomWebView> e)
        {
            base.OnElementChanged(e);
    
            if (Control == null)
            {
                UIWebView webView = new UIWebView();
                SetNativeControl(webView);
            }
    

    ......

  • jbyrdjbyrd Member

    @Programmer16 - But I'm confused, it looks like you're just overwriting the Native Control with a blank UIWebView. Wouldn't you always end up with a blank web view?

  • programmerhammerprogrammerhammer BYMember ✭✭

    Hi, @jbyrd! Can you provide another option?

  • jbyrdjbyrd Member

    Hey @programmerhammer - I don't know, I'm just trying to figure out how the web view is not blank in your code - does it work?

  • programmerhammerprogrammerhammer BYMember ✭✭

    Yes, it is blank. But you can later upload content into.
    In case when e.NewElement != null and in OnElementPropertyChanged event
    Get uri from this element

    var yourWebView = Element as CustomViewRenderer;
    

    And load content with

    Control.LoadRequest
    
  • NickKovalskyNickKovalsky USMember ✭✭✭

    You can use the NativeView public property instead of empty (is this an eternal bug???) Controlon iOS.

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    The WebViewRenderer itself is the UIWebView. Same if you opt into using the newer WkWebViewRenderer instead.

Sign In or Register to comment.