Skip to content

Commit

Permalink
Recalculate editor height on setting back scrollable
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep committed Sep 24, 2024
1 parent 5eb9d29 commit 911ca2d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Proton/Sources/Swift/Base/AutogrowingTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AutogrowingTextView: UITextView {
self.allowAutogrowing = allowAutogrowing
super.init(frame: frame, textContainer: textContainer)
isScrollEnabled = false
setAutogrowing(allowAutogrowing)
addHeightConstraint()

//TODO: enable only when line numbering is turned on
contentMode = .redraw
Expand All @@ -49,13 +49,8 @@ class AutogrowingTextView: UITextView {

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

NSLayoutConstraint.activate([
heightConstraint
])
addHeightConstraint()
recalculateHeight()
}
} else {
isScrollEnabled = false
Expand All @@ -66,6 +61,17 @@ class AutogrowingTextView: UITextView {
}
}

private func addHeightConstraint() {
guard allowAutogrowing else { return }
let heightConstraint = heightAnchor.constraint(greaterThanOrEqualToConstant: contentSize.height)
heightAnchorConstraint = heightConstraint
heightAnchorConstraint?.priority = .defaultHigh

NSLayoutConstraint.activate([
heightConstraint
])
}

override func layoutSubviews() {
super.layoutSubviews()
guard allowAutogrowing, maxHeight != .greatestFiniteMagnitude else { return }
Expand Down

0 comments on commit 911ca2d

Please sign in to comment.