aboutsummaryrefslogtreecommitdiff
path: root/src/components/chat/chat_layout_utils.js
diff options
context:
space:
mode:
authorMark Felder <feld@FreeBSD.org>2020-07-13 13:25:23 -0500
committerMark Felder <feld@FreeBSD.org>2020-07-13 13:25:23 -0500
commitda94935aaa18f16ac7fbe715c4610427d68ccf72 (patch)
tree52691b7cbac2773858b245e596d56c1c5e6ea74b /src/components/chat/chat_layout_utils.js
parent2eda3d687e8c986a982057c6f5eb969aa8d403d5 (diff)
parent3e09a708f600b47dde831eeddb412828b38a0cf4 (diff)
Merge branch 'develop' into refactor/notification_settings
Diffstat (limited to 'src/components/chat/chat_layout_utils.js')
-rw-r--r--src/components/chat/chat_layout_utils.js26
1 files changed, 26 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..609dc0c9
--- /dev/null
+++ b/src/components/chat/chat_layout_utils.js
@@ -0,0 +1,26 @@
+// 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) => {
+ return inner.offsetHeight - header.clientHeight - footer.clientHeight
+}