Last active
July 11, 2022 11:50
-
-
Save AvocadoVenom/8ba6c8faafc249d2d1f0c0065efda215 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const supportedScreenOrientation = | |
| (screen?.orientation || {}).type ?? (screen as any).mozOrientation ?? (screen as any).msOrientation | |
| const safariScreenOrientation: OrientationType = | |
| !screen?.orientation && matchMedia('(orientation: portrait)').matches ? 'portrait-primary' : 'landscape-primary' | |
| const initialScreenOrientation = supportedScreenOrientation ?? safariScreenOrientation ?? 'portrait-primary' | |
| let screenOrientation: OrientationType = initialScreenOrientation | |
| if (screen.orientation) { | |
| screen.orientation.addEventListener( | |
| 'change', | |
| (ev: Event) => (screenOrientation = (ev.target ?? ({} as any)).type) | |
| ) | |
| } | |
| const isLandscapeOrientation = () => ['landscape-primary', 'landscape-secondary'].includes(screenOrientation) | |
| const isPortraitOrientation = () => ['portrait-primary', 'portrait-secondary'].includes(screenOrientation) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment