Xamarin.forms: [Bug] After using rotation on button it disappears

Created on 2 Mar 2020  路  9Comments  路  Source: xamarin/Xamarin.Forms

Description

Usage of Rotation property or RotateTo extension method on circle button causes that button disappears partially. This bug happens only on Android 7 and Android 8.

Steps to Reproduce

  1. Make really simple ContentView:
    <StackLayout HorizontalOptions="Center" VerticalOptions="Center"> <Button x:Name="PlusButton" BackgroundColor="#f45f06" Clicked="PlusButton_OnClicked" CornerRadius="32" HeightRequest="64" ImageSource="plus_icon" Rotation="45" WidthRequest="64" /> </StackLayout>
  2. In Code Behind create method PlusButton_OnClicked with this implementation:
    ` private bool _rotated;

    private void PlusButton_OnClicked(object sender, EventArgs e)
    {
        if (!_rotated)
        {
            _rotated = true;
            PlusButton.RotateTo(45, 100, Easing.Linear);
        }
        else
        {
            _rotated = false;
            PlusButton.RotateTo(0, 100, Easing.Linear);
        }
    }`
    
  3. After opening app/rotating button by click you can see only part of button.

Expected Behavior

Button is fully visible on screen

Actual Behavior

Button disappears partially

Basic Information

  • Version with issue: Xamarin Forms 4.5.0.356, 4.4 has this problem too.
  • Last known good version: Xamarin Forms 4.2, maybe 4.3 works too.
  • IDE: Visual Studio 2019 Enterprise
  • Platform Target Frameworks:

    • Android: Android SDK 29 with Android SDK Tools 26.1.1.

  • Android Support Library Version: 28.0.0.3
  • Nuget Packages: Xamarin Forms 4.5.0.356, Prism.Forms 7.0.0.396
  • Affected Devices: Any device with Android 7.0/7.1/8.0/8.1

Screenshots

Screenshot_1583183887

4.4.0 button 5 regression Android bug

All 9 comments

@Skirtek Workaround for this fix is to disable Draw() method in
FastButtonRenderer

public override void Draw(Canvas canvas)
        {
            if (_backgroundTracker?.BackgroundDrawable != null)
                _backgroundTracker.BackgroundDrawable.DrawCircle(canvas, canvas.Width, canvas.Height, base.Draw);
            else
                base.Draw(canvas);
        }

And same method in MaterialButtonRenderer

public override void Draw(Canvas canvas)
        {
            if(Element == null || Element.CornerRadius <= 0)
            {
                base.Draw(canvas);
                return;
            }

            try
            {
                var radiusToPixels = (float)Context.ToPixels(Element.CornerRadius);

                using (var path = new Path())
                {
                    RectF rect = new RectF(0, 0, canvas.Width, canvas.Height);
                    path.AddRoundRect(rect, radiusToPixels, radiusToPixels, Path.Direction.Ccw);
                    canvas.Save();
                    canvas.ClipPath(path);
                    base.Draw(canvas);
                }

                canvas.Restore();
                return;
            }
            catch (Exception ex)
            {
                Internals.Log.Warning(nameof(MaterialButtonRenderer), $"Unable to create circle image: {ex}");
            }

            base.Draw(canvas);


        }

This bug was introduced in Xamarin.Forms 4.4.0.991440 as a solution to fix some clipping issues:)

@yurkinh Thank you for your answer! Could you explain wider how to disable this method? Overriding in custom renderer does not give any effect :(

@Skirtek Actually you should just remove this method form both renderers not override. I can make custom nugets for you to test it on your project or you can install Xamarin.Forms 4.4.0.991265

Fixed in 4.5.0.530 (update: older Android only. Still broken in 8, 9 10)

@mdbill Sorry but I cannot agree. I confimed it happenes in version 4.5.0.530 (SR3) for example on Android 8.1

@Skirtek Ah, good thing you spoke up. My problem was added to this as a duplicate--which we now know it was not since my problem went away. Maybe 617 will work for you? Anyway, good luck!

I found that thisclipping problem also exists in XF 4.4.0.991265 leaving me with no version of XF that works with rotation (note: it's not just animation, simply static rotation is enough). Happens on Android 7.1.2, release builds (not debug)
But! have a workaround! If I set Opacity to 0.99 (or less) all is well. Hope this helps.

@mdbill I'm glad that you have found solution. I can confirm that works on Android 7 and 8 and it could be (not dirty) workaround until Team Xamarin fix this :)

Was this page helpful?
0 / 5 - 0 ratings