Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fix wrong gray color using transparent in iOS gradients #17696

Merged
merged 10 commits into from Dec 20, 2023
Merged

Conversation

jsuarezruiz
Copy link
Contributor

@jsuarezruiz jsuarezruiz commented Sep 27, 2023

Description of Change

Fix wrong gray color using transparent in iOS gradients.

Simulator Screenshot - iPhone 15 - 2023-09-27 at 12 29 30

If the GradientStop color is transparent, use the next one Color with Alpha 0. In other case, the effect is not correct because use a Clear default color and can see a black color in the gradient from one to other color.
More info: https://betterprogramming.pub/the-proper-way-of-creating-a-transparent-gradient-layer-in-ios-b082daa866b1

To test the changes can use the added sample to the Frame sample in the .NET MAUI Gallery.
image

Issues Fixed

Fixes #17366
Fixes #14766

@jsuarezruiz jsuarezruiz added t/bug Something isn't working area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/iOS 🍎 labels Sep 27, 2023
@jsuarezruiz jsuarezruiz requested a review from a team as a code owner September 27, 2023 14:05
@@ -251,6 +251,31 @@ static NSNumber[] GetCAGradientLayerLocations(List<GradientStop> gradientStops)
}
}

static CGColor[] GetCAGradientLayerColors(List<GradientStop> gradientStops)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are mostly pending changes from xamarin/Xamarin.Forms#13401

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this rather be a reference to the code in Core? Instead of a duplicate? Might be possible if the method was internal.

@samhouts samhouts added this to the .NET 8 GA milestone Sep 28, 2023
@@ -251,6 +251,31 @@ static NSNumber[] GetCAGradientLayerLocations(List<GradientStop> gradientStops)
}
}

static CGColor[] GetCAGradientLayerColors(List<GradientStop> gradientStops)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this rather be a reference to the code in Core? Instead of a duplicate? Might be possible if the method was internal.

{
if (gradientStop.Color == Colors.Transparent)
{
var color = gradientStops[index == 0 ? index + 1 : index - 1].Color;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there are multiple transparent together? trans at 0, trans at 0.3 and then red at 1? Also, what happens if the transparent is between two colors? red, trans, green.

nit: this feels like a for loop instead of foreach. I personally don't like the rando index variable outside the loop. But I am also just weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new sample and a new Device Test to validate that case:
image

@samhouts samhouts modified the milestones: .NET 8 GA, .NET 8 SR1 Oct 9, 2023
@samhouts samhouts added the stale Indicates a stale issue/pr and will be closed soon label Nov 21, 2023
@Redth Redth removed this from the .NET 8 SR1 milestone Nov 30, 2023
@jsuarezruiz
Copy link
Contributor Author

Received request from Customer Services and Support team, could we get another review?. Thanks in advance.

@jsuarezruiz jsuarezruiz removed the stale Indicates a stale issue/pr and will be closed soon label Dec 12, 2023
@rmarinho rmarinho merged commit ba78d8a into main Dec 20, 2023
47 checks passed
@rmarinho rmarinho deleted the fix-17366 branch December 20, 2023 18:26
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
6 participants