Swiftpack.co -  RxSwiftCommunity/RxTheme as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
RxSwiftCommunity/RxTheme
Theme management based on Rx
.package(url: "https://github.com/RxSwiftCommunity/RxTheme.git", from: "6.0.0")

RxTheme

Build Status Version Carthage compatible License Platform

Manual

Define theme service

import RxTheme

protocol Theme {
    var backgroundColor: UIColor { get }
    var textColor: UIColor { get }
}

struct LightTheme: Theme {
    let backgroundColor = .white
    let textColor = .black
}

struct DarkTheme: Theme {
    let backgroundColor = .black
    let textColor = .white
}

enum ThemeType: ThemeProvider {
    case light, dark
    var associatedObject: Theme {
        switch self {
        case .light:
            return LightTheme()
        case .dark:
            return DarkTheme()
        }
    }
}

let themeService = ThemeType.service(initial: .light)

Apply theme to UI


// Bind stream to a single attribute
// RxTheme would automatically manage the lifecycle of the binded stream
view.theme.backgroundColor = themeService.attribute { $0.backgroundColor }

Switch themes

themeService.switch(.dark)
// When this is triggered by some signal, you can use:
someSignal.bind(to: themeService.switcher)

Other APIs

// Current theme type
themeService.type
// Theme type stream
themeService.typeStream

Examples

You can run the example project, clone the repo, run pod install from the Example directory first, and open up the workspace file.

Installation

SPM

  1. File > Swift Packages > Add Package Dependency
  2. Add https://github.com/RxSwiftCommunity/RxTheme

Cocoapods

pod 'RxTheme', '~> 6.0'

Carthage

github "RxSwiftCommunity/RxTheme" ~> 6.0.0

Author

duan, wddwyss@gmail.com

License

RxTheme is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 337
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Dependencies

Release Notes

3 weeks ago
  • Injected a setter before binding
  • Remove old multi-bind API

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API