π― Viewrito makes applying view modifiers in SwiftUI easier.
We all love the beautiful and marvelous SwiftUI, but we've likely all experienced hitting the wall of iOS version compatibility issues.
For example...
if #available(iOS 17.0, *) {
Text("Hello, world! π―")
.font(.title)
.padding()
.background {
RoundedRectangle(cornerRadius: 4)
.fill(.black)
}
.foregroundStyle(Color.blue) // β₯ iOS 17
} else {
Text("Hello, world! π―")
.font(.title)
.padding()
.background {
RoundedRectangle(cornerRadius: 4)
.fill(.black)
}
.foregroundColor(Color.blue) // < iOS 17
}
Or at least, you've tried something like this...
struct ContentView: View {
var body: some View {
let text = Text("Hello, world! π―")
.font(.title)
.padding()
.background {
RoundedRectangle(cornerRadius: 4)
.fill(.black)
}
if #available(iOS 17.0, *) {
text.foregroundStyle(Color.blue)
} else {
text.foregroundColor(Color.blue)
}
}
}
The idea is to simplify this duplicate code and make it prettier.
import SwiftUI
import Viewrito
struct ContentView: View {
var body: some View {
Viewrito {
Text("Hello, world! π―")
} modified: { text in
if #available(iOS 17.0, *) {
text.foregroundStyle(Color.blue)
} else {
text.foregroundColor(Color.blue)
}
}
}
}
import SwiftUI
import Viewrito
struct ContentView: View {
var body: some View {
Text("Hello, world! π―")
.addViewModifier { text in
if #available(iOS 17.0, *) {
text.foregroundStyle(Color.blue)
} else {
text.foregroundColor(Color.blue)
}
}
}
}
- Swift Package Manager
https://github.com/mgdgc/Viewrito.git