Forum Xamarin Cross Platform with Xamarin

WebViewRenderer for Tizen

Hello
In this document it is explained how to implement the WebViewRenderer for iOS, Android and UWP
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview
I cannot find any reference regarding implementation for Tizen
Can you please help?
Many thanks in advance
Regards

Best Answer

  • hadihashemhadihashem Member ✭✭
    Accepted Answer

    The answer was finally provided by Samsung:
    https://github.com/xamarin/Xamarin.Forms/pull/2860#issuecomment-603768088

    Therefore, 2 steps are required

    1) In the PCL project, create the CustomWebView class

    namespace MyNamespace
    {
        public class CustomWebView : WebView
        {
            Action<string> Callback;
    
            public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri", returnType: typeof(string), declaringType: typeof(CustomWebView), defaultValue: default(string));
    
            public string Uri
            {
                get { return (string)GetValue(UriProperty); }
                set { SetValue(UriProperty, value); }
            }
    
            public void RegisterAction(Action<string> callback)
            {
                Callback = callback;
            }
    
            public void Cleanup()
            {
                Callback = null;
            }
    
            public void InvokeAction(string data)
            {
                if (Callback == null || data == null)
                {
                    return;
                }
                Callback.Invoke(data);
            }
        }
    }
    

    2) Consume the CustomWebView class in the Tizen project

    [assembly: ExportRenderer(typeof(CustomWebView), typeof(CustomWebViewRenderer))]
    namespace MyNamespace.Tizen
    {
        public class CustomWebViewRenderer : WebViewRenderer
        {        
            protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
            {
                base.OnElementChanged(e);
                if (e.OldElement != null)
                {
    
                }
                if (e.NewElement != null)
                {
    
                }
            }
    
            protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                base.OnElementPropertyChanged(sender, e);
            }
    
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    ((CustomWebView)Element).Cleanup();
                }
                base.Dispose(disposing);
            }
        }
    }
    

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    To achieve WebViewRenderer for Tizen in Xamarin.Forms, please check the following link.

    https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.Tizen/Renderers/WebViewRenderer.cs

  • hadihashemhadihashem Member ✭✭
    Accepted Answer

    The answer was finally provided by Samsung:
    https://github.com/xamarin/Xamarin.Forms/pull/2860#issuecomment-603768088

    Therefore, 2 steps are required

    1) In the PCL project, create the CustomWebView class

    namespace MyNamespace
    {
        public class CustomWebView : WebView
        {
            Action<string> Callback;
    
            public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri", returnType: typeof(string), declaringType: typeof(CustomWebView), defaultValue: default(string));
    
            public string Uri
            {
                get { return (string)GetValue(UriProperty); }
                set { SetValue(UriProperty, value); }
            }
    
            public void RegisterAction(Action<string> callback)
            {
                Callback = callback;
            }
    
            public void Cleanup()
            {
                Callback = null;
            }
    
            public void InvokeAction(string data)
            {
                if (Callback == null || data == null)
                {
                    return;
                }
                Callback.Invoke(data);
            }
        }
    }
    

    2) Consume the CustomWebView class in the Tizen project

    [assembly: ExportRenderer(typeof(CustomWebView), typeof(CustomWebViewRenderer))]
    namespace MyNamespace.Tizen
    {
        public class CustomWebViewRenderer : WebViewRenderer
        {        
            protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
            {
                base.OnElementChanged(e);
                if (e.OldElement != null)
                {
    
                }
                if (e.NewElement != null)
                {
    
                }
            }
    
            protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                base.OnElementPropertyChanged(sender, e);
            }
    
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    ((CustomWebView)Element).Cleanup();
                }
                base.Dispose(disposing);
            }
        }
    }
    
Sign In or Register to comment.