Skip to content

Commit

Permalink
Allow changing allowAutogrowing after init
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Sep 23, 2024
1 parent 46db750 commit d348acd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Proton/Sources/Swift/Base/AutogrowingTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,30 @@ class AutogrowingTextView: UITextView {
super.init(frame: frame, textContainer: textContainer)
isScrollEnabled = false

setAutogrowing(allowAutogrowing)
//TODO: enable only when line numbering is turned on
contentMode = .redraw
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func setAutogrowing(_ isAutogrowing: Bool) {
guard allowAutogrowing != isAutogrowing else { return }
allowAutogrowing = isAutogrowing

if allowAutogrowing {
heightAnchorConstraint = heightAnchor.constraint(greaterThanOrEqualToConstant: contentSize.height)
heightAnchorConstraint.priority = .defaultHigh

NSLayoutConstraint.activate([
heightAnchorConstraint
])
} else {
isScrollEnabled = false
NSLayoutConstraint.deactivate([heightAnchorConstraint])
}
//TODO: enable only when line numbering is turned on
contentMode = .redraw
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
Expand Down
9 changes: 9 additions & 0 deletions Proton/Sources/Swift/Editor/EditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,15 @@ open class EditorView: UIView {
richTextView.recalculateHeight(size: size)
}

/// Set the behavior for how Editor size would be updated based on content
/// - Parameter isAutogrowing: When `true`, uses custom calculation and constrains to size editor based on content. This is typically the case where
/// Editor is scrollable and needs to be confined to certain size using applied constraints. Use `false` in case Editor is itself non-scrollable but is hosted within
/// another scroll container. This will use iOS's internal logic for sizing the Editor based on the height of the content and is generally better performing.
public func setAutogrowing(_ isAutogrowing: Bool) {
richTextView.setAutogrowing(isAutogrowing)
}


open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return richTextView.canPerformAction(action, withSender: sender)
}
Expand Down

0 comments on commit d348acd

Please sign in to comment.