SnappTheming
is a Swift framework designed to streamline the process of integrating dynamic design themes into iOS applications.
By leveraging JSON declarations, the framework allows developers to easily extract and apply various theming elements such as colors, fonts, gradients, and shape styles, directly into their app’s user interface.
This repository contains the SnappTheming
framework as well as an Example Xcode project to demonstrate its capabilities.
The documentation for the package can be found here
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
- Navigate to your project settings.
- Select the “Package Dependencies” option.
- Utilize the search feature to locate the repository:
https://github.com/Snapp-Mobile/SnappTheming
. - Choose the “SnappTheming” package and select “Add Package” to incorporate it into your project.
// 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"]
)
]
)
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()
}
}
}
}