How to create React Native Image Picker

In this React Native source code example, the source code below illustrate how to create React Native Image Picker.

You can copy and adopt this source code example to your React Native project without reinventing the wheel.

import React, { Component } from 'react';
import { View, StyleSheet,Text,Image} from 'react-native'
import ImagePicker from 'react-native-image-picker';

const options = {
  storageOptions: {
    skipBackup: true,
    path: 'images'
  }
};

export default class App extends Component {
  state = { image:''}

  getImage(){
    ImagePicker.launchImageLibrary(options, (response) => {
      var source= response;
        this.setState({ image:source});
      });
  }
   render() {
      return (
         <View style={styles.container}>
              <Text
                style={{padding: 10,backgroundColor: 'rgb(242, 143, 247)'}}
                onPress={()=>this.getImage()}>Find Image</Text>
              <Image source={{ uri: this.state.image.uri }} style={{ width: 200, height: 200,margin: 10 }}
                 />
         </View>
      )
   }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#ddd'
  },
})

If you have any questions or suggestions kindly use the comment box or you can contact us directly through our contact page below.

 

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.