Browse Source

fix: ios页面无法滚动的bug

master
xsx 7 months ago
parent
commit
20b8fb2397
  1. 22
      im-uniapp/pages/chat/chat-box.vue

22
im-uniapp/pages/chat/chat-box.vue

@ -866,12 +866,13 @@ export default {
return; return;
} }
if (uni.getSystemInfoSync().platform == 'ios') { if (uni.getSystemInfoSync().platform == 'ios') {
// ios h5
window.addEventListener('focusin', this.focusInListener);
window.addEventListener('focusout', this.focusOutListener);
// ios13 // ios13
if (window.visualViewport) { if (window.visualViewport) {
window.visualViewport.addEventListener('resize', this.resizeListener); window.visualViewport.addEventListener('resize', this.resizeListener);
} else {
// ios h5
window.addEventListener('focusin', this.focusInListener);
window.addEventListener('focusout', this.focusOutListener);
} }
} else { } else {
// h5 // h5
@ -885,9 +886,12 @@ export default {
}, },
unListenKeyboard() { unListenKeyboard() {
// #ifdef H5 // #ifdef H5
window.removeEventListener('resize', this.resizeListener);
window.removeEventListener('focusin', this.focusInListener); window.removeEventListener('focusin', this.focusInListener);
window.removeEventListener('focusout', this.focusOutListener); window.removeEventListener('focusout', this.focusOutListener);
window.removeEventListener('resize', this.resizeListener);
if (window.visualViewport) {
window.visualViewport.removeEventListener('resize', this.resizeListener);
}
// #endif // #endif
// #ifndef H5 // #ifndef H5
uni.offKeyboardHeightChange(this.keyBoardListener); uni.offKeyboardHeightChange(this.keyBoardListener);
@ -906,12 +910,14 @@ export default {
if (window.visualViewport && uni.getSystemInfoSync().platform == 'ios') { if (window.visualViewport && uni.getSystemInfoSync().platform == 'ios') {
keyboardHeight = this.initHeight - window.visualViewport.height; keyboardHeight = this.initHeight - window.visualViewport.height;
} }
console.log("resizeListener:", window.visualViewport.height) let isShowKeyBoard = keyboardHeight > 150;
this.isShowKeyBoard = keyboardHeight > 150; if (isShowKeyBoard) {
if (this.isShowKeyBoard) {
this.keyboardHeight = keyboardHeight; this.keyboardHeight = keyboardHeight;
} }
setTimeout(() => this.reCalChatMainHeight(), 30); if (this.isShowKeyBoard != isShowKeyBoard) {
this.isShowKeyBoard = isShowKeyBoard;
setTimeout(() => this.reCalChatMainHeight(), 30);
}
}, },
focusInListener() { focusInListener() {
this.isShowKeyBoard = true; this.isShowKeyBoard = true;

Loading…
Cancel
Save