Как предоставить разрешение на доступ к библиотеке фотографий камеры в коде Visual Studio для приложения ReactNative Iphone - PullRequest
0 голосов
/ 04 августа 2020

Я хочу знать, как предоставить разрешение на доступ к библиотеке фотографий камеры в коде Visual Studio для приложения ReactNative Iphone?

Вот мой код:

FeedBackScreen. js :

import React,{Component} from 'react';
import {View,Text, StyleSheet,FlatList,Dimensions,TouchableOpacity,Image} from 'react- 
native';
import {ActionSheet,configuration,onSelect,Root,options} from 'native-base';
import ImagePicker from 'react-native-image-crop-picker';

const width = Dimensions.get('window').width;
export default class FeedBackScreen extends Component{
constructor(props){
super(props);
this.state = {
fileList:[]
}
}

onSelectedImage = (image) =>{
let newDataImg = this.state.fileList;
const source = {uri:image.path};
let item = {
id:Date.now(),
url:source,
content:image.content
}
newDataImg.push(item);
this.setState({fileList:newDataImg})
};

takePhotoFromCamera = () =>{
ImagePicker.openPicker({
 width:300,
 height:400,
 cropping:true
 }).then(image =>
 {
  this.onSelectedImage(image);
  console.log(image);
 })
 };

 choosePhotoFromLibrary = () =>{
 ImagePicker.openPicker({
 width:300,
 height:400,
 cropping:true
 }).then(image =>{
 this.onSelectedImage(image);
 console.log(image);
  })
  };

 onClickAddPhoto = () => {
 const BUTTONS = ['Take Photo', 'Choose Photo Library', 'Cancel'];
 ActionSheet.show({
 options: BUTTONS,
 cancelButtonIndex: 2,
 title: 'Select a Photo'
 }, 
 buttonIndex => {
  switch (buttonIndex) {
    case 0:
      this.takePhotoFromCamera();
      break;
    case 1:
      this.choosePhotoFromLibrary();
      break;
    default:
      break;
  }
  })
  }
  renderItem = ({item,index}) =>{
  return(
  <View>
  <Image 
  source={item.url}
  style={styles.itemImage}
  />
  </View>
  )
  };
  render(){
  let {content,btwPressStyle} = styles;
  let {fileList } = this.state;
  return(
   <Root>
      <View style={content}>
      <Text>Sample React Native Add Image</Text>
      <FlatList 
      data={fileList}
      renderItem={this.renderItem}
      keyExtractor={(item,index) => index.toString()}
      extraData={this.state}
      />
    <TouchableOpacity onPress={this.onClickAddPhoto}
    style={styles.btwPressStyle}>
    <Text>Add Photo</Text>
  </TouchableOpacity> 
    </View>

   </Root>
  )
  }
  };

  const styles = StyleSheet.create({
  content:{
  flex:1,
  alignItems:'center',
  marginTop:50
  },
  btwPressStyle:{
  backgroundColor:'blue',
  height:50,
  width:100,
  alignItems:'center'
  },
  itemImage:{
  backgroundColor:'#2F455C',
  height:150,
  width:width-60,
  borderRadius:8,
  resizeMode:'contain'
  }
  })

После запуска выдает следующую ошибку: TypeError: null не является объектом (оценка '_reactNativeImageCropPicker.default.openPicker')

Не могли бы вы помочь мне с Как дать разрешение? Заранее спасибо.

...