Gathering detailed insights and metrics for @react-native-camera-roll/camera-roll
Gathering detailed insights and metrics for @react-native-camera-roll/camera-roll
Gathering detailed insights and metrics for @react-native-camera-roll/camera-roll
Gathering detailed insights and metrics for @react-native-camera-roll/camera-roll
react-native-camera-roll-picker
A React Native component providing images selection from camera roll
@react-native-community/cameraroll
React Native Camera Roll for iOS & Android
@react-native-oh-tpl/camera-roll
React Native Camera Roll for iOS & Android
react-native-camera-roll
Camera Roll for react native.
CameraRoll is a react-native native module that provides access to the local camera roll or photo library.
npm install @react-native-camera-roll/camera-roll
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Java (26.32%)
Objective-C++ (24.5%)
TypeScript (23.03%)
Objective-C (14.81%)
JavaScript (6.74%)
Kotlin (2.39%)
Ruby (2.22%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,020 Stars
495 Commits
446 Forks
15 Watchers
13 Branches
152 Contributors
Updated on Jul 15, 2025
Latest Version
7.10.1
Package Id
@react-native-camera-roll/camera-roll@7.10.1
Unpacked Size
318.51 kB
Size
113.13 kB
File Count
88
NPM Version
10.2.5
Node Version
20.10.0
Published on
Jun 25, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
25
@react-native-camera-roll/camera-roll
Previous package name: @react-native-community/cameraroll
New package name: @react-native-camera-roll/camera-roll
$ npm install @react-native-camera-roll/camera-roll --save
or
$ yarn add @react-native-camera-roll/camera-roll
Linking should be automatic since react-native version 0.60. Below are instructions if auto linking does not work.
$ react-native link @react-native-camera-roll/camera-roll && npx pod-install
Libraries
➜ Add Files to [your project's name]
node_modules
➜ @react-native-camera-roll/camera-roll
and add RNCCameraroll.xcodeproj
libRNCCameraroll.a
to your project's Build Phases
➜ Link Binary With Libraries
Cmd+R
)<android/app/src/main/java/[...]/MainApplication.java
(Auto link, ^RN0.69 does not required)import com.reactnativecommunity.cameraroll.CameraRollPackage;
to the imports at the top of the filenew CameraRollPackage()
to the list returned by the getPackages()
methodandroid/settings.gradle
:
include ':@react-native-camera-roll_camera-roll'
project(':@react-native-camera-roll_camera-roll').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-camera-roll/camera-roll/android')
android/app/build.gradle
:
implementation project(':@react-native-camera-roll_camera-roll')
react-native
moduleThis module was created when the CameraRoll was split out from the core of React Native. To migrate to this module you need to follow the installation instructions above and then change you imports from:
1import { CameraRoll } from "react-native";
to:
1import { CameraRoll } from "@react-native-camera-roll/camera-roll";
CameraRoll
provides access to the local camera roll or photo library.
iOS
The user's permission is required in order to access the Camera Roll on devices running iOS 10 or later. Add the NSPhotoLibraryUsageDescription
key in your Info.plist
with a string that describes how your app will use this data. This key will appear as Privacy - Photo Library Usage Description
in Xcode.
If you are targeting devices running iOS 11 or later, you will also need to add the NSPhotoLibraryAddUsageDescription
key in your Info.plist
. Use this key to define a string that describes how your app will use this data. By adding this key to your Info.plist
, you will be able to request write-only access permission from the user. If you try to save to the camera roll without this permission, your app will exit.
Android
Permission is required to read and write to the external storage.
On Expo, follow the guide here for requesting the permission.
On react-native-cli or ejected apps, adding the following lines will add the capability for the app to request the permission. Find more info on Android Permissions here.
1<manifest> 2... 3 <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> 4 <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> 5 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" 6 android:maxSdkVersion="32" /> 7 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 8... 9<application>
Then you have to explicitly ask for the permission
1import { PermissionsAndroid, Platform } from "react-native"; 2import { CameraRoll } from "@react-native-camera-roll/camera-roll"; 3 4async function hasAndroidPermission() { 5 const getCheckPermissionPromise = () => { 6 if (Platform.Version >= 33) { 7 return Promise.all([ 8 PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES), 9 PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO), 10 ]).then( 11 ([hasReadMediaImagesPermission, hasReadMediaVideoPermission]) => 12 hasReadMediaImagesPermission && hasReadMediaVideoPermission, 13 ); 14 } else { 15 return PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE); 16 } 17 }; 18 19 const hasPermission = await getCheckPermissionPromise(); 20 if (hasPermission) { 21 return true; 22 } 23 const getRequestPermissionPromise = () => { 24 if (Platform.Version >= 33) { 25 return PermissionsAndroid.requestMultiple([ 26 PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES, 27 PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO, 28 ]).then( 29 (statuses) => 30 statuses[PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES] === 31 PermissionsAndroid.RESULTS.GRANTED && 32 statuses[PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO] === 33 PermissionsAndroid.RESULTS.GRANTED, 34 ); 35 } else { 36 return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE).then((status) => status === PermissionsAndroid.RESULTS.GRANTED); 37 } 38 }; 39 40 return await getRequestPermissionPromise(); 41} 42 43async function savePicture() { 44 if (Platform.OS === "android" && !(await hasAndroidPermission())) { 45 return; 46 } 47 48 CameraRoll.save(tag, { type, album }) 49};
save()
1CameraRoll.save(tag, { type, album })
Saves the photo or video to the photo library, and returns the URI of the newly created asset.
The tag must be a local image or video URI, such as "file:///sdcard/img.png"
.
If the tag has a file extension of .mov or .mp4 (lower or uppercase), it will be inferred as a video. Otherwise it will be treated as a photo. To override the automatic choice, you can pass an optional type
parameter that must be one of 'photo' or 'video'.
It allows to specify a particular album you want to store the asset to when the param album
is provided.
On Android, if no album is provided, DCIM directory is used, otherwise PICTURE or MOVIES directory is used depending on the type
provided.
Returns a Promise which will resolve with the new URI.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
tag | string | Yes | See above. |
type | enum('photo', 'video') | No | Overrides automatic detection based on the file extension. |
album | string | No | The album to save to |
saveAsset()
Same as save()
, but returns the full asset information (PhotoIdentifier
) instead of just the URI.
getAlbums()
1CameraRoll.getAlbums(params);
Returns a Promise with a list of albums
Parameters:
assetType
: {string} : Specifies filter on asset type. Valid values are:
All
// defaultVideos
Photos
albumType
: {string} : (iOS only) Specifies filter on type of album. Valid values are:
All
Album
// defaultSmartAlbum
Returns:
Array of Album
object
getPhotos()
1CameraRoll.getPhotos(params);
Returns a Promise with photo identifier objects from the local camera roll of the device matching shape defined by getPhotosReturnChecker
.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
params | object | Yes | Expects a params with the shape described below. |
first
: {number} : The number of photos wanted in reverse order of the photo application (i.e. most recent first for SavedPhotos). Required.after
: {string} : A cursor that matches page_info { end_cursor }
returned from a previous call to getPhotos
. Note that using this will reduce performance slightly on iOS. An alternative is just using the fromTime
and toTime
filters, which have no such impact.groupTypes
: {string} : Specifies which group types to filter the results to. Valid values are:
Album
All
// defaultEvent
Faces
Library
SmartAlbum
PhotoStream
SavedPhotos
groupName
: {string} : Specifies filter on group names, like 'Recent Photos' or custom album titles.includeSharedAlbums
: {boolean} : Include assets originating from an iCloud Shared Album. iOS only.assetType
: {string} : Specifies filter on asset type. Valid values are:
All
Videos
Photos
// defaultmimeTypes
: {Array} : Filter by mimetype (e.g. image/jpeg). Note that using this will reduce performance slightly on iOS.fromTime
: {number} : Filter by creation time with a timestamp in milliseconds. This time is exclusive, so we'll select all photos with timestamp > fromTime
.toTime
: {number} : Filter by creation time with a timestamp in milliseconds. This time is inclusive, so we'll select all photos with timestamp <= toTime
.include
: {Array} : Whether to include some fields that are slower to fetch
filename
: Ensures image.filename
is available in each node. This has a large performance impact on iOS.fileSize
: Ensures image.fileSize
is available in each node. This has a large performance impact on iOS.fileExtension
: Ensures image.fileExtension
is available in each node.location
: Ensures location
is available in each node. This has a large performance impact on Android.imageSize
: Ensures image.width
and image.height
are available in each node. This has a small performance impact on Android.playableDuration
: Ensures image.playableDuration
is available in each node. This has a medium peformance impact on Android.orientation
: Ensures image.orientation
is available in each node. This has a small peformance impact on Android. Android onlyalbums
: Ensures group_name
is available in each node. This has a large peformance impact on iOS.sourceType
: Ensures sourceType
is available in each node.Returns a Promise which when resolved will be of the following shape:
edges
: {Arraynode
: {object} An object with the following shape:
id
: {string} : A local identifier. Correspond to Media._ID
on Android and localIdentifier
on iOS.type
: {string}subTypes
: {ArraySubTypes
type). Always [] on Android.sourceType
: {string | null} : "UserLibrary" (for the user library) or "CloudShared" (for an iCloud Shared Album). Always "UserLibrary" on Android.group_name
: {Arrayimage
: {object} : An object with the following shape:
uri
: {string}filename
: {string | null} : Only set if the include
parameter contains filename
extension
: {string | null} : Only set if the include
parameter contains fileExtension
height
: {number | null} : Only set if the include
parameter contains imageSize
width
: {number | null} : Only set if the include
parameter contains imageSize
fileSize
: {number | null} : Only set if the include
parameter contains fileSize
playableDuration
: {number | null} : Only set for videos if the include
parameter contains playableDuration
. Will be null for images.orientation
: {number | null} : Only set for images if the include
parameter contains orientation
. Android onlytimestamp
: {number}modificationTimestamp
: {number}location
: {object | null} : Only set if the include
parameter contains location
. An object with the following shape:
latitude
: {number}longitude
: {number}altitude
: {number}heading
: {number}speed
: {number}page_info
: {object} : An object with the following shape:
has_next_page
: {boolean}start_cursor
: {string}end_cursor
: {string}limited
: {boolean | undefined} : true if the app can only access a subset of the gallery pictures (authorization is PHAuthorizationStatusLimited
), false otherwise (iOS only)Loading images:
1_handleButtonPress = () => { 2 CameraRoll.getPhotos({ 3 first: 20, 4 assetType: 'Photos', 5 }) 6 .then(r => { 7 this.setState({ photos: r.edges }); 8 }) 9 .catch((err) => { 10 //Error Loading Images 11 }); 12 }; 13render() { 14 return ( 15 <View> 16 <Button title="Load Images" onPress={this._handleButtonPress} /> 17 <ScrollView> 18 {this.state.photos.map((p, i) => { 19 return ( 20 <Image 21 key={i} 22 style={{ 23 width: 300, 24 height: 100, 25 }} 26 source={{ uri: p.node.image.uri }} 27 /> 28 ); 29 })} 30 </ScrollView> 31 </View> 32 ); 33}
Loading images with listeners and refetchs:
1import { CameraRoll, cameraRollEventEmitter } from '@react-native-camera-roll/camera-roll'; 2 3import { useCallback, useEffect, useState } from 'react'; 4 5import { AppState, EmitterSubscription } from 'react-native'; 6 7interface GalleryOptions { 8 pageSize: number; 9 mimeTypeFilter?: Array<string>; 10} 11 12interface GalleryLogic { 13 photos?: ImageDTO[]; 14 loadNextPagePictures: () => void; 15 isLoading: boolean; 16 isLoadingNextPage: boolean; 17 isReloading: boolean; 18 hasNextPage: boolean; 19} 20 21const supportedMimeTypesByTheBackEnd = [ 22 'image/jpeg', 23 'image/png', 24 'image/heif', 25 'image/heic', 26 'image/heif-sequence', 27 'image/heic-sequence', 28]; 29 30export const useGallery = ({ 31 pageSize = 30, 32 mimeTypeFilter = supportedMimeTypesByTheBackEnd, 33}: GalleryOptions): GalleryLogic => { 34 const [isLoading, setIsLoading] = useState(false); 35 const [isReloading, setIsReloading] = useState(false); 36 const [isLoadingNextPage, setIsLoadingNextPage] = useState(false); 37 const [hasNextPage, setHasNextPage] = useState(false); 38 const [nextCursor, setNextCursor] = useState<string>(); 39 const [photos, setPhotos] = useState<ImageDTO[]>(); 40 41 const loadNextPagePictures = useCallback(async () => { 42 try { 43 nextCursor ? setIsLoadingNextPage(true) : setIsLoading(true); 44 const { edges, page_info } = await CameraRoll.getPhotos({ 45 first: pageSize, 46 after: nextCursor, 47 assetType: 'Photos', 48 mimeTypes: mimeTypeFilter, 49 ...(isAndroid && { include: ['fileSize', 'filename'] }), 50 }); 51 const photos = convertCameraRollPicturesToImageDtoType(edges); 52 setPhotos((prev) => [...(prev ?? []), ...photos]); 53 54 setNextCursor(page_info.end_cursor); 55 setHasNextPage(page_info.has_next_page); 56 } catch (error) { 57 console.error('useGallery getPhotos error:', error); 58 } finally { 59 setIsLoading(false); 60 setIsLoadingNextPage(false); 61 } 62 }, [mimeTypeFilter, nextCursor, pageSize]); 63 64 const getUnloadedPictures = useCallback(async () => { 65 try { 66 setIsReloading(true); 67 const { edges, page_info } = await CameraRoll.getPhotos({ 68 first: !photos || photos.length < pageSize ? pageSize : photos.length, 69 assetType: 'Photos', 70 mimeTypes: mimeTypeFilter, 71 // Include fileSize only for android since it's causing performance issues on IOS. 72 ...(isAndroid && { include: ['fileSize', 'filename'] }), 73 }); 74 const newPhotos = convertCameraRollPicturesToImageDtoType(edges); 75 setPhotos(newPhotos); 76 77 setNextCursor(page_info.end_cursor); 78 setHasNextPage(page_info.has_next_page); 79 } catch (error) { 80 console.error('useGallery getNewPhotos error:', error); 81 } finally { 82 setIsReloading(false); 83 } 84 }, [mimeTypeFilter, pageSize, photos]); 85 86 useEffect(() => { 87 if (!photos) { 88 loadNextPagePictures(); 89 } 90 }, [loadNextPagePictures, photos]); 91 92 useEffect(() => { 93 const subscription = AppState.addEventListener('change', async (nextAppState) => { 94 if (nextAppState === 'active') { 95 getUnloadedPictures(); 96 } 97 }); 98 99 return () => { 100 subscription.remove(); 101 }; 102 }, [getUnloadedPictures]); 103 104 useEffect(() => { 105 let subscription: EmitterSubscription; 106 if (isAboveIOS14) { 107 subscription = cameraRollEventEmitter.addListener('onLibrarySelectionChange', (_event) => { 108 getUnloadedPictures(); 109 }); 110 } 111 112 return () => { 113 if (isAboveIOS14 && subscription) { 114 subscription.remove(); 115 } 116 }; 117 }, [getUnloadedPictures]); 118 119 return { 120 photos, 121 loadNextPagePictures, 122 isLoading, 123 isLoadingNextPage, 124 isReloading, 125 hasNextPage, 126 }; 127};
deletePhotos()
1CameraRoll.deletePhotos([uri]);
Requests deletion of photos in the camera roll.
On Android, the uri must be a local image or video URI, such as "file:///sdcard/img.png"
.
On iOS, the uri can be any image URI (including local, remote asset-library and base64 data URIs) or a local video file URI. The user is presented with a dialog box that shows them the asset(s) and asks them to confirm deletion. This is not able to be bypassed as per Apple Developer guidelines.
Returns a Promise which will resolve when the deletion request is completed, or reject if there is a problem during the deletion. On iOS the user is able to cancel the deletion request, which causes a rejection, while on Android the rejection will be due to a system error.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
uri | string | Yes | See above. |
iosGetImageDataById()
1CameraRoll.iosGetImageDataById(internalID, true);
Parameters:
Name | Type | Required | Description |
---|---|---|---|
internalID | string | Yes | Ios internal ID 'PH://xxxx'. |
options | PhotoConvertionOptions | False | Expects an options object with the shape described below. |
convertHeic
: {boolean} : default = false : Whether to convert or not to JPEG image.quality
: {number} : default = 1.0 : jpeg quality used for compression (a value from 0.0 to 1.0). A value of 0.0 is maximum compression (or lowest quality). A value of 1.0 is least compression (or best quality).Upload photo/video with iosGetImageDataById
method
1 2try { 3// uri 'PH://xxxx' 4const fileData = await CameraRoll.iosGetImageDataById(uri); 5if (!fileData?.node?.image?.filepath) return undefined; 6const uploadPath = imageData.node.image.filepath; // output should be file://... 7// fetch or ReactNativeBlobUtil.fetch to upload 8} 9catch (error) {} 10
Note:
Sometimes when calling iosGetImageDataById
, the image/video can be downloaded from iCloud. To be able to receive the progress of this download, you need to add a listener to the onProgressUpdate
event and use it to render on the UI.
The event generated will be an object containing the image id (id
) and the progress of the download (progress
). The id
is a string with the internalID
you used to call iosGetImageDataById
. The progress
is a double ranging from 0 to 1, where 0 represents the start of the download and 1 represents the completion of the download.
1 2import { progressUpdateEventEmitter } from '@react-native-camera-roll/camera-roll'; 3 4useEffect(() => { 5 const subscription = progressUpdateEventEmitter.addListener( 6 'onProgressUpdate', 7 event => { 8 // Render the progress of the image / video being 9 // downloaded using event.id and event.progress 10 }, 11 ); 12 13 return () => { 14 subscription.remove(); 15 }; 16}, []); 17
useCameraRoll()
useCameraRoll
is a utility hooks for the CameraRoll module.
1import React, {useEffect} from 'react'; 2import {Button} from 'react-native'; 3import {useCameraRoll} from "@react-native-camera-roll/camera-roll"; 4 5function Example() { 6 const [photos, getPhotos, save] = useCameraRoll(); 7 8 return <> 9 <Button title='Get Photos' onPress={() => getPhotos()}>Get Photos</Button> 10 { 11 photos.map((photo, index) => /* render photos */) 12 } 13 </>; 14};
getPhotoThumbnail()
iOS only
Returns a Promise with thumbnail photo.
Parameters:
Name | Type | Required | Description |
---|---|---|---|
internalID | string | Yes | Ios internal ID 'PH://xxxx'. |
options | PhotoThumbnailOptions | Yes | Expects an options object with the shape described below. |
allowNetworkAccess
: {boolean} : default = false : Specifies whether the requested image can be downloaded from iCloud. iOS onlytargetSize
: {ThumbnailSize} : Expects a targetSize with the shape desribed below:
height
: {number} : default = 400width
: {number} : default = 400quality
: {number} : default = 1.0 : jpeg quality used for compression (a value from 0.0 to 1.0). A value of 0.0 is maximum compression (or lowest quality). A value of 1.0 is least compression (or best quality).Returns:
Type | Description |
---|---|
Promise<PhotoThumbnail> | A Promise with PhotoThumbnail with the shape described below. |
thumbnailBase64
: {string}Loading a thumbnail:
1export default function Thumbnail(props) { 2 const [base64Image, setBase64Image] = useState(null); 3 4 useEffect(() => { 5 const getThumbnail = async () => { 6 const options = { 7 allowNetworkAccess: true, 8 targetSize: { 9 height: 80, 10 width: 80 11 }, 12 quality: 1.0 13 }; 14 15 const thumbnailResponse = await CameraRoll.getPhotoThumbnail(props.image.uri, options); 16 17 setBase64Image(thumbnailResponse.thumbnailBase64); 18 }; 19 20 getThumbnail(); 21 }, []); 22 23 const extension = props.image.extension; 24 let prefix; 25 26 switch (extension) { 27 case 'png': 28 prefix = 'data:image/png;base64,'; 29 break; 30 default: 31 //all others can use jpeg 32 prefix = 'data:image/jpeg;base64,'; 33 break; 34 } 35 36 return ( 37 <Image 38 source={{ uri: `${prefix}${base64Image}` }} 39 /> 40 ); 41}
If you try to save media into specific album without asking for read and write permission then saving will not work, workaround is to not precice album name for IOS if you don't want to request full permission (Only ios >= 14).
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
binaries present in source code
Details
Reason
Found 7/21 approved changesets -- score normalized to 3
Reason
2 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
15 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More