Esempio n. 1
0
 protected override void OnAttached()
 {
     try {
         var   control   = Control as Android.Widget.TextView;
         float radius    = (float)ShadowEffect.GetRadius(Element);
         float distanceX = (float)ShadowEffect.GetDistanceX(Element);
         float distanceY = (float)ShadowEffect.GetDistanceY(Element);
         Android.Graphics.Color color = ShadowEffect.GetColor(Element).ToAndroid();
         control.SetShadowLayer(radius, distanceX, distanceY, color);
     } catch (Exception ex) {
         Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
     }
 }
Esempio n. 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();
        }
 void UpdateRadius()
 {
     Control.Layer.CornerRadius = (nfloat)ShadowEffect.GetRadius(Element);
 }
        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 color = ShadowEffect.GetColor(Element);

            if (!color.IsDefault)
            {
                color = color.MultiplyAlpha(opacity);
            }

            var androidColor = color.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
        }
Esempio n. 6
0
 void UpdateRadius()
 {
     radius = (float)ShadowEffect.GetRadius(Element);
 }