All Projects → RxSwiftCommunity → Rxtheme

RxSwiftCommunity / Rxtheme

Licence: mit
Theme management based on Rx

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Rxtheme

Cathay
an iOS project for demonstration of Reactive Programming
Stars: ✭ 21 (-93.66%)
Mutual labels:  rxswift
MovieInfoMVVMiOS
Movie Info app using TMDb API built with MVVM
Stars: ✭ 38 (-88.52%)
Mutual labels:  rxswift
Verge
🟣 Verge is a very tunable state-management engine on iOS App (UIKit / SwiftUI) and built-in ORM.
Stars: ✭ 273 (-17.52%)
Mutual labels:  rxswift
MGCleanArchitecture
Clean Architecture with RxSwift & MVVM - Templates and Solutions
Stars: ✭ 156 (-52.87%)
Mutual labels:  rxswift
TVToday
iOS TV Shows app with TMDb Api. RxSwift, MVVM, Clean Architecture. Tuist + Swift Package Manager
Stars: ✭ 27 (-91.84%)
Mutual labels:  rxswift
RxMVVM-Texture
RxSwift MVVM pattern best practice built on Texture(AsyncDisplayKit) and written in Swift
Stars: ✭ 84 (-74.62%)
Mutual labels:  rxswift
ios-architecture-example
Architecture pattern simple examples in iOS. You can compare differences in MVC, MVP, MVVM-Delegate and MVVM-Rx for same feature
Stars: ✭ 16 (-95.17%)
Mutual labels:  rxswift
Rxxmly
RxSwift 实现MVVM高仿喜马拉雅的函数响应式编程
Stars: ✭ 313 (-5.44%)
Mutual labels:  rxswift
mvcvm-swift-file-templates
Swift file templates for boosting mobile app development.
Stars: ✭ 16 (-95.17%)
Mutual labels:  rxswift
Swiftrex
Swift + Redux + (Combine|RxSwift|ReactiveSwift) -> SwiftRex
Stars: ✭ 267 (-19.34%)
Mutual labels:  rxswift
RxResponderChain
RxResponderChain
Stars: ✭ 18 (-94.56%)
Mutual labels:  rxswift
Cycle.swift
An experiment in unidirectional architecture inspired by Cycle.js. https://cycle.js.org
Stars: ✭ 24 (-92.75%)
Mutual labels:  rxswift
Swift
💻 Swift - Boilerplate Front : RxSwift, ReactorKit, JWT, Moya (Beta)
Stars: ✭ 17 (-94.86%)
Mutual labels:  rxswift
mvvm-with-rxswift-mentoring-008
Project and source code of the iOS Dev Mentoring #008 - Test-driven MVVM with RxSwift
Stars: ✭ 45 (-86.4%)
Mutual labels:  rxswift
Rxviewcontroller
RxSwift wrapper for UIViewController and NSViewController
Stars: ✭ 280 (-15.41%)
Mutual labels:  rxswift
RxApollo
RxSwift extensions for Apollo
Stars: ✭ 57 (-82.78%)
Mutual labels:  rxswift
DailyNews
Daily News is a news app with good looking user interface ! Apps architecture is MVVM and used RxSwift for binding.
Stars: ✭ 31 (-90.63%)
Mutual labels:  rxswift
Rxappstate
RxSwift extensions for UIApplicationDelegate methods to observe changes in your app's state
Stars: ✭ 328 (-0.91%)
Mutual labels:  rxswift
Cleanarchitecturerxswift
Example of Clean Architecture of iOS app using RxSwift
Stars: ✭ 3,256 (+883.69%)
Mutual labels:  rxswift
Articles Ios Viper
Demo app for VIPER design pattern implementation
Stars: ✭ 254 (-23.26%)
Mutual labels:  rxswift

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
// In the way, RxTheme would automatically manage the lifecycle of the binded stream
view.theme.backgroundColor = themeService.attrStream { $0.backgroundColor }

// Or bind a bunch of attributes, add them to a disposeBag
themeService.rx
    .bind({ $0.textColor }, to: label1.rx.textColor, label2.rx.textColor)
    .bind({ $0.backgroundColor }, to: view.rx.backgroundColor)
    .disposed(by: disposeBag)

All streams generated by ThemeService has share(1)

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
// Current theme attributes
themeService.attrs
// Theme type stream
themeService.typeStream
// Theme attributes stream
themeService.attrsStream

Extend binders in your codebase

Because RxTheme uses Binder<T> from RxCocoa, any Binder defined in RxCocoa could be used here.

This also makes the lib super easy to extend in your codebase, here is an example

extension Reactive where Base: UIView {
    var borderColor: Binder<UIColor?> {
        return Binder(self.base) { view, color in
            view.layer.borderColor = color?.cgColor
        }
    }
}

NOTICE: Since RxSwift 6, most variable based rx extensions should already been derived by @dynamicMemberLookup.

if you also want to use the sugar view.theme.borderColor, you have to write another extension:

extension ThemeProxy where Base: UIView {
    var borderColor: Observable<UIColor?> {
        get { return .empty() }
        set {
            let disposable = newValue
                .take(until: base.rx.deallocating)
                .observe(on: MainScheduler.instance)
                .bind(to: base.rx.borderColor)
            hold(disposable, for: "borderColor")
        }
    }
}

If you think your extension is commonly used, please send us a PR.

Examples

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

If you prefer, there is also a nice video tutorial by @rebeloper.

Installation

5.x requires RxSwift 6, If you are using RxSwift 5, please use 4.x.

SPM

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

Cocoapods

pod 'RxTheme', '~> 5.0'

Carthage

github "RxSwiftCommunity/RxTheme" ~> 5.0.0

Author

duan, [email protected]

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].