Skip to content

Commit

Permalink
Merge pull request #1 from Heads-and-Hands/feature/editing_text_view_…
Browse files Browse the repository at this point in the history
…attributes

Feature/editing text view attributes
  • Loading branch information
ct4h authored Feb 20, 2021
2 parents 32e36b4 + 4cc0da6 commit 448e43f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Sources/ViewStyler/UITextView/UITextView+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ extension UITextView: VSTextHolderView, VSStringHolderView {
}
}

public var holderedEditingTextAttributes: [NSAttributedString.Key : Any] {
get {
typingAttributes
}
set {
typingAttributes = newValue
}
}

public var holderedText: NSAttributedString? {
get {
if let attributedText = attributedText {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ public extension VSStyleProvider where View: VSTextView {
configurator(VSInnerStyleProvider(view: VSWrappedTextView(view: view, state: .link)))
return self
}

@discardableResult
func editingAttributes(configurator: @escaping (VSStyleProvider<VSWrappedTextView<View>>) -> Void) -> VSStyleProvider<View> {
configurator(VSInnerStyleProvider(view: VSWrappedTextView(view: view, state: .editing)))
return self
}
}
1 change: 1 addition & 0 deletions Sources/ViewStyler/UITextView/VSTextHolderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
import Foundation

public protocol VSTextHolderView: VSItem {
var holderedEditingTextAttributes: [NSAttributedString.Key: Any] { get set }
var holderedLinkTextAttributes: [NSAttributedString.Key: Any] { get set }
}
5 changes: 5 additions & 0 deletions Sources/ViewStyler/UITextView/VSWrappedTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Foundation
public class VSWrappedTextView<View: VSTextView>: VSStringView {
public enum State {
case link
case editing
}

public typealias TextStyle = View.TextStyle
Expand All @@ -23,12 +24,16 @@ public class VSWrappedTextView<View: VSTextView>: VSStringView {
switch state {
case .link:
return NSAttributedString(string: "...", attributes: view.holderedLinkTextAttributes)
case .editing:
return NSAttributedString(string: "...", attributes: view.holderedEditingTextAttributes)
}
}
set {
switch state {
case .link:
view.holderedLinkTextAttributes = newValue?.attributes(at: 0, effectiveRange: nil) ?? [:]
case .editing:
view.holderedEditingTextAttributes = newValue?.attributes(at: 0, effectiveRange: nil) ?? [:]
}
}
}
Expand Down

0 comments on commit 448e43f

Please sign in to comment.