npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-cameraroll-image-picker

v1.0.10

Published

camera roll image picker

Downloads

105

Readme

react-native-cameraroll-image-picker

Image Picker with cameraroll

Getting started

$ npm install @react-native-community/cameraroll --save $ npm install react-native-cameraroll-image-picker --save && npx pod-install

Permissions

iOS

ios/Podfile

  target 'routine' do
    config = use_native_modules!

    permissions_path = '../node_modules/react-native-permissions/ios'
    pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary/Permission-PhotoLibrary.podspec"

    ...

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.

<manifest>
...
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
...
<application>

Components

Methods


Reference

Components

ImagePicker

component accepts the following props...

Parameters:

| Name | Type | Required | Description | | ------ | ------ | -------- | ------------------------------------------------ | | params | object | No | Expects a params with the shape described below. |

  • ref : {any} : you can use getAlbum method.
  • initialNumToRender : {number} : Number of photos to load first. [default 50]
  • groupTypes : {string} : Specifies which group types to filter the results to. Valid values are:
    • Album
    • All // default
    • Event
    • Faces
    • Library
    • PhotoStream
    • SavedPhotos
  • assetType : {string} : Specifies filter on asset type. Valid values are:
    • All
    • Videos
    • Photos // default
  • maximum : {number} : Maximum number of selectable images. [default 15]
  • imagesPerRow : {number} : number of spaces. [default 3]
  • imageMargin : {number} : gap between images. [default 1]
  • containerWidth : {number} : screen width. [default Dimension screen width]
  • backgroundColor : {string} : backgroundColor [default white]
  • emptyText : {string} : Text to be displayed when the image is empty. [default null]
  • emptyTextStyle : {object} : Text style to show if image is empty. [default null]
  • loader : {element} : Loading Component [default null]
  • album : {string} : current album [default All]
  • albums : {array} : album list [default []]
  • isMultiSelect : {boolean} : Whether to allow multiple selections or not. [default false]
  • onChangePhotosEvent : {(e: { selected: { name: string; type: string; uri: string; }[]; item: { name: string; type: string; uri: string; }; index: number; isChecked: boolean; }) => void} : event when the selected image changes.
  • onMaxSelectedEvent : {() => void} : Event when image selection is no longer possible.
  • getAlbumsData : {(albums: { label: string; value: string; count: number; }[]) => void} : Import album list.
  • onChangeAlbumEvent : {(album: string) => void} : Event when the selected album is changed.
import ImagePicker from "react-native-cameraroll-image-picker";

return (
  <ImagePicker
    initialNumToRender={50}
    album={"All"}
    maximum={5}
    onChangePhotosEvent={(e) => setSelected(e?.selected)}
    isMultiSelect={true}
  />
);

Methods

getAlbums()

import ImagePicker, { getAlbums } from "react-native-cameraroll-image-picker";

await getAlbums();

Returns a Promise with a list of albums

Returns:

Array of Album object

  • label: {string};
  • value: {string};
  • count: {number};

Example

import React, { useEffect, useState } from "react";
import { SafeAreaView, View } from "react-native";
import ImagePicker, { getAlbums } from "react-native-cameraroll-image-picker";
import styled from "styled-components/native";
import ImagePickerHeader from "@/styles/ui/Header/ImagePickerHeader";

const ImagePickerView = ({ navigation: { goBack }, route }) => {
  const [albums, setAlbums] = useState([{ label: "All", value: "All" }]);
  const [currentAlbum, setCurrentAlbum] = useState("All");
  const [selected, setSelected] = useState < any > [];

  const handleSelectAlbum = (album) => {
    setCurrentAlbum(album);
  };

  const handleCompleteSelect = async () => {
    if (!selected?.[0]?.uri) return;
    console.log(selected);
  };

  useEffect(() => {
    (async function handleGetAlbums() {
      const result = await getAlbums();
      setAlbums(result);
    })();
  }, []);

  return (
    <SafeAreaView style={{ flex: 1 }}>
      <Container>
        <ImagePickerHeader
          onSelectAlbum={handleSelectAlbum}
          onCompleteSelect={handleCompleteSelect}
          albums={albums}
          currentAlbum={currentAlbum}
          goBack={goBack}
        />
        <View style={{ flex: 1 }}>
          <ImagePicker
            initialNumToRender={50}
            album={currentAlbum}
            maximum={1}
            onChangePhotosEvent={(e) => setSelected(e?.selected)}
          />
        </View>
      </Container>
    </SafeAreaView>
  );
};

const Container = styled.View`
  flex: 1;
  background-color: white;
`;

export default ImagePickerView;