Skip to content

Commit 0946874

Browse files
committed
fix(polyfill): device rotation size
1 parent c6f30f4 commit 0946874

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

packages/canvas-polyfill/resize.ts

Lines changed: 23 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,34 @@
1-
import {Screen} from "@nativescript/core";
2-
import {Application} from "@nativescript/core";
1+
import { Screen } from '@nativescript/core';
2+
import { Application } from '@nativescript/core';
33
/*
44
Window Resize Stub
55
*/
66

77
const scale = Screen.mainScreen.scale;
88

99
(global as any).window.devicePixelRatio = (global as any).devicePixelRatio = 1;
10-
(global as any).window.innerWidth = (global as any).innerWidth =
11-
Screen.mainScreen.widthPixels;
12-
(global as any).window.clientWidth = (global as any).clientWidth =
13-
Screen.mainScreen.widthPixels;
14-
(global as any).window.innerHeight = (global as any).innerHeight =
15-
Screen.mainScreen.heightPixels;
16-
(global as any).window.clientHeight = (global as any).clientHeight =
17-
Screen.mainScreen.heightPixels;
18-
(global as any).window.screen = (global as any).screen =
19-
(global as any).screen || {};
20-
(global as any).window.screen.orientation = (global as any).screen.orientation =
21-
(global as any).screen.orientation ||
22-
(global as any).clientWidth < (global as any).clientHeight
23-
? 0
24-
: 90;
10+
(global as any).window.innerWidth = (global as any).innerWidth = Screen.mainScreen.widthPixels;
11+
(global as any).window.clientWidth = (global as any).clientWidth = Screen.mainScreen.widthPixels;
12+
(global as any).window.innerHeight = (global as any).innerHeight = Screen.mainScreen.heightPixels;
13+
(global as any).window.clientHeight = (global as any).clientHeight = Screen.mainScreen.heightPixels;
14+
(global as any).window.screen = (global as any).screen = (global as any).screen || {};
15+
(global as any).window.screen.orientation = (global as any).screen.orientation = (global as any).screen.orientation || (global as any).clientWidth < (global as any).clientHeight ? 0 : 90;
2516

2617
if (!(global as any).__TNS_BROWSER_POLYFILL_RESIZE) {
27-
(global as any).__TNS_BROWSER_POLYFILL_RESIZE = true;
28-
Application.on("orientationChanged", (args) => {
29-
let width = 0;
30-
let height = 0;
31-
switch (args.newValue) {
32-
case "portrait":
33-
width = Screen.mainScreen.widthPixels;
34-
height = Screen.mainScreen.heightPixels;
35-
break;
36-
default:
37-
width = Screen.mainScreen.heightPixels;
38-
height = Screen.mainScreen.widthPixels;
39-
break;
40-
}
18+
(global as any).__TNS_BROWSER_POLYFILL_RESIZE = true;
19+
Application.on(Application.orientationChangedEvent, (args) => {
20+
let width = Screen.mainScreen.widthPixels;
21+
let height = Screen.mainScreen.heightPixels;
4122

42-
(global as any).window.devicePixelRatio = (global as any).devicePixelRatio = scale;
43-
(global as any).window.innerWidth = (global as any).innerWidth = width;
44-
(global as any).window.clientWidth = (global as any).clientWidth = width;
45-
(global as any).window.innerHeight = (global as any).innerHeight = height;
46-
(global as any).window.clientHeight = (global as any).clientHeight = height;
47-
(global as any).window.orientation = (global as any).orientation =
48-
args.newValue === "portrait" ? 0 : 90;
49-
(global as any).window.screen.orientation = (global as any).screen.orientation = (global as any).orientation;
50-
if ((global as any).emitter && (global as any).emitter.emit) {
51-
(global as any).emitter.emit("resize");
52-
}
53-
});
23+
(global as any).window.devicePixelRatio = (global as any).devicePixelRatio = scale;
24+
(global as any).window.innerWidth = (global as any).innerWidth = width;
25+
(global as any).window.clientWidth = (global as any).clientWidth = width;
26+
(global as any).window.innerHeight = (global as any).innerHeight = height;
27+
(global as any).window.clientHeight = (global as any).clientHeight = height;
28+
(global as any).window.orientation = (global as any).orientation = args.newValue === 'portrait' ? 0 : 90;
29+
(global as any).window.screen.orientation = (global as any).screen.orientation = (global as any).orientation;
30+
if ((global as any).emitter && (global as any).emitter.emit) {
31+
(global as any).emitter.emit('resize');
32+
}
33+
});
5434
}

0 commit comments

Comments
 (0)