protected override void OnAttached()
        {
            base.OnAttached();

            NativeButton = Control as AppCompatButton;
            if (NativeButton == null)
            {
                return;
            }

            FormsButton = Element as Button;

            OrgBackground        = NativeButton.Background;
            OrgStateListAnimator = NativeButton.StateListAnimator;

            //shadow off
            NativeButton.StateListAnimator = null;

            Shape = new GradientDrawable();
            Shape.SetShape(ShapeType.Rectangle);

            UpdateBackgroundColor();
            UpdateBorderRadius();
            UpdateBorder();
            UpdateRippleColor();

            NativeButton.Background = Ripple;
        }
        protected override void OnDetached()
        {
            if (!IsDisposed)
            {
                NativeButton.Background        = OrgBackground;
                NativeButton.StateListAnimator = OrgStateListAnimator;
                System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached Disposing");
            }
            Colors.Dispose();
            Shape.Dispose();
            Inset.Dispose();
            Ripple.Dispose();

            FormsButton          = null;
            NativeButton         = null;
            OrgBackground        = null;
            OrgStateListAnimator = null;

            Colors = null;
            Shape  = null;
            Ripple = null;
            Inset  = null;
            System.Diagnostics.Debug.WriteLine($"{this.GetType().FullName} Detached completely");

            base.OnDetached();
        }
Beispiel #3
0
        protected override void OnDetached()
        {
            var renderer = Container as IVisualElementRenderer;

            if (renderer?.Element != null)
            {
                NativeButton.Background                = OrgBackground;
                NativeButton.StateListAnimator         = OrgStateListAnimator;
                NativeButton.SupportBackgroundTintList = OrgBackgroundTint;
            }
            Colors.Dispose();
            Shape.Dispose();
            Inset.Dispose();
            Ripple.Dispose();

            FormsButton          = null;
            NativeButton         = null;
            OrgBackground        = null;
            OrgStateListAnimator = null;
            OrgBackgroundTint    = null;

            Colors = null;
            Shape  = null;
            Ripple = null;
            Inset  = null;
        }
Beispiel #4
0
        private StateListAnimator CreateStateListAnimator()
        {
            if (_button.ButtonType != MaterialButtonType.Elevated || !_aView.Enabled)
            {
                return(null);
            }

            var stateListAnimator = new StateListAnimator();

            var objAnimTransZEnabled = ObjectAnimator.OfFloat(_aView, "translationZ", MaterialHelper.ConvertToDp(_button.Elevation.RestingElevation))
                                       .SetDuration(100);

            objAnimTransZEnabled.StartDelay = 100;

            var objAnimElevationEnabled = ObjectAnimator.OfFloat(_aView, "elevation", MaterialHelper.ConvertToDp(_button.Elevation.RestingElevation))
                                          .SetDuration(0);

            var objAnimTransZPressed = ObjectAnimator.OfFloat(_aView, "translationZ", MaterialHelper.ConvertToDp(_button.Elevation.PressedElevation))
                                       .SetDuration(100);

            var objAnimElevationPressed = ObjectAnimator.OfFloat(_aView, "elevation", MaterialHelper.ConvertToDp(_button.Elevation.RestingElevation))
                                          .SetDuration(0);

            var b = new AnimatorSet();

            b.PlayTogether(objAnimTransZEnabled, objAnimElevationEnabled);
            b.SetTarget(_aView);

            var bb = new AnimatorSet();

            bb.PlayTogether(objAnimTransZPressed, objAnimElevationPressed);
            bb.SetTarget(_aView);


            stateListAnimator.AddState(new[] { R.Attribute.StatePressed }, bb);
            stateListAnimator.AddState(new[] { R.Attribute.StateFocused, R.Attribute.StateEnabled }, bb);
            stateListAnimator.AddState(new[] { R.Attribute.StateEnabled }, b);
            stateListAnimator.AddState(new[] { R.Attribute.StateFocused }, bb);

            if (!(_aView is AppCompatImageButton))
            {
                return(stateListAnimator);
            }

            _aView.OutlineProvider = new MaterialOutlineProvider(_button.CornerRadius);
            _aView.ClipToOutline   = false;

            return(stateListAnimator);
        }
Beispiel #5
0
        protected override void OnDetached()
        {
            if (!IsDisposed)
            {
                NativeButton.Background        = OrgBackground;
                NativeButton.StateListAnimator = OrgStateListAnimator;
            }
            Colors.Dispose();
            Shape.Dispose();
            Inset.Dispose();
            Ripple.Dispose();

            FormsButton          = null;
            NativeButton         = null;
            OrgBackground        = null;
            OrgStateListAnimator = null;

            Colors = null;
            Shape  = null;
            Ripple = null;
            Inset  = null;
        }
Beispiel #6
0
        private void UpdateElevation()
        {
            if (!Material.IsLollipop)
            {
                return;
            }

            StateListAnimator stateListAnimator = null;

            if (_button.ButtonType == MaterialButtonType.Elevated && _aView.Enabled)
            {
                stateListAnimator = AnimatorInflater.LoadStateListAnimator(_aView.Context, Resource.Animator.material_button_state_list_anim);

                if (_aView is AppCompatImageButton)
                {
                    _aView.OutlineProvider = new MaterialOutlineProvider(_button.CornerRadius);
                    _aView.ClipToOutline   = false;
                }
            }

            _aView.StateListAnimator = stateListAnimator;
        }
Beispiel #7
0
 protected override void OnAttached()
 {
     _originalStateListAnimator = Control.StateListAnimator;
     Control.StateListAnimator  = null;
 }