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
        }
 protected override void OnAttached()
 {
     try {
         Control.Layer.CornerRadius  = (nfloat)ShadowEffect.GetRadius(Element);
         Control.Layer.ShadowColor   = ShadowEffect.GetColor(Element).ToCGColor();
         Control.Layer.ShadowOffset  = new CGSize((double)ShadowEffect.GetDistanceX(Element), (double)ShadowEffect.GetDistanceY(Element));
         Control.Layer.ShadowOpacity = 1.0f;
     } catch (Exception ex) {
         Console.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
     }
 }
Пример #3
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);
     }
 }
Пример #4
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();
        }
        protected override void OnAttached()
        {
            try {
                if (!shadowAdded)
                {
                    var textBlock = Control as Windows.UI.Xaml.Controls.TextBlock;

                    var shadowLabel = new Label();
                    shadowLabel.Text              = textBlock.Text;
                    shadowLabel.FontAttributes    = FontAttributes.Bold;
                    shadowLabel.HorizontalOptions = LayoutOptions.Center;
                    shadowLabel.VerticalOptions   = LayoutOptions.CenterAndExpand;
                    shadowLabel.TextColor         = ShadowEffect.GetColor(Element);
                    shadowLabel.TranslationX      = ShadowEffect.GetDistanceX(Element);
                    shadowLabel.TranslationY      = ShadowEffect.GetDistanceY(Element);

                    ((Grid)Element.Parent).Children.Insert(0, shadowLabel);
                    shadowAdded = true;
                }
            } catch (Exception ex) {
                Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
            }
        }
Пример #7
0
 void UpdateColor()
 {
     Control.Layer.ShadowColor = ShadowEffect.GetColor(Element).ToCGColor();
 }
Пример #8
0
 void UpdateColor()
 {
     color = ShadowEffect.GetColor(Element).ToAndroid();
 }
        private string GetColor()
        {
            var c = ShadowEffect.GetColor(Element).ToNative();

            return(string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", c.R, c.G, c.B, c.A));
        }
Пример #10
0
 void UpdateColor()
 {
     shadowLabel.TextColor = ShadowEffect.GetColor(Element);
 }