Reduce relayout and reload churn; respond to dynamic type changes.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-10-16 12:29:22 -04:00
parent 385d7c0c77
commit c2608785e1
4 changed files with 33 additions and 17 deletions

View File

@ -125,6 +125,8 @@ NS_ASSUME_NONNULL_BEGIN
[self.bubbleImageView autoPinToSuperviewEdges];
self.textView = [UITextView new];
// Honor dynamic type in the message bodies.
self.textView.font = [self textMessageFont];
self.textView.font = [UIFont ows_regularFontWithSize:16.f];
self.textView.backgroundColor = [UIColor clearColor];
self.textView.opaque = NO;
@ -167,6 +169,11 @@ NS_ASSUME_NONNULL_BEGIN
return NSStringFromClass([self class]);
}
- (UIFont *)textMessageFont
{
return [UIFont ows_dynamicTypeBodyFont];
}
- (OWSMessageCellType)cellType
{
return self.viewItem.messageCellType;
@ -543,6 +550,7 @@ NS_ASSUME_NONNULL_BEGIN
self.textView.text = self.textMessage;
UIColor *textColor = [self textColor];
self.textView.textColor = textColor;
self.textView.font = [self textMessageFont];
// Don't link outgoing messages that haven't been sent yet, as
// this interferes with "tap to retry".
@ -738,6 +746,7 @@ NS_ASSUME_NONNULL_BEGIN
const int maxTextWidth = (int)floor(maxMessageWidth - (leftMargin + rightMargin));
self.textView.text = self.textMessage;
self.textView.font = [self textMessageFont];
CGSize textSize = [self.textView sizeThatFits:CGSizeMake(maxTextWidth, CGFLOAT_MAX)];
cellSize = CGSizeMake((CGFloat)ceil(textSize.width + leftMargin + rightMargin),
(CGFloat)ceil(textSize.height + textVMargin * 2));

View File

@ -49,6 +49,8 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable NSString *)textInputPrimaryLanguage;
- (void)updateFontSizes;
#pragma mark - Voice Memo
- (void)showVoiceMemoUI;

View File

@ -83,6 +83,7 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex
_inputTextView = [ConversationInputTextView new];
self.inputTextView.textViewToolbarDelegate = self;
self.inputTextView.font = [UIFont ows_dynamicTypeBodyFont];
[self.contentView addSubview:self.inputTextView];
// We want to be permissive about taps on the send and attachment buttons,
@ -151,6 +152,13 @@ static void *kConversationInputTextViewObservingContext = &kConversationInputTex
[self ensureContentConstraints];
}
- (void)updateFontSizes
{
self.inputTextView.font = [UIFont ows_dynamicTypeBodyFont];
[self ensureContentConstraints];
}
- (void)setInputTextViewDelegate:(id<ConversationInputTextViewDelegate>)value
{
OWSAssert(self.inputTextView);

View File

@ -329,8 +329,11 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[self setNavigationTitle];
}
// Reload all cells.
[self resetContentAndLayout];
if (self.isGroupConversation) {
// Reload all cells if this is a group conversation,
// since we may need to update the sender names on the messages.
[self resetContentAndLayout];
}
}
}
@ -633,10 +636,8 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
- (void)resetContentAndLayout
{
// Avoid layout corrupt issues and out-of-date message subtitles.
[self.collectionView.collectionViewLayout
invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
[self.collectionView.collectionViewLayout invalidateLayout];
[self.collectionView reloadData];
// TODO: Should we evacuate cached cell sizes here?
}
@ -1377,9 +1378,14 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
*/
- (void)didChangePreferredContentSize:(NSNotification *)notification
{
// [self.collectionView.collectionViewLayout setMessageBubbleFont:[UIFont ows_dynamicTypeBodyFont]];
DDLogInfo(@"%@ didChangePreferredContentSize", self.tag);
// Evacuate cached cell sizes.
for (ConversationViewItem *viewItem in self.viewItems) {
[viewItem clearCachedLayoutState];
}
[self resetContentAndLayout];
// [self reloadInputToolbarSizeIfNeeded];
[self.inputToolbar updateFontSizes];
}
#pragma mark - Actions
@ -3579,7 +3585,6 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[groupMemberIds addObject:[TSAccountManager localNumber]];
groupModel.groupMemberIds = [NSMutableArray arrayWithArray:[groupMemberIds allObjects]];
[self updateGroupModelTo:groupModel successCompletion:nil];
[self resetContentAndLayout];
}
- (void)popAllConversationSettingsViews
@ -3668,20 +3673,12 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[self toggleDefaultKeyboard];
}
[self clearDraft];
[self finishSendingMessage];
[self.inputToolbar clearTextMessage];
if (didAddToProfileWhitelist) {
[self ensureDynamicInteractions];
}
}
- (void)finishSendingMessage
{
[self.inputToolbar clearTextMessage];
[self.collectionView.collectionViewLayout
invalidateLayoutWithContext:[JSQMessagesCollectionViewFlowLayoutInvalidationContext context]];
[self.collectionView reloadData];
}
- (void)voiceMemoGestureDidStart
{
OWSAssert([NSThread isMainThread]);