-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOSUtils.js
44 lines (38 loc) · 1.58 KB
/
IOSUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* IOSUtils
* IOS utils methods for IOS detection and requesting orientation permissions.
* @author danrossi / https://github.com/danrossi
*/
let visionOSWidth = 1306,
visionOSHeight = 735;
export default class IOSUtils {
/**
* Only way to detect visionOS is detect for MacIntel Ipad and screen width greater than 1306
* xr detection for visionOS is only possible if the flag is enabled.
* Need to use width instead of availWidth as Ipad is more, and do a height check as Ipad height is more.
*/
static get isVisionOS() {
return this.isIpad && screen.width >= visionOSWidth && screen.height <= visionOSHeight;
}
/**
* Modern Ipad detection
*/
static get isIpad() {
return (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
}
/**
* Iphone and Ipad detection and filter for visionOS screens.
* We don't want to detect visionOS as iOS to prevent including mobile features like orientation controls.
* Need to use width instead of availWidth as Ipad is more, and do a height check as Ipad height is more.
*
*/
static get isIOS() {
return ((/iP(hone|ad)/i).test(navigator.platform) || (this.isIpad && screen.width < visionOSWidth && screen.height > visionOSHeight));
}
static requireOrientationPermission() {
return window.DeviceOrientationEvent !== undefined && typeof window.DeviceOrientationEvent.requestPermission === 'function';
}
static requestOrientationPermissions() {
return window.DeviceOrientationEvent.requestPermission();
}
}