File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,4 @@ export * from "./prevent-close";
88export * from "./network" ;
99export * from "./vibration" ;
1010export * from "./geolocation" ;
11+ export * from "./screen-info" ;
Original file line number Diff line number Diff line change 1+ export interface ScreenInfo {
2+ width : number ;
3+ height : number ;
4+ availWidth : number ;
5+ availHeight : number ;
6+ devicePixelRatio : number ;
7+ orientation : string ;
8+ isLandscape : boolean ;
9+ }
10+
11+ /**
12+ * Get current screen and viewport info
13+ */
14+ export function getScreenInfo ( ) : ScreenInfo {
15+ const orientation =
16+ ( screen . orientation || { } ) . type || "unknown" ;
17+
18+ return {
19+ width : window . innerWidth ,
20+ height : window . innerHeight ,
21+ availWidth : screen . availWidth ,
22+ availHeight : screen . availHeight ,
23+ devicePixelRatio : window . devicePixelRatio ,
24+ orientation : orientation ,
25+ isLandscape : window . innerWidth > window . innerHeight
26+ } ;
27+ }
28+
29+ /**
30+ * Listen for screen size changes (resize/orientation change)
31+ */
32+ export function onScreenResize (
33+ callback : ( info : ScreenInfo ) => void
34+ ) : void {
35+ const handler = ( ) => callback ( getScreenInfo ( ) ) ;
36+
37+ window . addEventListener ( "resize" , handler ) ;
38+ window . addEventListener ( "orientationchange" , handler ) ;
39+ }
You can’t perform that action at this time.
0 commit comments