Add tablet landscape layout and allow PWA horizontal orientation.
Split mobile and tablet breakpoints, restore desktop-style reading on landscape tablets, and lock Android tablet apps to landscape. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/** Android 平板 PWA 安装后默认锁定横屏 */
|
||||
export function initTabletLandscape() {
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
function tryLockLandscape() {
|
||||
const isStandalone =
|
||||
window.matchMedia('(display-mode: standalone)').matches ||
|
||||
(window.navigator as Navigator & { standalone?: boolean }).standalone
|
||||
|
||||
if (!isStandalone || !/Android/i.test(navigator.userAgent)) return
|
||||
|
||||
const shortestSide = Math.min(window.screen.width, window.screen.height)
|
||||
if (shortestSide < 600) return
|
||||
|
||||
const lock = screen.orientation?.lock?.bind(screen.orientation)
|
||||
if (!lock) return
|
||||
|
||||
lock('landscape-primary').catch(() => {
|
||||
lock('landscape').catch(() => {})
|
||||
})
|
||||
}
|
||||
|
||||
tryLockLandscape()
|
||||
window.addEventListener('orientationchange', tryLockLandscape)
|
||||
}
|
||||
Reference in New Issue
Block a user