Commit f3398a3b by Orkhan Alikhanov

Made TextView and Editor Themeable

parent 0e02f6ca
......@@ -35,7 +35,7 @@ public enum EditorPlaceholderAnimation {
case hidden
}
open class Editor: View {
open class Editor: View, Themeable {
/// Reference to textView.
public let textView = TextView()
......@@ -173,11 +173,14 @@ open class Editor: View {
open override func prepare() {
super.prepare()
backgroundColor = nil
prepareDivider()
prepareTextView()
preparePlaceholderLabel()
prepareDetailLabel()
prepareNotificationHandlers()
applyCurrentTheme()
}
open override func layoutSubviews() {
......@@ -187,6 +190,17 @@ open class Editor: View {
layoutBottomLabel(label: detailLabel, verticalOffset: detailVerticalOffset)
}
open func apply(theme: Theme) {
placeholderActiveColor = theme.secondary
placeholderNormalColor = theme.onSurface.withAlphaComponent(0.38)
dividerActiveColor = theme.secondary
dividerNormalColor = theme.onSurface.withAlphaComponent(0.12)
detailColor = theme.onSurface.withAlphaComponent(0.38)
textView.tintColor = theme.secondary
}
@discardableResult
open override func becomeFirstResponder() -> Bool {
return textView.becomeFirstResponder()
......
......@@ -87,7 +87,7 @@ public protocol TextViewDelegate : UITextViewDelegate {
optional func textView(textView: TextView, didProcessEditing textStorage: TextStorage, text: String, range: NSRange)
}
open class TextView: UITextView {
open class TextView: UITextView, Themeable {
/// A boolean indicating whether the text is empty.
open var isEmpty: Bool {
return 0 == text?.utf16.count
......@@ -289,6 +289,7 @@ open class TextView: UITextView {
prepareNotificationHandlers()
prepareRegularExpression()
preparePlaceholderLabel()
applyCurrentTheme()
}
open override var contentSize: CGSize {
......@@ -354,6 +355,11 @@ open class TextView: UITextView {
super.paste(sender)
fixTypingFont()
}
open func apply(theme: Theme) {
textColor = theme.onSurface.withAlphaComponent(0.87)
placeholderColor = theme.onSurface.withAlphaComponent(0.38)
}
}
fileprivate extension TextView {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment