void Update()
        {
            if (View == null || Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
                return;
            }

            var radius = (float)ShadowEffect.GetRadius(Element);

            if (radius < 0)
            {
                radius = defaultRadius;
            }

            var opacity = ShadowEffect.GetOpacity(Element);

            if (opacity < 0)
            {
                opacity = defaultOpacity;
            }

            var androidColor = ShadowEffect.GetColor(Element).MultiplyAlpha(opacity).ToAndroid();
            var offsetX      = (float)ShadowEffect.GetOffsetX(Element);
            var offsetY      = (float)ShadowEffect.GetOffsetY(Element);
            var cornerRadius = Element is IBorderElement borderElement ? borderElement.CornerRadius : 0;

            if (View is AButton button)
            {
                button.StateListAnimator = null;
            }
            else if (View is not AButton && View is ATextView textView)
            {
                textView.SetShadowLayer(radius, offsetX, offsetY, androidColor);
                return;
            }

            var pixelOffsetX      = View.Context.ToPixels(offsetX);
            var pixelOffsetY      = View.Context.ToPixels(offsetY);
            var pixelCornerRadius = View.Context.ToPixels(cornerRadius);

            View.OutlineProvider = new ShadowOutlineProvider(pixelOffsetX, pixelOffsetY, pixelCornerRadius);
            View.Elevation       = View.Context.ToPixels(radius);
            if (View.Parent is ViewGroup group)
            {
                group.SetClipToPadding(false);
            }

#pragma warning disable
            if (Build.VERSION.SdkInt < BuildVersionCodes.P)
            {
                return;
            }

            View.SetOutlineAmbientShadowColor(androidColor);
            View.SetOutlineSpotShadowColor(androidColor);
#pragma warning restore
        }
Example #2
0
        void Update()
        {
            if (View == null || Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
            {
                return;
            }

            var radius = (float)ShadowEffect.GetRadius(Element);

            if (radius < 0)
            {
                radius = defaultRadius;
            }

            var opacity = ShadowEffect.GetOpacity(Element);

            if (opacity < 0)
            {
                opacity = defaultOpacity;
            }

            var androidColor = ShadowEffect.GetColor(Element).MultiplyAlpha(opacity).ToAndroid();

            if (View is TextView textView)
            {
                var offsetX = (float)ShadowEffect.GetOffsetX(Element);
                var offsetY = (float)ShadowEffect.GetOffsetY(Element);
                textView.SetShadowLayer(radius, offsetX, offsetY, androidColor);
                return;
            }

            View.OutlineProvider = (Element as VisualElement)?.BackgroundColor.A > 0
                                ? ViewOutlineProvider.PaddedBounds
                                : ViewOutlineProvider.Bounds;

            View.Elevation = View.Context.ToPixels(radius);

            if (Build.VERSION.SdkInt < BuildVersionCodes.P)
            {
                return;
            }

            View.SetOutlineAmbientShadowColor(androidColor);
            View.SetOutlineSpotShadowColor(androidColor);
        }
        void UpdateShadow()
        {
            if (shadow == null)
            {
                return;
            }

            var radius  = (float)ShadowEffect.GetRadius(Element);
            var opacity = (float)ShadowEffect.GetOpacity(Element);
            var color   = ShadowEffect.GetColor(Element).ToWindowsColor();
            var offsetX = (float)ShadowEffect.GetOffsetX(Element);
            var offsetY = (float)ShadowEffect.GetOffsetY(Element);

            shadow.Color      = color;
            shadow.BlurRadius = radius < 0 ? defaultRadius : radius;
            shadow.Opacity    = opacity < 0 ? defaultOpacity : opacity;
            shadow.Offset     = new Vector3(offsetX, offsetY, 0);

            UpdateShadowMask();
        }