Fix edge cases in conversation view scroll continuity.

This commit is contained in:
Matthew Chen 2019-01-07 15:08:16 -05:00
parent b92051c881
commit 7df17251a2

View file

@ -102,9 +102,9 @@ typedef enum : NSUInteger {
} kMediaTypes; } kMediaTypes;
typedef enum : NSUInteger { typedef enum : NSUInteger {
kScrollBiasBottom = 0, kScrollContinuityBottom = 0,
kScrollBiasTop, kScrollContinuityTop,
} ScrollBias; } ScrollContinuity;
#pragma mark - #pragma mark -
@ -202,7 +202,7 @@ typedef enum : NSUInteger {
@property (nonatomic) CGFloat scrollDistanceToBottomSnapshot; @property (nonatomic) CGFloat scrollDistanceToBottomSnapshot;
@property (nonatomic, nullable) NSNumber *lastKnownDistanceFromBottom; @property (nonatomic, nullable) NSNumber *lastKnownDistanceFromBottom;
@property (nonatomic) ScrollBias scrollBias; @property (nonatomic) ScrollContinuity scrollContinuity;
@property (nonatomic, nullable) NSTimer *autoLoadMoreTimer; @property (nonatomic, nullable) NSTimer *autoLoadMoreTimer;
@end @end
@ -247,7 +247,7 @@ typedef enum : NSUInteger {
NSString *audioActivityDescription = [NSString stringWithFormat:@"%@ voice note", self.logTag]; NSString *audioActivityDescription = [NSString stringWithFormat:@"%@ voice note", self.logTag];
_recordVoiceNoteAudioActivity = [[OWSAudioActivity alloc] initWithAudioDescription:audioActivityDescription behavior:OWSAudioBehavior_PlayAndRecord]; _recordVoiceNoteAudioActivity = [[OWSAudioActivity alloc] initWithAudioDescription:audioActivityDescription behavior:OWSAudioBehavior_PlayAndRecord];
self.scrollBias = kScrollBiasBottom; self.scrollContinuity = kScrollContinuityBottom;
} }
#pragma mark - Dependencies #pragma mark - Dependencies
@ -810,7 +810,7 @@ typedef enum : NSUInteger {
- (void)resetContentAndLayout - (void)resetContentAndLayout
{ {
self.scrollBias = kScrollBiasBottom; self.scrollContinuity = kScrollContinuityBottom;
// Avoid layout corrupt issues and out-of-date message subtitles. // Avoid layout corrupt issues and out-of-date message subtitles.
self.lastReloadDate = [NSDate new]; self.lastReloadDate = [NSDate new];
[self.conversationViewModel viewDidResetContentAndLayout]; [self.conversationViewModel viewDidResetContentAndLayout];
@ -4282,7 +4282,7 @@ typedef enum : NSUInteger {
- (CGPoint)collectionView:(UICollectionView *)collectionView - (CGPoint)collectionView:(UICollectionView *)collectionView
targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset
{ {
if (self.scrollBias == kScrollBiasBottom && self.lastKnownDistanceFromBottom) { if (self.scrollContinuity == kScrollContinuityBottom && self.lastKnownDistanceFromBottom) {
// Adjust the content offset to reflect the "last known" distance // Adjust the content offset to reflect the "last known" distance
// from the bottom of the content. // from the bottom of the content.
CGFloat contentOffsetYBottom = self.maxContentOffsetY; CGFloat contentOffsetYBottom = self.maxContentOffsetY;
@ -4558,7 +4558,7 @@ typedef enum : NSUInteger {
// if the user is inserting new interactions. // if the user is inserting new interactions.
__block BOOL scrollToBottom = NO; __block BOOL scrollToBottom = NO;
self.scrollBias = ([self isScrolledToBottom] ? kScrollBiasBottom : kScrollBiasTop); self.scrollContinuity = ([self isScrolledToBottom] ? kScrollContinuityBottom : kScrollContinuityTop);
void (^batchUpdates)(void) = ^{ void (^batchUpdates)(void) = ^{
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
@ -4701,8 +4701,6 @@ typedef enum : NSUInteger {
// We want to restore the current scroll state after we update the range, update // We want to restore the current scroll state after we update the range, update
// the dynamic interactions and re-layout. Here we take a "before" snapshot. // the dynamic interactions and re-layout. Here we take a "before" snapshot.
self.scrollDistanceToBottomSnapshot = self.safeContentHeight - self.collectionView.contentOffset.y; self.scrollDistanceToBottomSnapshot = self.safeContentHeight - self.collectionView.contentOffset.y;
self.scrollBias = kScrollBiasBottom;
} }
- (void)conversationViewModelDidLoadMoreItems - (void)conversationViewModelDidLoadMoreItems