Bluesky app fork with some witchin' additions 💫

Request permissions properly on mobile (closes #308) (#328)

authored by

Paul Frazee and committed by
GitHub
df6a7128 4f9e9e60

+10 -4
+10 -4
src/lib/hooks/usePermissions.ts
··· 23 23 } 24 24 25 25 export function usePhotoLibraryPermission() { 26 - const [mediaLibraryPermissions] = MediaLibrary.usePermissions() 26 + const [res, requestPermission] = MediaLibrary.usePermissions() 27 27 const requestPhotoAccessIfNeeded = async () => { 28 28 // On the, we use <input type="file"> to produce a filepicker 29 29 // This does not need any permission granting. ··· 31 31 return true 32 32 } 33 33 34 - if (mediaLibraryPermissions?.status === 'granted') { 34 + if (res?.granted) { 35 35 return true 36 + } else if (!res || res?.status === 'undetermined' || res?.canAskAgain) { 37 + const updatedRes = await requestPermission() 38 + return updatedRes?.granted 36 39 } else { 37 40 openPermissionAlert('photo library') 38 41 return false ··· 42 45 } 43 46 44 47 export function useCameraPermission() { 45 - const [cameraPermissionStatus] = Camera.useCameraPermissions() 48 + const [res, requestPermission] = Camera.useCameraPermissions() 46 49 47 50 const requestCameraAccessIfNeeded = async () => { 48 - if (cameraPermissionStatus?.granted) { 51 + if (res?.granted) { 49 52 return true 53 + } else if (!res || res?.status === 'undetermined' || res?.canAskAgain) { 54 + const updatedRes = await requestPermission() 55 + return updatedRes?.granted 50 56 } else { 51 57 openPermissionAlert('camera') 52 58 return false