mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2024-12-26 03:38:29 +00:00
30 lines
1.1 KiB
JavaScript
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 (CC_JSB && (cc.sys.os === cc.sys.OS_IOS || cc.sys.os === cc.sys.OS_ANDROID)) {
|
|
setTimeout(() => {
|
|
this.updateArea();
|
|
}, 200);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|