Skip to content

Commit aff3dbf

Browse files
committed
(fix) scroll bouncing issue on iOS
1 parent 4c73127 commit aff3dbf

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/ChatWindow/Room.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ import SvgIcon from './SvgIcon'
338338
import EmojiPicker from './EmojiPicker'
339339
340340
const { messagesValid } = require('../utils/roomValidation')
341-
const { detectMobile } = require('../utils/mobileDetection')
341+
const { detectMobile, iOSDevice } = require('../utils/mobileDetection')
342342
import typingText from '../utils/typingText'
343343
344344
export default {
@@ -690,15 +690,21 @@ export default {
690690
this.resetMessage(true)
691691
},
692692
loadMoreMessages(infiniteState) {
693-
if (this.loadingMoreMessages) return
694-
695-
if (this.messagesLoaded || !this.room.roomId) {
696-
return infiniteState.complete()
697-
}
698-
699-
this.infiniteState = infiniteState
700-
this.$emit('fetch-messages')
701-
this.loadingMoreMessages = true
693+
setTimeout(
694+
() => {
695+
if (this.loadingMoreMessages) return
696+
697+
if (this.messagesLoaded || !this.room.roomId) {
698+
return infiniteState.complete()
699+
}
700+
701+
this.infiniteState = infiniteState
702+
this.$emit('fetch-messages')
703+
this.loadingMoreMessages = true
704+
},
705+
// prevent scroll bouncing issue on iOS devices
706+
iOSDevice() ? 500 : 0
707+
)
702708
},
703709
messageActionHandler({ action, message }) {
704710
switch (action.name) {

src/utils/mobileDetection.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ function getUserAgent() {
2121

2222
return userAgent
2323
}
24+
25+
export function iOSDevice() {
26+
return (
27+
['iPad', 'iPhone', 'iPod'].includes(navigator.platform) ||
28+
(navigator.userAgent.includes('Mac') && 'ontouchend' in document)
29+
)
30+
}

0 commit comments

Comments
 (0)