Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ScreenOrientationLocker } from '@/components/Global/ScreenOrientationLocker'
import { TranslationSafeWrapper } from '@/components/Global/TranslationSafeWrapper'
import { PeanutProvider } from '@/config'
import { ContextProvider } from '@/context'
Expand Down Expand Up @@ -61,6 +62,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
<body
className={`${roboto.variable} ${londrina.variable} ${knerdOutline.variable} ${knerdFilled.variable} ${sniglet.variable} chakra-ui-light font-sans`}
>
<ScreenOrientationLocker />
<PeanutProvider>
<ContextProvider>
<FooterVisibilityProvider>
Expand Down
39 changes: 39 additions & 0 deletions src/components/Global/ScreenOrientationLocker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use client'

import { useEffect } from 'react'
import { captureException } from '@sentry/nextjs'

export function ScreenOrientationLocker() {
useEffect(() => {
const lockOrientation = async () => {
if (screen.orientation && (screen.orientation as any).lock) {
try {
await (screen.orientation as any).lock('portrait-primary')
} catch (error) {
console.error('Failed to lock screen orientation:', error)
captureException(error)
}
}
}

lockOrientation()

const handleOrientationChange = () => {
// if the orientation is no longer portrait, try to lock it back.
if (screen.orientation && !screen.orientation.type.startsWith('portrait')) {
lockOrientation()
}
}

// some browsers might not support addEventListener on screen.orientation
if (screen.orientation && screen.orientation.addEventListener) {
screen.orientation.addEventListener('change', handleOrientationChange)

return () => {
screen.orientation.removeEventListener('change', handleOrientationChange)
}
}
}, [])

return null
}
Loading