Skip to content

Commit

Permalink
fix(useScreenOrientation): Add fault tolerance to lock and unlock (#3575
Browse files Browse the repository at this point in the history
)
  • Loading branch information
satrong committed Dec 4, 2023
1 parent acb2fe6 commit be3ccc7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/core/useScreenOrientation/index.ts
Expand Up @@ -43,13 +43,14 @@ export function useScreenOrientation(options: ConfigurableWindow = {}) {
}

const lockOrientation = (type: OrientationLockType) => {
if (!isSupported.value)
return Promise.reject(new Error('Not supported'))
return screenOrientation.lock(type)
if (isSupported.value && typeof screenOrientation.lock === 'function')
return screenOrientation.lock(type)

return Promise.reject(new Error('Not supported'))
}

const unlockOrientation = () => {
if (isSupported.value)
if (isSupported.value && typeof screenOrientation.unlock === 'function')
screenOrientation.unlock()
}

Expand Down

0 comments on commit be3ccc7

Please sign in to comment.