A powerful lightweight theme ๐ŸŽจ manager for SwiftUI

Last update: May 20, 2022

Action Status MIT License

SwiftTheming ๐ŸŽจ is a handy lightweight handy theme manager which handles multiple themes based on system-wide appearances - light and dark appearances and overrides the system appearance for the application.

Demo ๐Ÿ“ฑ

this slowpoke moves

You can see the demo project in Example folder.

Motivation ๐ŸŽ‰

Imagine that you want to achieve injecting multiple themes and managing them depending on the current system appearance or your preferred appearance. As SwiftUI does not come with the mechanism to manage different themes, you have to come up with it on your own. To me, I want to focus on other time-consuming stuff and don't want to spend on it. So, the idea to implement the handy mechanism for developers came to me and I eventually started crafting it. That was the becoming of SwiftTheming. ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰ Using SwiftTheming, we can manage theme and system appearance as you desire without too much sweating. All you have to do is declare your themes with different colors, images, fonts and gradients. Pretty easy!

Requirements โš ๏ธ

  • iOS 14+, macOS 11+, watchOS 7+, tvOS 14+

SwiftTheming is developed using Xcode 13.0. Make sure you are using Xcode 13 and above.

Installation ๐Ÿ› 

Using Swift Package Manager ๐Ÿ“ฆ

Add it as a dependency within your Package.swift.

dependencies: [
    .package(url: "https://github.com/dscyrescotti/SwiftTheming.git", from: "1.0.0")
]

Currently, SwiftTheming can be installed only via Swift Package Manager.

Usage ๐Ÿ“‹

Defining multiple themes

To get started, you need to declare the abstraction layer of asset that may contain a group of colors, images, gradients and/or fonts. It will be injected into different themes that you create later.

