cocos-enhance-kit/jsb-adapter/engine/jsb-safearea.js

30 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-06-24 16:23:03 +00:00
let SafeArea = cc.SafeArea;
if (SafeArea) {
let _onEnable = SafeArea.prototype.onEnable;
let _onDisable = SafeArea.prototype.onDisable;
Object.assign(SafeArea.prototype, {
onEnable(){
_onEnable.call(this);
this._adaptSafeAreaChangeWithThis = this.adaptSafeAreaChange.bind(this);
this._updateAreaWithThis = this.adaptSafeAreaChange.bind(this);
window.addEventListener('orientationchange', this._adaptSafeAreaChangeWithThis);
window.addEventListener('safearea-change', this._updateAreaWithThis);
},
onDisable(){
_onDisable.call(this);
window.removeEventListener('orientationchange', this._adaptSafeAreaChangeWithThis);
window.removeEventListener('safearea-change', this._updateAreaWithThis);
},
adaptSafeAreaChange(){
if (CC_JSB && (cc.sys.os === cc.sys.OS_IOS || cc.sys.os === cc.sys.OS_ANDROID)) {
setTimeout(() => {
this.updateArea();
}, 200);
}
}
});
}