Created
July 29, 2018 17:56
-
-
Save jarvisluong/70fc7d7f36e54091b57d45974e2fc16b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import Alert from 'utils/AlertUtils'; | |
import { ImagePicker as ExpoImagePicker, Permissions } from 'expo'; | |
export default { | |
async launchCameraAsync(options: { | |
allowsEditing?: boolean, | |
quality?: number | |
}): Promise<{ uri?: string }> { | |
const { status: cameraPermission } = await Permissions.askAsync( | |
Permissions.CAMERA | |
); | |
const { status: cameraRollPermission } = await Permissions.askAsync( | |
Permissions.CAMERA_ROLL | |
); | |
if (cameraPermission === 'granted' && cameraRollPermission === 'granted') { | |
return ExpoImagePicker.launchCameraAsync(options); | |
} | |
Alert.alert('Oops!', 'We need your permission to open the camera :('); | |
return {}; | |
}, | |
async launchImageLibraryAsync(options: { | |
mediaTypes?: 'Images' | 'Videos' | 'All', | |
quality?: number | |
}): Promise<{ uri?: string }> { | |
const { status: cameraPermission } = await Permissions.askAsync( | |
Permissions.CAMERA | |
); | |
const { status: cameraRollPermission } = await Permissions.askAsync( | |
Permissions.CAMERA_ROLL | |
); | |
if (cameraPermission === 'granted' && cameraRollPermission === 'granted') { | |
console.log('granted'); | |
return ExpoImagePicker.launchImageLibraryAsync(options); | |
} | |
Alert.alert( | |
'Oops!', | |
'We need your permission to open your image library :(' | |
); | |
return {}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment