Contents

snapp-mobile/snapptheming

`SnappTheming` is a Swift framework designed to streamline the process of integrating dynamic design themes into iOS applications.

Contents

This repository contains the SnappTheming framework as well as an Example Xcode project to demonstrate its capabilities.

Documentation

The documentation for the package can be found here

Tutorial

Explore the essentials of creating your first theme with SnappTheming in SwiftUI, defining colors and styles, and managing multiple themes for seamless user switching. Follow the tutorials for hands-on experience in theming your projects effectively. It can be found here

Quick Start

Instalation

Using Xcode
  1. Navigate to your project settings.
  2. Select the “Package Dependencies” option.
  3. Utilize the search feature to locate the repository: https://github.com/Snapp-Mobile/SnappTheming.
  4. Choose the “SnappTheming” package and select “Add Package” to incorporate it into your project.
Using Swift Package Manager
// swift-tools-version: 5.7
import PackageDescription

let package = Package(
    name: "YourPackage",
    dependencies: [
        .package(url: "https://github.com/Snapp-Mobile/SnappTheming", from: "0.1.0"),
    ],
    targets: [
        .target(
            name: "YourPackage",
            dependencies: ["SnappTheming"]
        )
    ]
)

Usage

In a SwiftUI App
import OSLog
import SnappTheming
import SwiftUI

@main
struct STTestApp: App {
    @State var declaration: SnappThemingDeclaration?

    // Discover more about the JSON Schema at 
    // https://ios-theming.snappmobile.io/documentation/snapptheming/jsonschema
    private let json = """
        {
            "colors": {
                "textPrimary": "#1a1a1a",
            },
            "images": {
                "globe": "system:globe"
            },
            "metrics": {
                "label": 16.0,
                "icon": 24
            },
            "fonts": {
                "label": {
                    "postScriptName": "Arial-BoldMT"
                }
            },
            "typography": {
                "title": {
                    "font": "$fonts/label",
                    "fontSize": "$metrics/label"
                }
            }
        }
        """

    init() {
        let configuration = SnappThemingParserConfiguration(themeName: "Light")
        guard let declaration = try? SnappThemingParser.parse(from: json, using: configuration) else {
            os_log(.error, "Error loading theme")
            return
        }

        if !declaration.fontInformation.isEmpty {
            let fontManager = SnappThemingFontManagerDefault(
                themeCacheRootURL: configuration.themeCacheRootURL,
                themeName: configuration.themeName
            )
            fontManager.registerFonts(declaration.fontInformation)
        }
        _declaration = .init(initialValue: declaration)
    }

    var body: some Scene {
        WindowGroup {
            if let declaration {
                VStack {
                    HStack(alignment: .center) {
                        declaration.images.globe
                            .resizable()
                            .frame(maxWidth: declaration.metrics.icon, maxHeight: declaration.metrics.icon)

                        Text("Praise Kier.")
                            .font(declaration.typography.title)
                    }
                }
                .foregroundStyle(declaration.colors.textPrimary)
            } else {
                Text("Unable to load the theme")
                    .bold()
            }
        }
    }
}

License

MIT License

Package Metadata

Repository: snapp-mobile/snapptheming

Default branch: main

README: README.md