xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] FrameRenderer MaskedCorners no longer working #14065

Open brad302 opened 3 years ago

brad302 commented 3 years ago

It appears as though my custom frame renderer is no longer respecting my masked corners (iOS). This code hasn't changed for quite a long time so I can only assume that a Forms or iOS update has caused this to stop working.

This is my renderer ...

    public class CustomFrameRenderer : FrameRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
        {
            base.OnElementChanged(e);

            if (Element != null)
            {
                var element = Element as CustomFrame;

                int result = 0;

                if (element.CornerRadiusTopLeft)
                    result += (int)CACornerMask.MinXMinYCorner;

                if (element.CornerRadiusTopRight)
                    result += (int)CACornerMask.MaxXMinYCorner;

                if (element.CornerRadiusBottomLeft)
                    result += (int)CACornerMask.MinXMaxYCorner;

                if (element.CornerRadiusBottomRight)
                    result += (int)CACornerMask.MaxXMaxYCorner;

                Layer.MaskedCorners = (CACornerMask)result;
            };
        }
    }

... this is my custom class that inherits the frame layout ...

    public class CustomFrame : Frame
    {
        // ---------------------------------------------------------------------------------------------------------------
        public static readonly BindableProperty CornerRadiusTopLeftProperty = BindableProperty.Create(
            propertyName: "CornerRadiusTopLeft",
            returnType: typeof(bool),
            declaringType: typeof(CustomFrame),
            defaultValue: true,
            defaultBindingMode: BindingMode.TwoWay
        );

        public bool CornerRadiusTopLeft
        {
            get { return (bool)GetValue(CornerRadiusTopLeftProperty); }
            set { base.SetValue(CornerRadiusTopLeftProperty, value); }
        }

        // ---------------------------------------------------------------------------------------------------------------
        public static readonly BindableProperty CornerRadiusTopRightProperty = BindableProperty.Create(
            propertyName: "CornerRadiusTopRight",
            returnType: typeof(bool),
            declaringType: typeof(CustomFrame),
            defaultValue: true,
            defaultBindingMode: BindingMode.TwoWay
        );

        public bool CornerRadiusTopRight
        {
            get { return (bool)GetValue(CornerRadiusTopRightProperty); }
            set { base.SetValue(CornerRadiusTopRightProperty, value); }
        }

        // ---------------------------------------------------------------------------------------------------------------
        public static readonly BindableProperty CornerRadiusBottomLeftProperty = BindableProperty.Create(
            propertyName: "CornerRadiusBottomLeft",
            returnType: typeof(bool),
            declaringType: typeof(CustomFrame),
            defaultValue: true,
            defaultBindingMode: BindingMode.TwoWay
        );

        public bool CornerRadiusBottomLeft
        {
            get { return (bool)GetValue(CornerRadiusBottomLeftProperty); }
            set { base.SetValue(CornerRadiusBottomLeftProperty, value); }
        }

        // ---------------------------------------------------------------------------------------------------------------
        public static readonly BindableProperty CornerRadiusBottomRightProperty = BindableProperty.Create(
            propertyName: "CornerRadiusBottomRight",
            returnType: typeof(bool),
            declaringType: typeof(CustomFrame),
            defaultValue: true,
            defaultBindingMode: BindingMode.TwoWay
        );

        public bool CornerRadiusBottomRight
        {
            get { return (bool)GetValue(CornerRadiusBottomRightProperty); }
            set { base.SetValue(CornerRadiusBottomRightProperty, value); }
        }

        // ---------------------------------------------------------------------------------------------------------------
        public static readonly BindableProperty CustomAttribute1Property = BindableProperty.Create(
            propertyName: "CustomAttribute1",
            returnType: typeof(string),
            declaringType: typeof(CustomFrame),
            defaultValue: string.Empty,
            defaultBindingMode: BindingMode.TwoWay
        );

        public string CustomAttribute1
        {
            get { return (string)GetValue(CustomAttribute1Property); }
            set { base.SetValue(CustomAttribute1Property, value); }
        }

        // ---------------------------------------------------------------------------------------------------------------
        public static readonly BindableProperty SelectedProperty = BindableProperty.Create(
            propertyName: "Selected",
            returnType: typeof(bool),
            declaringType: typeof(CustomFrame),
            defaultValue: false,
            defaultBindingMode: BindingMode.TwoWay
        );

        public bool Selected
        {
            get { return (bool)GetValue(SelectedProperty); }
            set { base.SetValue(SelectedProperty, value); }
        }

    }

.... XAML implementation ...

