Giter Club home page Giter Club logo

rxtheme's Introduction

RxTheme

Build Status Version License Platform

Manual

Define theme service

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

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

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

let themeService = ThemeService<Theme>(themes: [LightTheme(), DarkTheme()])

Apply theme to UI

themeService.bind([
    ({ $0.textColor }, [label.rx.textColor]),
    ({ $0.backgroundColor }, [view.rx.backgroundColor])
]).disposed(by: disposeBag)

Switch themes

themeService.set(index: 0)

Binder presets

UIApplication
  • statusBarStyle
UIView
  • backgroundColor
  • tintColor
UIButton
  • tintColor
UILabel
  • font
  • textColor
  • highlightedTextColor
  • shadowColor
UITextField
  • font
  • keyboardAppearance
  • textColor
UIImageView
  • image
UIProgressView
  • progressTintColor
  • trackTintColor
UIPageControl
  • pageIndicatorTintColor
  • currentPageIndicatorTintColor
UISlider
  • thumbTintColor
  • minimumTrackTintColor
  • maximumTrackTintColor
UIToolbar
  • barTintColor
UISwitch
  • onTintColor
  • thumbTintColor
UITableView
  • separatorColor
UINavigationBar
  • barStyle
  • barTintColor
  • titleTextAttributes
UITabBar
  • barStyle
  • barTintColor
UITextView
  • font
  • textColor
UIActivityIndicatorView
  • activityIndicatorViewStyle
UIBarButtonItem
  • tintColor
CALayer
  • backgroundColor
  • borderWidth
  • borderColor
  • shadowColor

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
        }
    }
}

Extend binders in the lib

Open codegen/exts.yml, add class, attributes and supported os.

UIApplication:
  attrs:
    statusBarStyle: UIStatusBarStyle
  os: [iOS]

then run codegen script

// make sure you have python3 and pipenv installed
$ pipenv install
$ pipenv run python -m codegen

If you think it's commonly used, please send us a PR.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

RxTheme is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RxTheme'

Author

duan, [email protected]

License

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

rxtheme's People

Contributors

wddwycc avatar

Watchers

James Cloos avatar Mustafa Dur avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.