Skip to content

Instantly share code, notes, and snippets.

@jarvisluong
Created July 29, 2018 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarvisluong/70fc7d7f36e54091b57d45974e2fc16b to your computer and use it in GitHub Desktop.
Save jarvisluong/70fc7d7f36e54091b57d45974e2fc16b to your computer and use it in GitHub Desktop.
// @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