Skip to content

Commit c6004c9

Browse files
PR Feedback. Adopt similar behavior in AttachmentTextView
1 parent fea0215 commit c6004c9

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

Signal/src/ViewControllers/ConversationView/ConversationInputTextView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class ConversationInputTextView: MentionTextView {
184184

185185
override func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
186186
textIsChanging = true
187-
return true
187+
return super.textView(self, shouldChangeTextIn: range, replacementText: text)
188188
}
189189

190190
override func textViewDidChange(_ textView: UITextView) {

SignalMessaging/ViewControllers/AttachmentApproval/AttachmentTextView.swift

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,36 @@ import Foundation
66
import UIKit
77

88
class AttachmentTextView: MentionTextView {
9-
// When creating new lines, contentOffset is animated, but because
10-
// we are simultaneously resizing the text view, this can cause the
11-
// text in the textview to be "too high" in the text view.
12-
// Solution is to disable animation for setting content offset.
9+
10+
private var textIsChanging = false
11+
12+
override func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
13+
textIsChanging = true
14+
return super.textView(self, shouldChangeTextIn: range, replacementText: text)
15+
}
16+
17+
override func textViewDidChange(_ textView: UITextView) {
18+
super.textViewDidChange(textView)
19+
textIsChanging = false
20+
}
21+
1322
override func setContentOffset(_ contentOffset: CGPoint, animated: Bool) {
14-
super.setContentOffset(contentOffset, animated: false)
23+
// When creating new lines, contentOffset is animated, but because because
24+
// we are simultaneously resizing the text view, on pre-iOS 13 this can
25+
// cause the text in the textview to be "too high" in the text view.
26+
// Solution is to disable animation for setting content offset between
27+
// -textViewShouldChange... and -textViewDidChange.
28+
//
29+
// We can't unilaterally disable *all* animated scrolling because that breaks
30+
// manipulation of the cursor in scrollable text. Animation is required to
31+
// slow the text view scrolling down to human scale when the cursor reaches
32+
// the top or bottom edge.
33+
let shouldAnimate: Bool
34+
if #available(iOS 13, *) {
35+
shouldAnimate = animated
36+
} else {
37+
shouldAnimate = animated && !textIsChanging
38+
}
39+
super.setContentOffset(contentOffset, animated: shouldAnimate)
1540
}
1641
}

0 commit comments

Comments
 (0)