Skip to content

Commit

Permalink
Merge pull request #1280 from xiaoguzhu/LayaAir_3.0.0
Browse files Browse the repository at this point in the history
fix: dont lock browser's viewport meta
  • Loading branch information
xiaoguzhu authored Nov 17, 2023
2 parents 1212315 + fe527d3 commit 68eade4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/layaAir/laya/display/Stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class Stage extends Sprite {

// Safari横屏工具栏偏移
if (Browser.onSafari)
this._safariOffsetY = (Browser.window.__innerHeight || Browser.document.body.clientHeight || Browser.document.documentElement.clientHeight) - Browser.window.innerHeight;
this._safariOffsetY = Browser.getSafariToolbarOffset();

if (this.screenAdaptationEnabled) {
this.event(Event.WILL_RESIZE);
Expand Down
40 changes: 29 additions & 11 deletions src/layaAir/laya/utils/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,34 @@ export class Browser {

//强制修改meta标签,防止开发者写错
var metas: any[] = doc.getElementsByTagName('meta');
var i: number = 0, flag: boolean = false, content: any = 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no';
while (i < metas.length) {
var meta: any = metas[i];
if (meta.name == 'viewport') {
meta.content = content;
flag = true;
let viewportContent: Record<string, string> = {
"width": "device-width",
"initial-scale": "1.0",
"minimum-scale": "1.0",
"maximum-scale": "1.0",
"user-scalable": "no"
};
let viewport: any;
for (const meta of metas) {
if (meta.name == "viewport") {
viewport = meta;
break;
}
i++;
}
if (!flag) {
meta = doc.createElement('meta');
meta.name = 'viewport', meta.content = content;
doc.getElementsByTagName('head')[0].appendChild(meta);
if (!viewport) {
viewport = doc.createElement('meta');
viewport.name = 'viewport';
doc.getElementsByTagName('head')[0]?.appendChild(viewport);
}
else {
let arr: Array<string> = (viewport.content || "").split(",");
for (let ele of arr) {
let arr2 = ele.split("=");
if (!viewportContent[arr2[0].trim()])
viewportContent[arr2[0]] = arr2[1];
}
}
viewport.content = Object.keys(viewportContent).map(k => k + "=" + viewportContent[k]);

//处理兼容性
Browser.onMobile = (window as any).conch ? true : u.indexOf("Mobile") > -1;
Expand Down Expand Up @@ -472,5 +485,10 @@ export class Browser {
if (r != null) return unescape(r[2]);
return null;
}

// Safari横屏工具栏偏移
static getSafariToolbarOffset() {
return (Browser.window.__innerHeight || Browser.document.body.clientHeight || Browser.document.documentElement.clientHeight) - Browser.window.innerHeight;
}
}

0 comments on commit 68eade4

Please # to comment.