From 52e21be6564dbfd7e36ac8681c17faa1fb624889 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 7 Dec 2018 17:56:50 -0500 Subject: [PATCH] fix draft scrolling --- .../ConversationView/ConversationInputToolbar.m | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m index 3c46a6912..74c5df40a 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputToolbar.m @@ -606,7 +606,14 @@ const CGFloat kMaxTextViewHeight = 98; { // compute new height assuming width is unchanged CGSize currentSize = textView.frame.size; - CGFloat newHeight = [self clampedHeightWithTextView:textView fixedWidth:currentSize.width]; + + CGFloat fixedWidth = currentSize.width; + CGSize contentSize = [textView sizeThatFits:CGSizeMake(fixedWidth, CGFLOAT_MAX)]; + + // `textView.contentSize` isn't accurate when restoring a multiline draft, so we compute it here. + textView.contentSize = contentSize; + + CGFloat newHeight = CGFloatClamp(contentSize.height, kMinTextViewHeight, kMaxTextViewHeight); if (newHeight != self.textViewHeight) { self.textViewHeight = newHeight; @@ -616,14 +623,6 @@ const CGFloat kMaxTextViewHeight = 98; } } -- (CGFloat)clampedHeightWithTextView:(UITextView *)textView fixedWidth:(CGFloat)fixedWidth -{ - CGSize fixedWidthSize = CGSizeMake(fixedWidth, CGFLOAT_MAX); - CGSize contentSize = [textView sizeThatFits:fixedWidthSize]; - - return CGFloatClamp(contentSize.height, kMinTextViewHeight, kMaxTextViewHeight); -} - #pragma mark QuotedReplyPreviewViewDelegate - (void)quotedReplyPreviewDidPressCancel:(QuotedReplyPreview *)preview