struct Asset: Assetable {
    enum ColorAsset {
        case backgroundColor
        // more...
    }
    enum ImageAsset { // more... }
    enum FontAsset { // more... }
    enum GradientAsset { // more... }
}

Now, we can start designating different themes based on the above asset.

class SampleTheme: Themed<Asset> {
    override func colorSet(for asset: Asset.ColorAsset) -> ColorSet {
        switch asset {
        case .backgroundColor:
            return ColorSet(light: Color.red, dark: Color.pink)
        }
    }
    override func imageSet(for asset: Asset.ImageAsset) -> ImageSet { // some stuff... }
    override func fontSet(for asset: Asset.FontAsset) -> FontSet { // some stuff... }
    override func gradientSet(for asset: Asset.GradientAsset) -> GradientSet { // some stuff... }
}

Make sure you override the above methods before you call. If not , you will end up with fatal error.

After you create multiple themes, it is time to list down all themes that you are going to use in app.

enum Theme: Themeable {
    case sampleTheme
    // more...
    
    func theme() -> Themed<Asset> {
        switch self {
        case .sampleTheme: return SampleTheme()
        // more...
        }
    }
}

Accessing theme provider across views

Yay! you are ready to use themes in your views. Let's get started to pass ThemeProvider across view hierarchy. Here you can set default theme and default appearance for first time running.

WindowGroup {
    ContentView()
        .themeProviding(defaultTheme: Theme.sampleTheme, defaultAppearance: .system)
}

Now, you can access ThemeProvider via @ThemeProviding property wrapper inside any view so that you can easily use assets prepopulated by passing it.

struct ContentView: View {
    @ThemeProviding<Theme> var themeProvider
    
    var body: some View {
        Color(on: themeProvider, for: .backgroundColor)
    }
}

Switching theme and appearance

You can change theme and appearance by callingsetTheme(with:)and setPreferredAppearance(with:)respectively.

Author ๐Ÿ–‹

Dscyre Scotti (@dscyrescotti)

Contributions ๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿง‘โ€๐Ÿ’ป ๐Ÿ‘ฉโ€๐Ÿ’ป

SwiftTheming ๐ŸŽจ welcomes all developers to contribute if you have any idea to enhance and open an issue if you encounter any bug.

License ๐Ÿ“ƒ

SwiftTheming ๐ŸŽจ is available under the MIT license. See the LICENSE file for more info.

GitHub

https://github.com/dscyrescotti/SwiftTheming
You might also like...

Task-Manager - Task Manager App With Swift

Task-Manager - Task Manager App With Swift

Task-Manager It's typical task manager where user can assign the importance, def

Jan 10, 2022

FlexibleImage is implemented with the hope that anyone could easily develop an app that provides features such as Camera Filter and Theme.

FlexibleImage is implemented with the hope that anyone could easily develop an app that provides features such as Camera Filter and Theme.

FlexibleImage is implemented with the hope that anyone could easily develop an app that provides features such as Camera Filter and Theme. When you wr

May 9, 2022

๐Ÿ‘•๐Ÿ‘š Theme management in Swift

๐Ÿ‘•๐Ÿ‘š Theme management in Swift

Themes Story Ever want to support Night mode? Or skin the app differently depending on the seasons? Or toggle features according to paid status? Well,

Apr 29, 2022

An unintrusive & light-weight iOS app-theming library with support for animated theme switching.

An unintrusive & light-weight iOS app-theming library with support for animated theme switching.

Gestalt Gestalt is an unintrusive and light-weight framework for application theming with support for animated theme switching. Usage Let's say you wa

Apr 22, 2022

A very simple soundboard that plays the first 5 seconds of the CSI Miami theme (YEAAAAAAAAAA)

MiamiSunglasses This app is a single-sound soundboard that plays the first few seconds of the CSI Miami theme song when you press the sunglasses. Disc

Feb 10, 2022

A Publish theme. ckitakishi.com is built with PaletteTheme

A Publish theme. ckitakishi.com is built with PaletteTheme

PaletteTheme A Publish theme. ckitakishi.com is built with PaletteTheme. Features Simple and fast Mobile friendly Support both Light/Dark mode Customi

Apr 4, 2022

This repository contains ๐ŸŽจ My Xcode theme that I use. It is compatible with all versions of Xcode.

This repository contains ๐ŸŽจ My Xcode theme that I use. It is compatible with all versions of Xcode.

DRL Xcodetheme Installation Automatic (via script) ./install.sh which will install the file in Xcode FontAndColorThemes directory. Restart Xcode Go t

Mar 30, 2022

Theme handling macOS Appkit (Swift/Objective-C)

DSFAppearanceManager A class for simplifying macOS appearance values and detecting setting changes (Swift/Objective-C). Why? If you're performing cust

May 5, 2022

Tranquillity is a lightweight but powerful dependency injection library for swift.

Tranquillity is a lightweight but powerful dependency injection library for swift.

DITranquillity Tranquillity is a lightweight but powerful dependency injection library for swift. The name "Tranquillity" laid the foundation in the b

May 8, 2022

VEditorKit - Lightweight and Powerful Editor Kit built on Texture(AsyncDisplayKit)

VEditorKit - Lightweight and Powerful Editor Kit built on Texture(AsyncDisplayKit)

VEditorKit provides the most core functionality needed for the editor. Unfortunately, When combined words are entered then UITextView selectedRange will changed and typingAttribute will cleared. So, In combined words case, Users can't continue typing the style they want.

Apr 15, 2022

Willow is a powerful, yet lightweight logging library written in Swift.

Willow Willow is a powerful, yet lightweight logging library written in Swift. Features Requirements Migration Guides Communication Installation Cocoa

May 3, 2022

A Lightweight But Powerful Color Kit (Swift)

A Lightweight But Powerful Color Kit (Swift)

BCColor A lightweight but powerful color kit (Swift) Features Pick Colors From Image Generate Monochrome Image Support Hex Color Style Lighten / Darke

Feb 27, 2022

A lightweight and powerful editor for localizing iOS, macOS, tvOS, and watchOS applications.

A lightweight and powerful editor for localizing iOS, macOS, tvOS, and watchOS applications.

It is Strings but with a Z ๐Ÿ˜ฌ Loved the project? Please share it with your friends and give it a โญ๏ธ Stringz is a lightweight and powerful editor that

May 8, 2022

๐Ÿ“ก RealHTTP is a lightweight yet powerful client-side HTTP library.

๐Ÿ“ก RealHTTP is a lightweight yet powerful client-side HTTP library.

RealHTTP RealHTTP is a lightweight yet powerful client-side HTTP library. Our goal is make an easy to use and effortless http client for Swift. Featur

Apr 30, 2022

A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.

A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.

XMNetworking English Document XMNetworking ๆ˜ฏไธ€ไธช่ฝป้‡็š„ใ€็ฎ€ๅ•ๆ˜“็”จไฝ†ๅŠŸ่ƒฝๅผบๅคง็š„็ฝ‘็ปœๅบ“๏ผŒๅŸบไบŽ AFNetworking 3.0+ ๅฐ่ฃ…ใ€‚ ๅ…ถไธญ๏ผŒXM ๅ‰็ผ€ๆ˜ฏๆˆ‘ไปฌๅ›ข้˜Ÿ Xcode-Men ็š„็ผฉๅ†™ใ€‚ ็ฎ€ไป‹ ๅฆ‚ไธŠๅ›พๆ‰€็คบ๏ผŒXMNetworking ้‡‡็”จไธญๅฟƒๅŒ–็š„่ฎพ่ฎกๆ€ๆƒณ

May 1, 2022

The most power-efficient and lightweight iOS location manager for Swift and ObjC

The most power-efficient and lightweight iOS location manager for Swift and ObjC

IngeoSDK for iOS Overview IngeoSDK is a power-efficient location manager for iOS (Swift and Objective-C), which extends and improves CoreLocation. It

Feb 28, 2022

The most powerful Grid container missed in SwiftUI

The most powerful Grid container missed in SwiftUI

Grid Grid view inspired by CSS Grid and written with SwiftUI We are a development agency building phenomenal apps. Overview Grid is a powerful and eas

May 13, 2022
๐Ÿ‘•๐Ÿ‘š Theme management in Swift
๐Ÿ‘•๐Ÿ‘š Theme management in Swift

Themes Story Ever want to support Night mode? Or skin the app differently depending on the seasons? Or toggle features according to paid status? Well,

Apr 29, 2022
A Publish theme. ckitakishi.com is built with PaletteTheme
A Publish theme. ckitakishi.com is built with PaletteTheme

PaletteTheme A Publish theme. ckitakishi.com is built with PaletteTheme. Features Simple and fast Mobile friendly Support both Light/Dark mode Customi

Apr 4, 2022
This repository contains ๐ŸŽจ My Xcode theme that I use. It is compatible with all versions of Xcode.
This repository contains ๐ŸŽจ My Xcode theme that I use. It is compatible with all versions of Xcode.

DRL Xcodetheme Installation Automatic (via script) ./install.sh which will install the file in Xcode FontAndColorThemes directory. Restart Xcode Go t

Mar 30, 2022
Theme handling macOS Appkit (Swift/Objective-C)

DSFAppearanceManager A class for simplifying macOS appearance values and detecting setting changes (Swift/Objective-C). Why? If you're performing cust

May 5, 2022
๐ŸŽจ Powerful theme/skin manager for iOS 9+ ไธป้ข˜/ๆข่‚ค, ๆš—่‰ฒๆจกๅผ
๐ŸŽจ Powerful theme/skin manager for iOS 9+ ไธป้ข˜/ๆข่‚ค, ๆš—่‰ฒๆจกๅผ

Introduction - Demos - Installation - Documents - FAQ - Contribution - ไธญๆ–‡ๆ–‡ๆกฃ Screenshot Running๏ผšopen SwiftTheme.xcworkspace, run target PlistDemo Intro

May 20, 2022
A powerful SwiftUI Architecture that merges Redux to the functional world of Swift. While bringing powerful workflows to streamline CoreML/Metal/IPFS usage in the Apple ecosystem.
A powerful SwiftUI Architecture that merges Redux to the functional world of Swift. While bringing powerful workflows to streamline CoreML/Metal/IPFS usage in the Apple ecosystem.

GraniteUI - v0.0 - WIP A powerful SwiftUI Architecture that merges Redux event handling and state management with functional programming. While bringi

Jan 17, 2022
๐Ÿง›๐Ÿปโ€โ™‚๏ธ Dark theme for SwiftUI
๐Ÿง›๐Ÿปโ€โ™‚๏ธ Dark theme for SwiftUI

Dracula for SwiftUI A dark theme for SwiftUI. Install All instructions can be found at draculatheme.com/swiftui. Team This theme is maintained by the

Mar 17, 2022
SwiftUI module library for adding seasons theme animations to your app
SwiftUI module library for adding seasons theme animations to your app

HolidayThemes SwiftUI module library for adding seasons theme animations to your app. Requirements iOS 13.0+ Xcode 12.0+ Installation Swift Package Ma

Mar 7, 2022
AwaitKit is a powerful Swift library which provides a powerful way to write asynchronous code in a sequential manner.
AwaitKit is a powerful Swift library which provides a powerful way to write asynchronous code in a sequential manner.

AwaitKit is a powerful Swift library inspired by the Async/Await specification in ES8 (ECMAScript 2017) which provides a powerful way to write asynchronous code in a sequential manner.

Apr 14, 2022
๐ŸŒธ Powerful Codable API requests builder and manager for iOS.
๐ŸŒธ Powerful Codable API requests builder and manager for iOS.

This lib is about network requests with blackjack, roulette and craps! Using it you will be able to convert your massive API layer code into an awesom

Apr 13, 2022