matthewhudson / current-device

📱 The easiest way to write conditional CSS and/or JavaScript based on device operating system (iOS, Android, Blackberry, Windows, Firefox OS, MeeGo), orientation (Portrait vs. Landscape), and type (Tablet vs. Mobile).
https://matthewhudson.github.io/current-device/
MIT License
3.94k stars 588 forks source link

Orientation not working properly in Safari on iOS 16 #367

Open samuelsimoes opened 1 year ago

samuelsimoes commented 1 year ago

Safari on iOS 16 exposes the screen.orientation property now, but from what I've seen, it only returns the correct information after the screen rotation animation has finished. However, the orientationchange event is invoked as soon as the animation starts, causing an issue with detecting the current orientation, as it always returns the previous orientation instead.

To fix this, I suggest moving the iOS-specific code block https://github.com/matthewhudson/current-device/blob/af958702564c904b66d666ab95ce37175627af92/src/index.js#L181-L186 to the top of the general detection routine. This way, iOS will always use window.orientation, which continues to work as expected.

subfighter3 commented 6 months ago

Looks like this issue has not being addressed yet… can somebody pack this solution into the main branch?