xabre / xamarin-forms-tab-badge

Xamarin Forms bindable Tab badges for iOS, Android, UWP, MacOS and WPF
MIT License
307 stars 75 forks source link

The plugin does not work on the last xamarin.forms version #106

Open jhovelnu opened 1 year ago

jhovelnu commented 1 year ago

The plugin does not work on the last xamarin.forms version:

On Android app the badge can be showed

On IOS app the background color does not work

Can you please update this Plugin with the latest version for xamarin.forms?

jhovelnu commented 1 year ago

That is the issue: https://stackoverflow.com/questions/71644970/xamarin-forms-bottom-tabbedpage-not-showing-badge

jhovelnu commented 1 year ago

The issue is on the BadgeView.cs

image

When the Position Center is set the badged is showed, but in other Position the badge is not showed because the margin position.

private void ApplyLayoutParams() { var layoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);

        if (!_hasWrappedLayout)
        {
            var targetParams = ((FrameLayout.LayoutParams)Target.LayoutParameters);
            var w = targetParams.Width / 2;
            var h = targetParams.Height / 2;

            layoutParameters.Gravity = GravityFlags.Center;
            switch (Postion)
            {
                case BadgePosition.PositionTopLeft:
                    layoutParameters.SetMargins(_badgeMarginL - w, _badgeMarginT - h, 0, 0);
                    break;
                case BadgePosition.PositionTopRight:
                    layoutParameters.SetMargins(0, _badgeMarginT - h, _badgeMarginR - w, 0);
                    break;
                case BadgePosition.PositionBottomLeft:
                    layoutParameters.SetMargins(_badgeMarginL - w, 0, 0, 0 + _badgeMarginB - h);
                    break;
                case BadgePosition.PositionBottomRight:
                    layoutParameters.SetMargins(0, 0, _badgeMarginR - w, 0 + _badgeMarginB - h);
                    break;
                case BadgePosition.PositionCenter:
                    layoutParameters.SetMargins(_badgeMarginL, _badgeMarginT, _badgeMarginR, _badgeMarginB);
                    break;
                case BadgePosition.PositionTopCenter:
                    layoutParameters.SetMargins(0, 0 + _badgeMarginT - h, 0, 0);
                    break;
                case BadgePosition.PositionBottomCenter:
                    layoutParameters.SetMargins(0, 0, 0, 0 + _badgeMarginB - h);
                    break;
                case BadgePosition.PositionLeftCenter:
                    layoutParameters.SetMargins(_badgeMarginL - w, 0, 0, 0);
                    break;
                case BadgePosition.PositionRightCenter:
                    layoutParameters.SetMargins(0, 0, _badgeMarginR - w, 0);
                    break;
            }
        }