From ef820a3719e7533da0b99b2673c0f7a167689c83 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 21 Nov 2017 16:50:01 -0500 Subject: [PATCH] Force conversation view cells to update layout immediately. // FREEBIE --- .../Cells/ConversationViewCell.m | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.m b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.m index 6235989d4..f6c72de3c 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.m @@ -35,10 +35,53 @@ NS_ASSUME_NONNULL_BEGIN _isCellVisible = isCellVisible; if (isCellVisible) { - [self layoutIfNeeded]; + [self forceLayoutImmediately]; } } +- (void)setFrame:(CGRect)frame +{ + BOOL didSizeChange = CGSizeEqualToSize(self.frame.size, frame.size); + + [super setFrame:frame]; + + if (didSizeChange) { + [self forceLayoutImmediately]; + } +} + +- (void)setBounds:(CGRect)bounds +{ + BOOL didSizeChange = CGSizeEqualToSize(self.bounds.size, bounds.size); + + [super setBounds:bounds]; + + if (didSizeChange) { + [self forceLayoutImmediately]; + } +} + +- (void)forceLayoutImmediately +{ + NSArray *descendents = [ConversationViewCell collectSubviewsOfViewDepthFirst:self]; + for (UIView *view in descendents) { + [view setNeedsLayout]; + } + for (UIView *view in descendents.reverseObjectEnumerator) { + [view layoutIfNeeded]; + } +} + ++ (NSArray *)collectSubviewsOfViewDepthFirst:(UIView *)view +{ + NSMutableArray *result = [NSMutableArray new]; + for (UIView *subview in view.subviews) { + [result addObjectsFromArray:[self collectSubviewsOfViewDepthFirst:subview]]; + } + [result addObject:view]; + return result; +} + @end NS_ASSUME_NONNULL_END