提交 b988c251 编写于 作者: Q qiang

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

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