Revise scrolling behavior of messages view.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent 4e1dda275d
commit c639926f2c

@ -150,22 +150,24 @@ typedef enum : NSUInteger {
- (void)setFrame:(CGRect)frame - (void)setFrame:(CGRect)frame
{ {
BOOL isNonEmpty = (self.width > 0.f && self.height > 0.f);
BOOL didChangeSize = !CGSizeEqualToSize(frame.size, self.frame.size); BOOL didChangeSize = !CGSizeEqualToSize(frame.size, self.frame.size);
[super setFrame:frame]; [super setFrame:frame];
if (didChangeSize) { if (didChangeSize && isNonEmpty) {
[self.textViewPasteDelegate textViewDidChangeSize]; [self.textViewPasteDelegate textViewDidChangeSize];
} }
} }
- (void)setBounds:(CGRect)bounds - (void)setBounds:(CGRect)bounds
{ {
BOOL isNonEmpty = (self.width > 0.f && self.height > 0.f);
BOOL didChangeSize = !CGSizeEqualToSize(bounds.size, self.bounds.size); BOOL didChangeSize = !CGSizeEqualToSize(bounds.size, self.bounds.size);
[super setBounds:bounds]; [super setBounds:bounds];
if (didChangeSize) { if (didChangeSize && isNonEmpty) {
[self.textViewPasteDelegate textViewDidChangeSize]; [self.textViewPasteDelegate textViewDidChangeSize];
} }
} }
@ -635,6 +637,7 @@ typedef enum : NSUInteger {
@property (nonatomic) NSCache *messageAdapterCache; @property (nonatomic) NSCache *messageAdapterCache;
@property (nonatomic) BOOL userHasScrolled; @property (nonatomic) BOOL userHasScrolled;
@property (nonatomic) NSDate *lastMessageSentDate; @property (nonatomic) NSDate *lastMessageSentDate;
@property (nonatomic) NSTimer *scrollToBottomTimer;
@end @end
@ -999,6 +1002,9 @@ typedef enum : NSUInteger {
- (void)scrollToDefaultPosition - (void)scrollToDefaultPosition
{ {
[self.scrollToBottomTimer invalidate];
self.scrollToBottomTimer = nil;
NSIndexPath *_Nullable indexPath = [self indexPathOfUnreadMessagesIndicator]; NSIndexPath *_Nullable indexPath = [self indexPathOfUnreadMessagesIndicator];
if (indexPath) { if (indexPath) {
[self.collectionView scrollToItemAtIndexPath:indexPath [self.collectionView scrollToItemAtIndexPath:indexPath
@ -3663,10 +3669,23 @@ typedef enum : NSUInteger {
BOOL wasAtBottom = [self isScrolledToBottom]; BOOL wasAtBottom = [self isScrolledToBottom];
if (wasAtBottom) { if (wasAtBottom) {
dispatch_async(dispatch_get_main_queue(), ^{ [self.scrollToBottomTimer invalidate];
[self scrollToBottomAnimated:NO]; self.scrollToBottomTimer = [NSTimer weakScheduledTimerWithTimeInterval:0.001f
}); target:self
selector:@selector(scrollToBottomImmediately)
userInfo:nil
repeats:NO];
}
} }
- (void)scrollToBottomImmediately
{
OWSAssert([NSThread isMainThread]);
[self.scrollToBottomTimer invalidate];
self.scrollToBottomTimer = nil;
[self scrollToBottomAnimated:NO];
} }
#pragma mark - OWSMessagesToolbarContentDelegate #pragma mark - OWSMessagesToolbarContentDelegate

Loading…
Cancel
Save