diff options
| author | eugenijm <eugenijm@protonmail.com> | 2020-05-07 16:10:53 +0300 |
|---|---|---|
| committer | eugenijm <eugenijm@protonmail.com> | 2020-07-08 15:21:31 +0300 |
| commit | aa2cf51c05ebdf411d74af5debbbc8fa4d3cf457 (patch) | |
| tree | 6032c3ee359b20cefca000df93b59787fc0d54d9 /src/components/chat/chat_layout_utils.js | |
| parent | a0ddcbdf5b19f658bc07086beaa4034a6309fe3b (diff) | |
Add Chats
Diffstat (limited to 'src/components/chat/chat_layout_utils.js')
| -rw-r--r-- | src/components/chat/chat_layout_utils.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/components/chat/chat_layout_utils.js b/src/components/chat/chat_layout_utils.js new file mode 100644 index 00000000..f07ba2a1 --- /dev/null +++ b/src/components/chat/chat_layout_utils.js @@ -0,0 +1,27 @@ +// Captures a scroll position +export const getScrollPosition = (el) => { + return { + scrollTop: el.scrollTop, + scrollHeight: el.scrollHeight, + offsetHeight: el.offsetHeight + } +} + +// 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 = (el, offset = 0) => { + if (!el) { return } + const scrollHeight = el.scrollTop + offset + const totalHeight = el.scrollHeight - el.offsetHeight + return totalHeight <= scrollHeight +} + +// Height of the scrollable container. The dynamic height is needed to ensure the mobile browser panel doesn't overlap or hide the posting form. +export const scrollableContainerHeight = (inner, header, footer) => { + const height = parseFloat(getComputedStyle(inner, null).height.replace('px', '')) + return height - header.clientHeight - footer.clientHeight +} |
