aboutsummaryrefslogtreecommitdiff
path: root/src/components/chat/chat_layout_utils.js
blob: c187892d9c527c65099fc8a6bf77deee34cab9ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Captures a scroll position
export const getScrollPosition = () => {
  return {
    scrollTop: window.scrollY,
    scrollHeight: document.documentElement.scrollHeight,
    offsetHeight: window.innerHeight
  }
}

// A helper function that is used to keep the scroll position fixed as the new elements are added to the top
// Takes two scroll positions, before and after the update.
export const getNewTopPosition = (previousPosition, newPosition) => {
  return previousPosition.scrollTop + (newPosition.scrollHeight - previousPosition.scrollHeight)
}

export const isBottomedOut = (offset = 0) => {
  const scrollHeight = window.scrollY + offset
  const totalHeight = document.documentElement.scrollHeight - window.innerHeight
  return totalHeight <= scrollHeight
}
// Returns whether or not the scrollbar is visible.
export const isScrollable = () => {
  return document.documentElement.scrollHeight > window.innerHeight
}