@@ -2793,6 +2793,7 @@ - (void)viewDidLayoutSubviews
27932793 [super viewDidLayoutSubviews ];
27942794
27952795 [self updateLastVisibleTimestamp ];
2796+ [self ensureScrollDownButton ];
27962797}
27972798
27982799- (void )createScrollDownButton
@@ -2838,13 +2839,23 @@ - (void)ensureScrollDownButton
28382839
28392840 BOOL shouldShowScrollDownButton = NO ;
28402841 NSUInteger numberOfMessages = [self .messageMappings numberOfItemsInSection: 0 ];
2842+ CGFloat scrollSpaceToBottom = (self.collectionView .contentSize .height + self.collectionView .contentInset .bottom
2843+ - (self.collectionView .contentOffset .y + self.collectionView .frame .size .height ));
2844+ CGFloat pageHeight = (self.collectionView .frame .size .height
2845+ - (self.collectionView .contentInset .top + self.collectionView .contentInset .bottom ));
2846+ // Show "scroll down" button if user is scrolled up at least
2847+ // one page.
2848+ BOOL isScrolledUp = scrollSpaceToBottom > pageHeight * 1 .f ;
2849+
28412850 if (numberOfMessages > 0 ) {
28422851 TSInteraction *lastInteraction =
28432852 [self interactionAtIndexPath: [NSIndexPath indexPathForRow: (NSInteger )numberOfMessages - 1 inSection: 0 ]];
28442853 OWSAssert (lastInteraction);
28452854
28462855 if (lastInteraction.timestampForSorting > self.lastVisibleTimestamp ) {
28472856 shouldShowScrollDownButton = YES ;
2857+ } else if (isScrolledUp) {
2858+ shouldShowScrollDownButton = YES ;
28482859 }
28492860 }
28502861
@@ -3992,7 +4003,7 @@ - (void)showErrorAlertForAttachment:(SignalAttachment *_Nullable)attachment
39924003 [self presentViewController: controller animated: YES completion: nil ];
39934004}
39944005
3995- - (void )textViewDidChangePosition
4006+ - (void )textViewDidChangeLayout
39964007{
39974008 OWSAssert ([NSThread isMainThread ]);
39984009
@@ -4006,6 +4017,8 @@ - (void)textViewDidChangePosition
40064017 userInfo: nil
40074018 repeats: NO ];
40084019 }
4020+
4021+ [self ensureScrollDownButton ];
40094022}
40104023
40114024- (void )scrollToBottomImmediately
@@ -4096,6 +4109,8 @@ - (void)textViewDidChange:(UITextView *)textView
40964109 // We want to show the "voice message" button if the text input is empty
40974110 // and the "send" button if it isn't.
40984111 [((OWSMessagesToolbarContentView *)self .inputToolbar.contentView)ensureEnabling];
4112+
4113+ [self ensureScrollDownButton ];
40994114}
41004115
41014116#pragma mark - UIScrollViewDelegate
@@ -4162,7 +4177,6 @@ - (void)popAllConversationSettingsViews
41624177
41634178#pragma mark - OWSMessagesCollectionViewFlowLayoutDelegate
41644179
4165-
41664180- (BOOL )shouldShowCellDecorationsAtIndexPath: (NSIndexPath *)indexPath
41674181{
41684182 TSInteraction *interaction = [self interactionAtIndexPath: indexPath];
0 commit comments