diff options
Diffstat (limited to 'src/lib/hooks/usePermissions.ts')
-rw-r--r-- | src/lib/hooks/usePermissions.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/hooks/usePermissions.ts b/src/lib/hooks/usePermissions.ts index 9f1f8fb6f..d248e1975 100644 --- a/src/lib/hooks/usePermissions.ts +++ b/src/lib/hooks/usePermissions.ts @@ -48,6 +48,35 @@ export function usePhotoLibraryPermission() { return {requestPhotoAccessIfNeeded} } +export function useVideoLibraryPermission() { + const [res, requestPermission] = MediaLibrary.usePermissions({ + granularPermissions: ['video'], + }) + const requestVideoAccessIfNeeded = async () => { + // On the, we use <input type="file"> to produce a filepicker + // This does not need any permission granting. + if (isWeb) { + return true + } + + if (res?.granted) { + return true + } else if (!res || res.status === 'undetermined' || res?.canAskAgain) { + const {canAskAgain, granted, status} = await requestPermission() + + if (!canAskAgain && status === 'undetermined') { + openPermissionAlert('video library') + } + + return granted + } else { + openPermissionAlert('video library') + return false + } + } + return {requestVideoAccessIfNeeded} +} + export function useCameraPermission() { const [res, requestPermission] = Camera.useCameraPermissions() |