Files
cocos4/platforms/native/engine/jsb-safearea.js
T
PP e3e1db619f move port/native into platforms/native (#7963)
* Revert "move in port/native to platforms/native (#7962)"

This reverts commit 96871ba26b.

* move port/native into platforms/native
2020-12-15 12:43:16 +08:00

30 lines
1.1 KiB
JavaScript

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 (JSB && (cc.sys.os === cc.sys.OS_IOS || cc.sys.os === cc.sys.OS_ANDROID)) {
setTimeout(() => {
this.updateArea();
}, 200);
}
}
});
}