[FEAT] LinearGradient, RadialGradient & AngularGradient#450
[FEAT] LinearGradient, RadialGradient & AngularGradient#450MiaKoring wants to merge 14 commits intomoreSwift:mainfrom
Conversation
|
Related issue: #427 |
|
The new commit now offers full API parity to SwiftUI on AngularGradient and correctly renders all 6 test gradients. “Correct” meaning looking like the SwiftUI rendered result. All 3 supported frameworks recieved this change and the shared screenshots were updated. |
|
Outstanding Tasks have been completed, this can now be reviewed and merged |
stackotter
left a comment
There was a problem hiding this comment.
Thanks for tackling this feature! I've reviewed all of the code now, but I haven't tested anything locally yet. I plan to construct a SwiftUI app with a bunch of edge cases that I have thought of, and then compile that with your PR and ensure that all of the edge cases act the same across platforms. It should be a useful tool to help you address some of my PR comments too. I likely won't get around to doing that today though.
| } | ||
|
|
||
| private func cssStops(gradient: Gradient, environment: EnvironmentValues) -> [String] { | ||
| return gradient.stops.map { |
There was a problem hiding this comment.
Give the closure parameter a name to make things a bit more readable
| return | ||
| """ | ||
| rgba(\(red), \(green), \(blue), \ | ||
| \(resolved.opacity)) \($0.location * 100)% |
There was a problem hiding this comment.
If you do the location percentage conversion outside of the interpolation then you might be able to fit the string on a single line.
| let nsGradient = NSGradient( | ||
| colors: colors, | ||
| atLocations: gradient.gradient.stops.map { CGFloat($0.location) }, | ||
| colorSpace: .extendedSRGB |
There was a problem hiding this comment.
We should use deviceRGB for consistency with UIKitBackend until we know what the real correct choice is
| override func didMoveToWindow() { | ||
| super.didMoveToWindow() | ||
| // UIView is always layer-backed, no need for wantsLayer | ||
| setupGradient() |
There was a problem hiding this comment.
Just put the implementation of setupGradient in here because it's not used anywhere else
| var cgPoint: CGPoint { | ||
| CGPoint(x: x, y: y) | ||
| } | ||
| } |
There was a problem hiding this comment.
Put a blank line after this






Summary
Added support for 3 types of gradients to be rendered as Views:
Changes
SwiftCrossUI
AppBackendprotocol.ElementaryViewstruct for each type of gradient.Angleintended for use byAngularGradientlaterAnglefrom aUnitPointUnitPoint, meant to represent a normalized point in a view’s coordinate spaceUnitPoints are not clamped, so you can use them with arbitrary values to benefit for example fromAngle(origin:destination:)Gradient, used by all implementations of a Gradient, its a gradient type agnostic representation of a color gradientGradient.Stoprepresenting a color and its normalized position in the gradient[Color]or[Gradient.Stop]AppKitBackend, GtkBackend, UIKitBackend
AppBackendmethodsWinUI
AppBackendmethods related toLinearGradientSwiftCrossUITests
Gradient[Color]Color(to make future support of addition possible and remove edgecases to check outside ofGradient)[Color]with one entryExamples
LinearGradientRadialGradientAngularGradientNotes
ShapeStylecould easily re-use the added structs tho.TODO / Status
RadialGradientsupport to WinUIBackend (pending RadialGradientBrush generation)RadialGradient