Code Monkey home page Code Monkey logo

react-native-image-picker's Introduction

React Native Image Picker

npm version npm MIT Platform - Android and iOS Gitter chat

A React Native module that allows you to use native UI to select a photo/video from the device library or directly from the camera, like so:

๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง

๐Ÿšง๐Ÿšง๐Ÿšง๐ŸšงHelp & Input Wanted ๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง

๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง๐Ÿšง

iOS Android

Before you open an issue

This library started as a basic bridge of the native iOS image picker, and I want to keep it that way. As such, functionality beyond what the native UIImagePickerController supports will not be supported here. Multiple image selection, more control over the crop tool, and landscape support are things missing from the native iOS functionality - not issues with my library. If you need these things, react-native-image-crop-picker might be a better choice for you.

React Native Compatibility

To use this library you need to ensure you match up with the correct version of React Native you are using.

p.s. React Native introduced AndroidX support in 0.60, which is a breaking change for most libraries (incl. this one) using native Android functionality.

@react-native-community/imagepicker version Required React Native Version
1.x.x >= 0.60 or >= 0.59 if using Jetifier
0.x.x <= 0.59

Getting Started

yarn add react-native-image-picker

# RN >= 0.60
npx pod-install

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

You will also need to add UsageDescription on iOS and some permissions on Android, refer to the Install doc.

Usage

import ImagePicker from 'react-native-image-picker';

// More info on all the options is below in the API Reference... just some common use cases shown here
const options = {
  title: 'Select Avatar',
  customButtons: [{ name: 'fb', title: 'Choose Photo from Facebook' }],
  storageOptions: {
    skipBackup: true,
    path: 'images',
  },
};

/**
 * The first arg is the options object for customization (it can also be null or omitted for default options),
 * The second arg is the callback which sends object: response (more info in the API Reference)
 */
ImagePicker.showImagePicker(options, (response) => {
  console.log('Response = ', response);

  if (response.didCancel) {
    console.log('User cancelled image picker');
  } else if (response.error) {
    console.log('ImagePicker Error: ', response.error);
  } else if (response.customButton) {
    console.log('User tapped custom button: ', response.customButton);
  } else {
    const source = { uri: response.uri };

    // You can also display the image using data:
    // const source = { uri: 'data:image/jpeg;base64,' + response.data };

    this.setState({
      avatarSource: source,
    });
  }
});

Then later, if you want to display this image in your render() method:

<Image source={this.state.avatarSource} style={styles.uploadAvatar} />

Directly Launching the Camera or Image Library

To Launch the Camera or Image Library directly (skipping the alert dialog) you can do the following:

// Launch Camera:
ImagePicker.launchCamera(options, (response) => {
  // Same code as in above section!
});

// Open Image Library:
ImagePicker.launchImageLibrary(options, (response) => {
  // Same code as in above section!
});

Notes

On iOS, don't assume that the absolute uri returned will persist. See #107

For more, read the API Reference.

License

MIT

react-native-image-picker's People

Contributors

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

Watchers

 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.