npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

@exodus/react-native-image-picker

8.2.1-exodus-4

@rgommezz

npmHomeRepoSnykSocket
Downloads:1196
$ npm install @exodus/react-native-image-picker
DailyWeeklyMonthlyYearly

@exodus/react-native-image-picker 🎆

A React Native module that allows you to select a photo/video from the device library or camera.

npm downloads npm package License

Installation

yarn add @exodus/react-native-image-picker

New Architecture

To take advantage of the new architecture run-

iOS

RCT_NEW_ARCH_ENABLED=1 npx pod-install ios

Android

Set newArchEnabled to true inside android/gradle.properties

Pre-Fabric (AKA not using the new architecture)

npx pod-install ios

Post-install Steps

iOS

Add the appropriate keys to your Info.plist depending on your requirement:

RequirementKey
Select image/video from photosNSPhotoLibraryUsageDescription
Capture ImageNSCameraUsageDescription
Capture VideoNSCameraUsageDescription & NSMicrophoneUsageDescription

Android

No permissions required (saveToPhotos requires permission check).

Note: This library does not require Manifest.permission.CAMERA, if your app declares as using this permission in manifest then you have to obtain the permission before using launchCamera.

Targeting Android API Levels Below 30

If your app's minSdkVersion is set to below 30 and it does not already include or depend on androidx.activity:activity:1.9.+ or a newer version, you'll need to add the following line to the dependencies section of your app/build.gradle file to ensure support for the backported AndroidX Photo Picker:

dependencies {
    ...
    implementation("androidx.activity:activity:1.9.+")
    ...
}

Additionally, you may need to update your AndroidManifest.xml to trigger the installation of the backported Photo Picker. For reference, you can check the example app's configuration in example/android/app/src/main/AndroidManifest.xml and example/android/app/build.gradle.

For more details, consult the Android documentation on AndroidX Photo Picker: https://developer.android.com/training/data-storage/shared/photopicker

API Reference

Methods

import {
  launchCamera,
  launchImageLibrary,
} from '@exodus/react-native-image-picker';

launchCamera()

Launch camera to take photo or video.

launchCamera(options?, callback);

// You can also use as a promise without 'callback':
const result = await launchCamera(options?);

See Options for further information on options.

The callback will be called with a response object, refer to The Response Object.

launchImageLibrary

Launch gallery to pick image or video.

launchImageLibrary(options?, callback)

// You can also use as a promise without 'callback':
const result = await launchImageLibrary(options?);

See Options for further information on options.

The callback will be called with a response object, refer to The Response Object.

Options

OptioniOSAndroidDescription
mediaTypeOKOKphoto or video or mixed(launchCamera on Android does not support 'mixed').
restrictMimeTypesNOOKArray containing the mime-types allowed to be picked. Default is empty (everything).
maxWidthOKOKTo resize the image.
maxHeightOKOKTo resize the image.
videoQualityOKOKlow, medium, or high on iOS, low or high on Android.
durationLimitOKOKVideo max duration (in seconds).
qualityOKOK0 to 1, photos.
conversionQualityNOOKFor conversion from HEIC/HEIF to JPEG, 0 to 1. Default is 0.92
cameraTypeOKOK'back' or 'front' (May not be supported in few android devices).
includeBase64OKOKIf true, creates base64 string of the image (Avoid using on large image files due to performance).
includeExtraOKOKIf true, will include extra data which requires library permissions to be requested (i.e. exif data).
saveToPhotosOKOK(Boolean) Only for launchCamera, saves the image/video file captured to public photo.
selectionLimitOKOKSupports providing any integer value. Use 0 to allow any number of files on iOS version >= 14 & Android version >= 13. Default is 1.
presentationStyleOKNOControls how the picker is presented. currentContext, pageSheet, fullScreen, formSheet, popover, overFullScreen, overCurrentContext. Default is currentContext.
formatAsMp4OKNOConverts the selected video to MP4 (iOS Only).
assetRepresentationModeOKOKA mode that determines which representation to use if an asset contains more than one on iOS or disables HEIC/HEIF to JPEG conversion on Android if set to 'current'. Possible values: 'auto', 'current', 'compatible'. Default is 'auto'.

|

The Response Object

keyiOSAndroidDescription
didCancelOKOKtrue if the user cancelled the process
errorCodeOKOKCheck ErrorCode for all error codes
errorMessageOKOKDescription of the error, use it for debug purpose only
assetsOKOKArray of the selected media, refer to Asset Object

Asset Object

keyiOSAndroidPhoto/VideoRequires PermissionsDescription
base64OKOKPHOTO ONLYNOThe base64 string of the image (photos only)
uriOKOKBOTHNOThe file uri in app specific cache storage. Except when picking video from Android gallery where you will get read only content uri, to get file uri in this case copy the file to app specific storage using any react-native library.
originalPathNOOKBOTHNOThe original file path.
widthOKOKBOTHNOAsset dimensions
heightOKOKBOTHNOAsset dimensions
fileSizeOKOKBOTHNOThe file size
typeOKOKBOTHNOThe file type
fileNameOKOKBOTHNOThe file name
durationOKOKVIDEO ONLYNOThe selected video duration in seconds
bitrate---OKVIDEO ONLYNOThe average bitrate (in bits/sec) of the selected video, if available. (Android only)
timestampOKOKBOTHYESTimestamp of the asset. Only included if 'includeExtra' is true
idOKOKBOTHYESlocal identifier of the photo or video. On Android, this is the same as fileName

Note on file storage

Image/video captured via camera will be stored in temporary folder allowing it to be deleted any time, so don't expect it to persist. Use saveToPhotos: true (default is false) to save the file in the public photos. saveToPhotos requires WRITE_EXTERNAL_STORAGE permission on Android 28 and below (The permission has to obtained by the App manually as the library does not handle that).

ErrorCode

CodeDescription
camera_unavailableCamera not available on device
permissionPermission not satisfied
othersOther errors (check errorMessage for description)

License

MIT