Skip to content

Commit d009289

Browse files
committed
Merge branch 'charlesmchen/moreScrollDownButton'
2 parents 89c252a + f7c81ba commit d009289

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Signal/src/ViewControllers/ConversationView/MessagesViewController.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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];

Signal/src/ViewControllers/ConversationView/OWSMessagesComposerTextView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
1212

1313
- (void)didPasteAttachment:(SignalAttachment *_Nullable)attachment;
1414

15-
- (void)textViewDidChangePosition;
15+
- (void)textViewDidChangeLayout;
1616

1717
@end
1818

Signal/src/ViewControllers/ConversationView/OWSMessagesComposerTextView.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ - (BOOL)becomeFirstResponder
1919
BOOL becameFirstResponder = [super becomeFirstResponder];
2020
if (becameFirstResponder) {
2121
// Intercept to scroll to bottom when text view is tapped.
22-
[self.textViewPasteDelegate textViewDidChangePosition];
22+
[self.textViewPasteDelegate textViewDidChangeLayout];
2323
}
2424
return becameFirstResponder;
2525
}
@@ -61,7 +61,7 @@ - (void)setFrame:(CGRect)frame
6161
[super setFrame:frame];
6262

6363
if (didChangeSize && isNonEmpty) {
64-
[self.textViewPasteDelegate textViewDidChangePosition];
64+
[self.textViewPasteDelegate textViewDidChangeLayout];
6565
}
6666
}
6767

@@ -73,7 +73,7 @@ - (void)setBounds:(CGRect)bounds
7373
[super setBounds:bounds];
7474

7575
if (didChangeSize && isNonEmpty) {
76-
[self.textViewPasteDelegate textViewDidChangePosition];
76+
[self.textViewPasteDelegate textViewDidChangeLayout];
7777
}
7878
}
7979

0 commit comments

Comments
 (0)