Skip to content

Instantly share code, notes, and snippets.

@jarvisluong
Created July 29, 2018 17:56
Show Gist options
  • Select an option

  • Save jarvisluong/70fc7d7f36e54091b57d45974e2fc16b to your computer and use it in GitHub Desktop.

Select an option

Save jarvisluong/70fc7d7f36e54091b57d45974e2fc16b to your computer and use it in GitHub Desktop.

Revisions

  1. jarvisluong created this gist Jul 29, 2018.
    43 changes: 43 additions & 0 deletions ImagePicker.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    // @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 {};
    }
    };