Skip to content
/ Viewrito Public

🌯 ( view + .modifier + .modifier ) { $0.modifier }

License

Notifications You must be signed in to change notification settings

mgdgc/Viewrito

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Viewrito

🌯 Viewrito makes applying view modifiers in SwiftUI easier.

When To Use

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.

How To Use

Using Viewrito View

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)
            }
        }
    }
}

Using .addViewModifier View Modifier

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)
                }
            }
    }
}

Installation

  • Swift Package Manager
https://github.com/mgdgc/Viewrito.git

License

MIT License

About

🌯 ( view + .modifier + .modifier ) { $0.modifier }

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages