dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

[iOS & Mac] Gradient background size is incorrect when invalidating parent #26057

Open RanjithkumarSyncfusion opened 1 week ago

RanjithkumarSyncfusion commented 1 week ago

Description

When invalidating a parent, gradient applied to the child fills the entire screen.

In my example, I have a Grid with 2 Rows(40,*) and loaded a button as first row with LinearGradientBrush. When calling Grid.InvalidateMeasure(), the gradient size fills the entire screen.

Steps to Reproduce

  1. Run the attached sample.
  2. Click anywhere outside the Button. Gradient.zip

Link to public reproduction project repository

No response

Version with bug

9.0.10 SR1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, macOS

Affected platform versions

No response

Did you find any workaround?

Yes Rename the gradient relevant layer name to skip size updating for this particaluar layer alone. private void ButtonLoaded(object? sender, EventArgs e) {

if IOS

        if(sender is Button button && button.Handler != null && button.Handler.PlatformView != null && button.Handler.PlatformView is UIKit.UIView platformView)
        {
            if(platformView.Layer != null && platformView.Layer.Sublayers != null)
            {
                if(platformView.Layer != null && platformView.Layer.Sublayers != null)
            {
                var layer = platformView.Layer.Sublayers.FirstOrDefault(x => x.Name == "MauiBackgroundLayer");
                if( layer != null && layer is CALayer gradientLayer)
                {
                    gradientLayer.Name = "GradientLayer";
                }
            }
            }
        }

endif

Relevant log output

Zhanglirong-Winnie commented 1 week ago

This issue has been verified using Visual Studio Code (9.0.10 & 9.0.0 ). Can repro this issue on iOS and macOS platforms. Image