Skip to content

Commit d28fbd5

Browse files
authored
Merge pull request #547 from GetStream/restore-hiding-jump-to-bottom-while-scrolling
fix: Restore hideJumpToLatestButtonDuringScroll behavior
2 parents f5b8d23 + c7f1a1a commit d28fbd5

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

projects/stream-chat-angular/src/lib/message-list/message-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
<div class="str-chat__jump-to-latest-message">
214214
<button
215215
data-testid="scroll-to-latest"
216-
*ngIf="isUserScrolled"
216+
*ngIf="isUserScrolled && isJumpToLatestButtonVisible"
217217
class="
218218
str-chat__message-notification-scroll-to-latest
219219
str-chat__message-notification-scroll-to-latest-right

projects/stream-chat-angular/src/lib/message-list/message-list.component.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ export class MessageListComponent
6262
@Input() messageOptionsTrigger: 'message-row' | 'message-bubble' =
6363
'message-row';
6464
/**
65-
* You can hide the "jump to latest" button while scrolling. A potential use-case for this input would be to [workaround a known issue on iOS Safar](https://github.com/GetStream/stream-chat-angular/issues/418)
65+
* You can hide the "jump to latest" button while scrolling. A potential use-case for this input would be to [workaround a known issue on iOS Safar webview](https://github.com/GetStream/stream-chat-angular/issues/418)
6666
*
67-
* @deprecated This scroll issue has been resolved, no need to use this workaround anymore.
6867
*/
6968
@Input() hideJumpToLatestButtonDuringScroll = false;
7069
/**
@@ -124,6 +123,7 @@ export class MessageListComponent
124123
firstUnreadMessageId?: string;
125124
unreadCount?: number;
126125
isJumpingToLatestUnreadMessage = false;
126+
isJumpToLatestButtonVisible = true;
127127
@ViewChild('scrollContainer')
128128
private scrollContainer!: ElementRef<HTMLElement>;
129129
@ViewChild('parentMessageElement')
@@ -148,6 +148,7 @@ export class MessageListComponent
148148
private parsedDates = new Map<Date, string>();
149149
private isViewInited = false;
150150
private checkIfUnreadNotificationIsVisibleTimeout?: any;
151+
private jumpToLatestButtonVisibilityTimeout?: any;
151152

152153
@HostBinding('class')
153154
private get class() {
@@ -525,6 +526,12 @@ export class MessageListComponent
525526
if (this.scrollEndTimeout) {
526527
clearTimeout(this.scrollEndTimeout);
527528
}
529+
if (this.checkIfUnreadNotificationIsVisibleTimeout) {
530+
clearTimeout(this.checkIfUnreadNotificationIsVisibleTimeout);
531+
}
532+
if (this.jumpToLatestButtonVisibilityTimeout) {
533+
clearTimeout(this.jumpToLatestButtonVisibilityTimeout);
534+
}
528535
}
529536

530537
trackByMessageId(index: number, item: StreamMessage) {
@@ -580,6 +587,23 @@ export class MessageListComponent
580587
});
581588
}
582589

590+
if (this.hideJumpToLatestButtonDuringScroll) {
591+
if (this.isJumpToLatestButtonVisible) {
592+
this.isJumpToLatestButtonVisible = false;
593+
this.cdRef.detectChanges();
594+
}
595+
if (this.jumpToLatestButtonVisibilityTimeout) {
596+
clearTimeout(this.jumpToLatestButtonVisibilityTimeout);
597+
}
598+
this.jumpToLatestButtonVisibilityTimeout = setTimeout(() => {
599+
if (this.isUserScrolled) {
600+
this.isJumpToLatestButtonVisible = true;
601+
this.jumpToLatestButtonVisibilityTimeout = undefined;
602+
this.cdRef.detectChanges();
603+
}
604+
}, 100);
605+
}
606+
583607
if (this.shouldLoadMoreMessages(scrollPosition)) {
584608
this.ngZone.run(() => {
585609
this.containerHeight = this.scrollContainer.nativeElement.scrollHeight;

0 commit comments

Comments
 (0)