Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added disabling theming globally and per-class #1174

Merged
merged 4 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/iOS/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ open class NavigationBar: UINavigationBar, Themeable {
*/
private func apply(theme: Theme, to item: UINavigationItem) {
Theme.apply(theme: theme, to: item.toolbar)
item.toolbar.backgroundColor = .clear
}
}

Expand All @@ -208,6 +207,7 @@ internal extension NavigationBar {
}

let toolbar = item.toolbar
toolbar.backgroundColor = .clear
toolbar.interimSpace = interimSpace
toolbar.contentEdgeInsets = contentEdgeInsets

Expand Down
17 changes: 16 additions & 1 deletion Sources/iOS/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public struct Theme: Hashable {
/// Text and iconography color to be used on error color.
public var onError = Color.white

/// A boolean indicating if theming is enabled globally.
public static var isEnabled = true

/// An initializer.
public init() { }
}
Expand Down Expand Up @@ -172,10 +175,22 @@ public extension Theme {
private var IsThemingEnabledKey: UInt8 = 0

public extension Themeable where Self: NSObject {
/// A class-wide boolean indicating if theming is enabled.
static var isThemingEnabled: Bool {
get {
return Theme.isEnabled && AssociatedObject.get(base: self, key: &IsThemingEnabledKey) {
true
}
}
set(value) {
AssociatedObject.set(base: self, key: &IsThemingEnabledKey, value: value)
}
}

/// A boolean indicating if theming is enabled.
var isThemingEnabled: Bool {
get {
return AssociatedObject.get(base: self, key: &IsThemingEnabledKey) {
return type(of: self).isThemingEnabled && AssociatedObject.get(base: self, key: &IsThemingEnabledKey) {
true
}
}
Expand Down