提交 b988c251 编写于 作者: Q qiang

fix: 解决部分设备上窗口变化事件重复触发的问题

上级 0093bba5
const callbacks = []
var tasks = []
function onResize () {
tasks.push(setTimeout(() => {
tasks.forEach(task => clearTimeout(task))
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge
callbacks.forEach(callbackId => {
const {
windowWidth,
windowHeight,
screenWidth,
screenHeight
} = uni.getSystemInfoSync()
var landscape = typeof window.orientation === 'number' ? Math.abs(window.orientation) === 90 : screenWidth / screenHeight > 1
var landscape = Math.abs(window.orientation) === 90
var deviceOrientation = landscape ? 'landscape' : 'portrait'
callbacks.forEach(callbackId => {
invoke(callbackId, {
deviceOrientation,
size: {
......@@ -24,6 +29,7 @@ function onResize () {
}
})
})
}, 10))
}
/**
* 监听窗口大小变化
......@@ -40,13 +46,8 @@ export function onWindowResize (callbackId) {
* @param {*} callbackId
*/
export function offWindowResize (callbackId) {
var index = callbacks.indexOf(callbackId)
// 此处和微信平台一致查询不到去掉最后一个
if (index >= 0) {
callbacks.splice(index, 1)
} else {
callbacks.pop()
}
callbacks.splice(callbacks.indexOf(callbackId), 1)
if (!callbacks.length) {
window.removeEventListener('resize', onResize)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册