GithubHelp home page GithubHelp logo

andreysam / react-native-in-app-gallery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xtreamsrl/react-native-in-app-gallery

0.0 0.0 0.0 7.35 MB

A RN in-app gallery component

TypeScript 80.34% JavaScript 0.93% Starlark 0.67% Java 6.95% Objective-C 4.92% Ruby 6.19%

react-native-in-app-gallery's Introduction

react-native-in-app-gallery

A react-native in-app gallery component which allows to pick an image from both gallery and camera, optionally without exiting the current screen. It's Android and iOS compatible.

Getting started

Installation guide

This package depends on some common react-native packages:

npm i --save @react-native-community/cameraroll react-native-permissions react-native-camera react-native-image-picker react-native-in-app-gallery

Android

Add required permissions inside the manifest

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

Add the following lines in android/app/build.gradle

android {
  ...
  defaultConfig {
    ...
    missingDimensionStrategy 'react-native-camera', 'general' // <--- insert this line
  }
}

iOS

Add required keys in your Info.plist

    <key>NSCameraUsageDescription</key>
	<string>$(PRODUCT_NAME) would like to use your camera</string>
	<key>NSMicrophoneUsageDescription</key>
	<string>$(PRODUCT_NAME) would like to use your microphone to let you take and send videos</string>
	<key>NSPhotoLibraryAddUsageDescription</key>
	<string>$(PRODUCT_NAME) would like to save photos to your photo gallery</string>
	<key>NSPhotoLibraryUsageDescription</key>
	<string>$(PRODUCT_NAME) would like access to your photo gallery</string>

Add permission handlers in your Podfile

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"
  pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary.podspec"

Run

cd ios
pod install

If any problems, please refer to the mentioned above packages installation guides before opening an issue.

Usage

The usage should be straightforward: simply import the component and consume it.

import InAppGallery from 'react-native-in-app-gallery';
...
<InAppGallery
    onImagePicked={(image) => {
        console.log(image);
    }}
/>

Try it out

You can check a simple example here.

Props

Property Type Description
onImagePicked (image: ImageFile) => void Callback which triggers when an image is picked (press on image, take a photo from the camera or from gallery)
pageSize number (default 100) (Optional) The page size dimension to paginate images fetching
initialNumToRender number (default 9) (Optional) The initial number of items to render for the FlatList
imageHeight number (default 120) (Optional) The height of the image item
withCamera bool (default true) (Optional) If true, shows camera preview and allow to take picture from the camera
withFullGallery bool (default true) (Optional) If true, a FAB button allows you to open the gallery
onPermissionGranted (permission: Permission) => void (Optional) Callback on permission granted
onPermissionDenied (permission: Permission) => void (Optional) Callback on permission denied
onPermissionBlocked (permission: Permission) => void (Optional) Callback on permission blocked
imagePickerOptions ImagePickerOptions (default {storageOptions: {skipBackup: true, path: 'images'}}) (Optional) Options for ImagePicker
enableSelection bool (default false) (Optional) It enables selection (with long press)
onImageSelected (image: ImageFile, selected: boolean) (Optional) Callback on image selection. It's triggered whenever an image is selected or deselected
onSelectionEnd (images: ImageFile[]) => void (Optional) Callback on images selection end
cancelSelectionText string (default Cancel) (Optional) Text to cancel selection
doneSelectionText string (default DONE) (Optional) Text to end selection
selectionColor string (default #0284ff) (Optional) It's the tint color for selection icon

Methods

Method Description
clearSelection It clears selected images

Who we are

A proudly ๐Ÿ‡ฎ๐Ÿ‡น software development and data science startup.
We consider ourselves a family of talented and passionate people building their own products and powerful solutions for our clients. Get to know us more on xtreamers.io or follow us on LinkedIn.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.