Create SwiftUI View extensions to apply each shader more easily
twostraws opened this issue · comments
Paul Hudson commented
The goal here is to make the shaders easily to apply by wrapping them in View extensions. So, rather than writing this:
Image(systemName: "figure.walk.circle")
.font(.system(size: 300))
.colorEffect(
ShaderLibrary.checkerboard(
.color(.red),
.float(50)
)
)
Users might* instead write this:
Image(systemName: "figure.walk.circle")
.font(.system(size: 300))
.checkerboardEffect(size: 50, replacement: .red)
I've put the asterisk next to "might" because that's just a suggestion for the spelling. Other options that come to mind:
- .checkerboard() <-- Might mean some shaders clash with other modifiers?
- .infernoEffect(.checkerboard(size: 50, replacement: .red)) <-- uses enum associated values, and means we have only one top-level View modifier rather than one for each shader.
Two tips:
- You don't need to convert them all. In fact, it's better to convert a small number at a time then commit that change, to avoid clashes with other developers.
- You're welcome to submit other API naming ideas – I'd rather have a discussion about it and reach a consensus than just dive in with the first option that comes to mind 🙂
Thank you!