using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(CircleImage), typeof(CircleImageRenderer))]
namespace Pixiview.iOS.Renderers
{
    public class CircleImageRenderer : ImageRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
        {
            base.OnElementChanged(e);

            var layer = Layer;
            if (layer != null)
            {
                layer.MasksToBounds = true;
            }
        }

        public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            var control = Control;
            if (control != null)
            {
                control.Layer.CornerRadius = control.Frame.Size.Width / 2;
            }
        }
    }
}
