Comments (6)
Could i know how to reproduce it?
from cocos-engine.
我的设备是IPhone 11, 系统是13.6版本,大概4年前的系统。
报错原因是用了matchMedia,并且调用它的addEventListener方法,我抓它的报错了,确实没有addEventListener方法。
虽然addListener被标记为已启用,但一些系统钉子户,仍然不支持最新的addEventListener方法。
我目前的临时兼容处理(window上的addEventListener可用,new EventTarget不可用):
// 兼容某些旧机型,无法使用MediaQueryList.prototype.addEventListener
if ('function' == typeof window.matchMedia) {
const matchMedia = window.matchMedia;
window.matchMedia = function (query: string): MediaQueryList {
const res = matchMedia.call(window, query) as MediaQueryList;
if (!res.addEventListener && res.addListener) {
const callback = function (this: MediaQueryList, ev: MediaQueryListEvent) {
window.dispatchEvent(new Event('matchMedia:' + ev.type, {
bubbles: ev.bubbles,
cancelable: ev.cancelable,
composed: ev.composed
}));
};
let listenerAdded = false;
res.addEventListener = function (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) {
window.addEventListener('matchMedia:' + type, listener, options);
if (listenerAdded === false) {
listenerAdded = true;
res.addListener(callback);
}
};
res.removeEventListener = function (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) {
window.removeEventListener('matchMedia:' + type, listener, options);
};
}
return res;
};
}
from cocos-engine.
我搜索了代码,screen-adapter.ts 里用到了 window.matchMedia
if (typeof window.matchMedia === 'function') {
const updateDPRChangeListener = (): void => {
const dpr = window.devicePixelRatio;
// NOTE: some browsers especially on iPhone doesn't support MediaQueryList
window.matchMedia(`(resolution: ${dpr}dppx)`)?.addEventListener?.('change', (): void => {
this.emit('window-resize', this.windowSize.width, this.windowSize.height);
updateDPRChangeListener();
}, { once: true });
};
...
}
这里对 addEventListener
是否存在做了判断,所以没太明白为什么还会有上面的代码。
from cocos-engine.
from cocos-engine.
@bofeng-song 看一下,我看是你加的代码。
from cocos-engine.
建议最好可以兼容一下,addEventListener不存在就用addListener
from cocos-engine.
Related Issues (20)
- 编辑器预览和浏览器预览不显示 HOT 1
- Metal swapchain accessed in non-ui thread
- Custom pipeline preview bug list
- [3.8.2] When the high refresh rate mode is enabled, the game FPS cannot be modified, and the FPS limit will automatically change to 65.
- Button,ProgressBar,EditBox等的子节点Label,Bar, TEXTLABEL,PLACEHOLDER_LABEL在创建时其layer没有跟随父节点
- (Cocos Creator - CI/CD) Endless build build via cmd on build agent teamcity: Stops at this log and loads endlessly - [Package] [email protected] enable HOT 1
- Forcing SafeAreaEdge to be symmetrical in ScreenAdapter
- Build machine hangs trying to download a cocos-service.zip but we don't use services
- 383 Label and Mask component lead to App crash on Xcode. HOT 1
- 希望编辑器能支持拖拽任意扩展名的文本文件 到 cc.TextAsset属性框上.
- 2D渲染时, 某些情况下会莫名其妙的断批
- [2.4.x, native] Memory leak in WebSocket binding
- Releasing the LMB outside the canvas keeps MouseInput._isPressed boolean true
- "HEADERS_RECEIVED"和"LOADING"这两个状态根本不会设置,实际请求过程中只有“OPENED”“DONE”这两个状态有用到。这里后续会完善吗?
- 希望能考虑下出差办公的程序员, 不要"断网不可用"
- 希望能考虑下出差办公的程序员, 不要"断网不可用". HOT 6
- IDE的自动图集预览时, 希望能显示一下生成的图集的尺寸
- 网上平台创建动态网格报错
- 希望提供一个通过 spriteFrame 获得 cc.Texture2D 的API HOT 3
- tiled-map 的 doCleanupImageCache() 压根不会被执行.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cocos-engine.