{"id":915,"url":"https://github.com/regexident/Gestalt","last_synced_at":"2025-07-30T19:33:07.297Z","repository":{"id":55665351,"uuid":"96208538","full_name":"regexident/Gestalt","owner":"regexident","description":"An unintrusive \u0026 light-weight iOS app-theming library with support for animated theme switching.","archived":false,"fork":false,"pushed_at":"2020-12-14T11:12:31.000Z","size":3662,"stargazers_count":326,"open_issues_count":2,"forks_count":21,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-25T01:04:48.561Z","etag":null,"topics":["darkmode","ios","theme","theme-switcher"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/regexident.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-04T10:58:18.000Z","updated_at":"2024-09-01T17:48:13.000Z","dependencies_parsed_at":"2022-08-15T06:00:26.692Z","dependency_job_id":null,"html_url":"https://github.com/regexident/Gestalt","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regexident%2FGestalt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regexident%2FGestalt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regexident%2FGestalt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/regexident%2FGestalt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/regexident","download_url":"https://codeload.github.com/regexident/Gestalt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228179016,"owners_count":17881123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["darkmode","ios","theme","theme-switcher"],"created_at":"2024-01-05T20:15:34.553Z","updated_at":"2024-12-04T19:32:21.777Z","avatar_url":"https://github.com/regexident.png","language":"Swift","funding_links":[],"categories":["Color","HarmonyOS"],"sub_categories":["Linter","Windows Manager","Other free courses"],"readme":"![jumbotron](jumbotron.png)\n# Gestalt\n\n**Gestalt** is an **unintrusive** and **light-weight** framework for **application theming** with support for **animated theme switching**.\n\n![screencast](screencast.gif)\n\n## Usage\n\nLet's say you want to theme a view controller with a single label:\n\n```swift\nimport Gestalt\n\nstruct Theme: Gestalt.Theme {\n    let view: ViewTheme = .init()\n\n    static let light: Theme = .init(view: .light)\n    static let dark: Theme = .init(view: .dark)\n}\n\nstruct ViewTheme: Gestalt.Theme {\n    let font = UIFont.preferredFont(forTextStyle: .headline)\n    let color: UIColor\n    let backgroundColor: UIColor\n\n    static let light: Theme = .init(\n        color: UIColor.black\n        backgroundColor: UIColor.white\n    )\n\n    static let dark: Theme = .init(\n        color: UIColor.white\n        backgroundColor: UIColor.black\n    )\n}\n\n// In `AppDelegate.application(_:didFinishLaunchingWithOptions:)`\n// assign a default theme (or user's choice from user defaults):\nThemeManager.default.theme = Theme.light\n\nclass ViewController: UIViewController {\n    @IBOutlet var label: UILabel!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \n        self.observe(theme: \\Theme.view)\n    }\n}\n\nextension ViewController: Themeable {\n\n    typealias Theme = ViewTheme\n\n    func apply(theme: Theme) {\n        self.view.backgroundColor = theme.backgroundColor\n        self.label.textColor = theme.color\n        self.label.font = theme.font\n    }\n}\n```\n\nThe call `self.observe(theme: \\Theme.view)` registers the receiver for theme observation on `ThemeManager.default` for future theme changes and then calls it once immediately. The initial call is not animated, any further changes however are animated.\n\nTo change the current theme (even while the app is running) simply assign a different theme to your given `ThemeManager` in use:\n\n```swift\nThemeManager.default.theme = Theme.dark\n```\n\nThis will cause all previously registered closures on the given `ThemeManager` to be called again.\n\nSee the `GestaltDemo` target for a more realistic/elaborate usage example.\n\n#### Note:\n\n1. It is generally sufficient to use `ThemeManager.default`. It is however possible to create dedicated `ThemeManager`s via `let manager = ThemeManager()`.\n\n### Usage in App Extensions\n\nThe use appearance proxies after a view has already been loaded this library uses a hack that removes and re-adds the root view of the application from the main window to activate the proxies. This is not possible in app extensions, such as a today widget, because the extension safe API restricts access to the main window. So to use this library in app extensions you need to manually trigger the reload of the root view by adding something like this to your root view controller after you set up your themes.\n\n```\nThemeManager.default.observe(theme: Theme.self) { [weak self] _ in\n        if let strongSelf = self, let superview = strongSelf.view.superview {\n            strongSelf.view.removeFromSuperview()\n            superview.addSubview(strongSelf.view)\n        }\n    }\n```\n\n#### Important:\n\n1. The body of `func apply(theme: Theme)` should be [idempotent](https://en.wikipedia.org/wiki/Idempotence) to avoid unwanted side-effects on repeated calls.\n\n## Installation\n\nThe recommended way to add **Gestalt** to your project is via [Carthage](https://github.com/Carthage/Carthage):\n\n    github 'regexident/Gestalt' ~\u003e 2.0.0\n    \nor via [Cocoapods](https://cocoapods.org):\n\n    pod 'Gestalt', '~\u003e 2.0.0'\n\nor via [Swift Package Manager](https://swift.org):\n\n```swift\nlet package = Package(\n    name: \"GestaltDemo\",\n    dependencies: [\n        .package(url: \"https://github.com/regexident/Gestalt.git\", from: \"2.0.0\")\n    ],\n    targets: [\n        .target(name: \"GestaltDemo\", dependencies: [ \"Gestalt\" ])\n    ]\n)\n```\n\n## License\n\n**Gestalt** is available under the **MPL-2.0 license**. See the `LICENSE` file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fregexident%2FGestalt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fregexident%2FGestalt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fregexident%2FGestalt/lists"}