Allow specifying scroll behavior on initial chat history load
This commit is contained in:
@@ -187,7 +187,7 @@ export default class Chat extends Component {
|
|||||||
this.handleNetworkingError(`Fetch getChatHistory: ${error}`);
|
this.handleNetworkingError(`Fetch getChatHistory: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scrollToBottom();
|
jumpToBottom(this.scrollableMessagesContainer.current, 'instant');
|
||||||
}
|
}
|
||||||
|
|
||||||
receivedWebsocketMessage(message) {
|
receivedWebsocketMessage(message) {
|
||||||
|
|||||||
@@ -24,15 +24,19 @@ export function clearLocalStorage(key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// jump down to the max height of a div, with a slight delay
|
// jump down to the max height of a div, with a slight delay
|
||||||
export function jumpToBottom(element) {
|
export function jumpToBottom(element, behavior) {
|
||||||
if (!element) return;
|
if (!element) return;
|
||||||
|
|
||||||
|
if (!behavior) {
|
||||||
|
behavior = document.visibilityState === 'visible' ? 'smooth' : 'instant';
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(
|
setTimeout(
|
||||||
() => {
|
() => {
|
||||||
element.scrollTo({
|
element.scrollTo({
|
||||||
top: element.scrollHeight,
|
top: element.scrollHeight,
|
||||||
left: 0,
|
left: 0,
|
||||||
behavior: document.visibilityState === 'visible' ? 'smooth' : 'instant',
|
behavior: behavior,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
50,
|
50,
|
||||||
|
|||||||
Reference in New Issue
Block a user