Commit 9cd30b33 by Orkhan Alikhanov Committed by OrkhanAlikhanov

Added divider to Editor

parent f172f0fc
...@@ -97,6 +97,38 @@ open class Editor: View { ...@@ -97,6 +97,38 @@ open class Editor: View {
@IBInspectable @IBInspectable
open var placeholderHorizontalOffset: CGFloat = 0 open var placeholderHorizontalOffset: CGFloat = 0
/// Divider normal height.
@IBInspectable
open var dividerNormalHeight: CGFloat = 1 {
didSet {
updateDividerHeight()
}
}
/// Divider active height.
@IBInspectable
open var dividerActiveHeight: CGFloat = 2 {
didSet {
updateDividerHeight()
}
}
/// Divider normal color.
@IBInspectable
open var dividerNormalColor = Color.grey.lighten2 {
didSet {
updateDividerColor()
}
}
/// Divider active color.
@IBInspectable
open var dividerActiveColor = Color.blue.base {
didSet {
updateDividerColor()
}
}
/// A reference to titleLabel.textAlignment observation. /// A reference to titleLabel.textAlignment observation.
private var placeholderLabelTextObserver: NSKeyValueObservation! private var placeholderLabelTextObserver: NSKeyValueObservation!
...@@ -108,6 +140,7 @@ open class Editor: View { ...@@ -108,6 +140,7 @@ open class Editor: View {
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
prepareDivider()
prepareTextView() prepareTextView()
preparePlaceholderLabel() preparePlaceholderLabel()
prepareNotificationHandlers() prepareNotificationHandlers()
...@@ -116,11 +149,17 @@ open class Editor: View { ...@@ -116,11 +149,17 @@ open class Editor: View {
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutPlaceholderLabel() layoutPlaceholderLabel()
layoutDivider()
} }
} }
private extension Editor { private extension Editor {
/// Prepares the divider.
func prepareDivider() {
dividerColor = dividerNormalColor
}
/// Prepares the textView. /// Prepares the textView.
func prepareTextView() { func prepareTextView() {
layout(textView).edges() layout(textView).edges()
...@@ -164,6 +203,16 @@ private extension Editor { ...@@ -164,6 +203,16 @@ private extension Editor {
placeholderLabel.isHidden = .hidden == placeholderAnimation placeholderLabel.isHidden = .hidden == placeholderAnimation
} }
/// Updates the dividerColor.
func updateDividerColor() {
dividerColor = isEditing ? dividerActiveColor : dividerNormalColor
}
/// Updates the dividerThickness.
func updateDividerHeight() {
dividerThickness = isEditing ? dividerActiveHeight : dividerNormalHeight
}
} }
private extension Editor { private extension Editor {
...@@ -216,11 +265,14 @@ private extension Editor { ...@@ -216,11 +265,14 @@ private extension Editor {
updateEditorState(animated: true) updateEditorState(animated: true)
} }
/// Updates editor.
func updateEditorState(animated: Bool = false) { func updateEditorState(animated: Bool = false) {
updatePlaceholderVisibility() updatePlaceholderVisibility()
updatePlaceholderLabelColor() updatePlaceholderLabelColor()
updateDividerHeight()
updateDividerColor()
guard isPlaceholderAnimated else { guard animated && isPlaceholderAnimated else {
layoutPlaceholderLabel() layoutPlaceholderLabel()
return return
} }
......
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