<local:CustomFrame x:Name="CloseFrame" BackgroundColor="Silver"
    CornerRadius="10" HasShadow="false" Padding="5" OutlineColor="Black"
    CornerRadiusTopLeft="false" CornerRadiusTopRight="true" CornerRadiusBottomLeft="false"
    CornerRadiusBottomRight="true" Opacity="0" />

Visual studio for Mac versioninig ...

=== Visual Studio Community 2019 for Mac ===

Version 8.9.3 (build 13) Installation UUID: 080f6141-c746-4725-a68c-1aa2f067edb4 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 612000125

=== Mono Framework MDK ===

Runtime: Mono 6.12.0.125 (2020-02/8c552e98bd6) (64-bit) Package version: 612000125

=== Xamarin Designer ===

Version: 16.9.0.316 Hash: 2241b204a Branch: tags/vsm-rel/d16.9-4540908 Build date: 2021-03-10 21:18:10 UTC

=== Roslyn (Language Service) ===

3.9.0-6.21152.10+c10f884b30737542ddd84ca889a4aad9281ce210

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: Not installed MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: Not installed

=== .NET Core 3.1 SDK ===

SDK: Not installed

=== Xamarin.Profiler ===

Version: 1.6.13.11 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 12.4 (17801) Build 12D4e

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 14.14.2.5 (Visual Studio Community) Hash: 3836759d4 Branch: d16-9 Build date: 2021-02-10 17:56:44-0500

=== Xamarin.Android ===

Version: 11.2.2.1 (Visual Studio Community) Commit: xamarin-android/d16-9/877f572 Android SDK: /Users/braddixon/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 8.1 (API level 27)

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 30.0.4 SDK Build Tools Version: 30.0.2

Build Information: Mono: 5e9cb6d Java.Interop: xamarin/java.interop/d16-9@54f8c24 ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.34.1@daff8f4 Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-9@d210f11

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/braddixon/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.9.0.22 Hash: a391de2 Branch: remotes/origin/d16-9 Build date: 2021-03-05 18:52:30 UTC

=== Android Device Manager ===

Version: 16.9.0.17 Hash: fc2b3db Branch: remotes/origin/d16-9 Build date: 2021-03-05 18:52:54 UTC

=== Build Information ===

Release ID: 809030013 Git revision: 9f03968ddc9d55da84019ce7a972b9fe225009fe Build date: 2021-03-18 10:15:43-04 Build branch: release-8.9 Xamarin extensions: 9f03968ddc9d55da84019ce7a972b9fe225009fe

=== Operating System ===

Mac OS X 10.16.0 Darwin 20.3.0 Darwin Kernel Version 20.3.0 Thu Jan 21 00:07:06 PST 2021 root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64

... keen to get the experts thoughts.

Thanks

Brad

rachelkang commented 3 years ago

Hi, @brad302 - thanks for submitting this issue! Which version of Xamarin.Forms and which version of iOS are you experiencing this issue on? And which versions have you seen the custom code working properly with? If you could also include some screenshots of what you're seeing vs. what you're expecting, that would be really helpful! Thanks :)

brad302 commented 3 years ago

@rachelkang, thanks for reaching out.

I believe it was the latest version of iOS and the latest version of Forms at the time I posted the issue.

Xcode has only just been updated and you can see the version of Xamarin iOS and Xcode in the info I provided above.

I don't have the code in front of me but if I look at the last commit on the 20th of March, the Forms version is 4.8.0.1560

In relation to behavior,the masked corners properties let you flag whether you want them rounded or not (individually chosen, i.e. top left, top right, bottom left & bottom right).

In this image, the top frames bottom corners should be square and not rounded. That code hasn't changed for a long time.

image

In this image, the left two corners of the close button should be square so it butts up against the edge of the device.

image

Does that all help?

Thanks

Brad

brad302 commented 3 years ago

@rachelkang, any update by chance?

rachelkang commented 3 years ago

@brad302 If you're still on XF 4.8, can you try updating to the latest version of XF 5.0.0.2012? https://www.nuget.org/packages/Xamarin.Forms/

brad302 commented 3 years ago

@rachelkang, apologies for the belated reply but just updated the packages to the latest version of forms and still no luck.

Redth commented 3 years ago

Can you attach a small project which reproduces the issue?

brad302 commented 3 years ago

@Redth, have done that for you.

I've confirmed that the renderer is being called and I'm getting the same behaviour.

FrameRendererIssue.zip

Let me know if there's anything else you need.

brad302 commented 3 years ago

Any word on this by chance @Redth? I figure you're busy with Maui stuff but keen to get an update if possible.

Thanks

Brad