Giter VIP home page Giter VIP logo

zhuyu1220 / react-native-image-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from react-native-image-picker/react-native-image-picker

0.0 0.0 0.0 2.03 MB

:sunrise_over_mountains: A React Native module that allows you to use native UI to select media from the device library or directly from the camera.

License: MIT License

Objective-C 32.39% JavaScript 7.46% Ruby 2.51% Java 52.97% TypeScript 3.56% Starlark 1.09%

react-native-image-picker's Introduction

React Native Image Picker

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

Note: If you are still using deprecated version 2.x.x check this for documentation.

Migration from 2.x.x to 3.x.x

  • showImagePicker API is removed.
  • No permission required for default options on Android.
  • Removed and updated some values in options, so please check them carefully.

Install

yarn add react-native-image-picker

# RN >= 0.60
cd ios && pod install

# RN < 0.60
react-native link react-native-image-picker

Post-install Steps

iOS

Add the appropriate keys to your Info.plist,

If you are allowing user to select image/video from photos, add NSPhotoLibraryUsageDescription.

If you are allowing user to capture image add NSCameraUsageDescription key also.

If you are allowing user to capture video add NSCameraUsageDescription add NSMicrophoneUsageDescription key also.

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.

API Reference

Methods

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

launchCamera()

Launch camera to take photo or video.

launchCamera(options?, callback);

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)

See Options for further information on options.

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

Options

Option iOS Android Description
mediaType OK OK 'photo' or 'video'
maxWidth OK OK To resize the image
maxHeight OK OK To resize the image
videoQuality OK OK 'low', 'medium', or 'high' on iOS, 'low' or 'high' on Android
durationLimit OK OK Video max duration in seconds
quality OK OK 0 to 1, photos
includeBase64 OK OK If true, creates base64 string of the image (Avoid using on large image files due to performance)
saveToPhotos OK OK (Boolean) Only for launchCamera, saves the image/video file captured to public photo

The Response Object

key iOS Android Description
didCancel OK OK true if the user cancelled the process
errorCode OK OK Check ErrorCode for all error codes
errorMessage OK OK Description of the error, use it for debug purpose only
base64 OK OK The base64 string of the image (photos only)
uri OK OK The uri to the local file on the device (uri might change for same file for different session so don't save it)
width OK OK Image dimensions (photos only)
height OK OK Image dimensions (photos only)
fileSize OK OK The file size (photos only)
type OK OK The file type (photos only)
fileName OK OK The file name

Note on file storage

Image/video captured via camera will be stored in temporary folder so will 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 (You have to obtain the permission, the library does not).

ErrorCode

Code Description
camera_unavailable camera not available on device
permission Permission not satisfied
others other errors (check errorMessage for description)

License

MIT

react-native-image-picker's People

Contributors

marcshilling avatar yfuks avatar johan-dutoit avatar charpeni avatar ravirajn22 avatar janicduplessis avatar pedro avatar haitaoli avatar rusfearuth avatar vorjdux avatar alexustinovsm avatar levic92 avatar lizraeli avatar semantic-release-bot avatar udfalkso avatar pjcabrera avatar levipro avatar johanisfap avatar igorming avatar nevir avatar npomfret avatar sgonyea avatar sarovin avatar iraycd avatar cooperka avatar keeth avatar brouding avatar algera avatar skv-headless avatar ajfigueroa avatar

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.