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()])
themeService.bind([
({ $0.textColor }, [label.rx.textColor]),
({ $0.backgroundColor }, [view.rx.backgroundColor])
]).disposed(by: disposeBag)
themeService.set(index: 0)
- statusBarStyle
- backgroundColor
- tintColor
- tintColor
- font
- textColor
- highlightedTextColor
- shadowColor
- font
- keyboardAppearance
- textColor
- image
- progressTintColor
- trackTintColor
- pageIndicatorTintColor
- currentPageIndicatorTintColor
- thumbTintColor
- minimumTrackTintColor
- maximumTrackTintColor
- barTintColor
- onTintColor
- thumbTintColor
- separatorColor
- barStyle
- barTintColor
- titleTextAttributes
- barStyle
- barTintColor
- font
- textColor
- activityIndicatorViewStyle
- tintColor
- backgroundColor
- borderWidth
- borderColor
- shadowColor
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
}
}
}
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.
To run the example project, clone the repo, and run pod install
from the Example directory first.
RxTheme is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'RxTheme'
duan, [email protected]
RxTheme is available under the MIT license. See the LICENSE file for more info.