3030 </room-header >
3131
3232 <div
33+ id =" messages-list"
3334 ref =" scrollContainer"
3435 class =" vac-container-scroll"
3536 @scroll =" onContainerScroll"
5354 </div >
5455 </div >
5556 </transition >
56- <transition name =" vac-fade-message" >
57- <infinite-loading
58- v-if =" messages.length"
59- :class =" { 'vac-infinite-loading': !messagesLoaded }"
60- force-use-infinite-wrapper =" .vac-container-scroll"
61- web-component-name =" vue-advanced-chat"
62- spinner =" spiral"
63- direction =" top"
64- :distance =" 40"
65- @infinite =" loadMoreMessages"
66- >
67- <template #spinner >
68- <loader :show =" true" :infinite =" true" >
69- <template v-for =" (idx , name ) in $scopedSlots " #[name ]=" data " >
70- <slot :name =" name" v-bind =" data" />
71- </template >
72- </loader >
73- </template >
74- <template #no-results >
75- <div />
76- </template >
77- <template #no-more >
78- <div />
57+ <div
58+ v-if =" messages.length && !messagesLoaded"
59+ id =" infinite-loader-messages"
60+ >
61+ <loader :show =" true" :infinite =" true" >
62+ <template v-for =" (idx , name ) in $scopedSlots " #[name ]=" data " >
63+ <slot :name =" name" v-bind =" data" />
7964 </template >
80- </infinite-loading >
81- </transition >
65+ </loader >
66+ </div >
8267 <transition-group :key =" roomId" name =" vac-fade-message" tag =" span" >
8368 <div v-for =" (m, i) in messages" :key =" m.indexId || m._id" >
8469 <message
316301</template >
317302
318303<script >
319- import InfiniteLoading from ' vue-infinite-loading'
320304import vClickOutside from ' v-click-outside'
321305import { Database } from ' emoji-picker-element'
322306
@@ -335,7 +319,7 @@ import Message from '../Message/Message'
335319import filteredItems from ' ../../utils/filter-items'
336320import Recorder from ' ../../utils/recorder'
337321
338- const { detectMobile , iOSDevice } = require (' ../../utils/mobile-detection' )
322+ const { detectMobile } = require (' ../../utils/mobile-detection' )
339323
340324const debounce = (func , delay ) => {
341325 let inDebounce
@@ -350,7 +334,6 @@ const debounce = (func, delay) => {
350334export default {
351335 name: ' Room' ,
352336 components: {
353- InfiniteLoading,
354337 Loader,
355338 SvgIcon,
356339 EmojiPickerContainer,
@@ -422,6 +405,8 @@ export default {
422405 messageReply: null ,
423406 infiniteState: null ,
424407 loadingMessages: false ,
408+ observer: null ,
409+ showLoader: true ,
425410 loadingMoreMessages: false ,
426411 files: [],
427412 fileDialog: false ,
@@ -502,6 +487,7 @@ export default {
502487 } else {
503488 if (this .infiniteState ) this .infiniteState .loaded ()
504489 this .focusTextarea (true )
490+ setTimeout (() => this .initIntersectionObserver ())
505491 }
506492 },
507493 room: {
@@ -596,6 +582,47 @@ export default {
596582 },
597583
598584 methods: {
585+ initIntersectionObserver () {
586+ if (this .observer ) {
587+ this .showLoader = true
588+ this .observer .disconnect ()
589+ }
590+
591+ const loader = document .getElementById (' infinite-loader-messages' )
592+
593+ if (loader) {
594+ const options = {
595+ root: document .getElementById (' messages-list' ),
596+ rootMargin: ' 60px' ,
597+ threshold: 0
598+ }
599+
600+ this .observer = new IntersectionObserver (entries => {
601+ if (entries[0 ].isIntersecting ) {
602+ this .loadMoreMessages ()
603+ }
604+ }, options)
605+
606+ this .observer .observe (loader)
607+ }
608+ },
609+ preventTopScroll () {
610+ const container = this .$refs .scrollContainer
611+ const prevScrollHeight = container .scrollHeight
612+
613+ const observer = new ResizeObserver (_ => {
614+ if (container .scrollHeight !== prevScrollHeight) {
615+ this .$refs .scrollContainer .scrollTo ({
616+ top: container .scrollHeight - prevScrollHeight
617+ })
618+ observer .disconnect ()
619+ }
620+ })
621+
622+ for (var i = 0 ; i < container .children .length ; i++ ) {
623+ observer .observe (container .children [i])
624+ }
625+ },
599626 getTextareaRef () {
600627 return this .$refs .roomTextarea
601628 },
@@ -962,26 +989,25 @@ export default {
962989
963990 this .resetMessage (true )
964991 },
965- loadMoreMessages (infiniteState ) {
966- if (this .loadingMessages ) {
967- this .infiniteState = infiniteState
968- return
969- }
992+ loadMoreMessages () {
993+ if (this .loadingMessages ) return
970994
971995 setTimeout (
972996 () => {
973997 if (this .loadingMoreMessages ) return
974998
975999 if (this .messagesLoaded || ! this .room .roomId ) {
976- return infiniteState .complete ()
1000+ this .loadingMoreMessages = false
1001+ this .showLoader = false
1002+ return
9771003 }
9781004
979- this .infiniteState = infiniteState
1005+ this .preventTopScroll ()
9801006 this .$emit (' fetch-messages' )
9811007 this .loadingMoreMessages = true
9821008 },
983- // prevent scroll bouncing issue on iOS devices
984- iOSDevice () ? 500 : 0
1009+ // prevent scroll bouncing speed
1010+ 500
9851011 )
9861012 },
9871013 messageActionHandler ({ action, message }) {
0 commit comments