【发布时间】:2021-06-15 16:24:59
【问题描述】:
我想在 react native 应用程序中捕获和渲染 3 个不同的图像。我怎样才能做到这一点。现在我可以单击图像,但是当我单击图像时,同一图像会渲染 3 次,但我想一张一张地单击图像。
这是我的代码
constructor(props) {
super(props);
this.state = {
resourcePath: {},
singleFile:null,
fileUri:null,
imageArray:{
PAN: null,
ADH: null,
ADH1: null,
},
imageType:'',
evenTry:false,
singleFilePAN:'',
singleFileADH:'',
singleFileADH1:'',
showCamera: false
};
}
requestCameraPermission = async () => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CAMERA,
{
title: "App Camera Permission",
message:"App needs access to your camera ",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
let options = {
storageOptions: {
skipBackup: true,
path: 'images',
},
};
ImagePicker.launchCamera(options, (res) => {
console.log('Response = ', res);
if (res.didCancel) {
console.log('User cancelled image picker');
} else if (res.error) {
console.log('ImagePicker Error: ', res.error);
} else if (res.customButton) {
console.log('User tapped custom button: ', res.customButton);
alert(res.customButton);
} else {
const source = { uri: res.uri };
console.log('response', res.uri);
const newImageArray = this.state.imageArray;
newImageArray.PAN = res.uri
newImageArray.ADH = res.uri
newImageArray.ADH1 = res.uri
this.setState({imageArray : {...newImageArray}})
this.setState({
filePath: res,
fileData: res.data,
fileUri: res.uri,
singleFilePAN: newImageArray.PAN,
singleFileADH: newImageArray.ADH,
singleFileADH1: newImageArray.ADH1
});
}
})
} else {
console.log("Camera permission denied");
}
} catch (err) {
console.warn(err);
}
};
render() {
return (
<View style={styles.container}>
<View style={styles.container}>
<Image source={{uri: this.state.imageArray.PAN}} style={{width: 100, height: 100}} />
<Image source={{uri: this.state.imageArray.ADH}} style={{width: 100, height: 100}} />
<Image source={{uri: this.state.imageArray.ADH1}} style={{width: 100, height: 100}} />
<TouchableOpacity onPress={this.requestCameraPermission} style={styles.button}>
<Text style={styles.buttonText}>Launch Camera Directly</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.uploadImage} style={styles.button} >
<Text style={styles.buttonText}>फोटो अपलोड कीजिए</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
请忽略这个。我想在反应原生应用程序中捕获和渲染 3 个不同的不同图像。我怎样才能做到这一点。现在我可以单击图像,但是当我单击图像时,相同的图像会渲染 3 次,但我想一张一张地单击图像。我想在反应原生应用程序中捕获和渲染 3 个不同的不同图像。我怎样才能做到这一点。现在我可以单击图像,但是当我单击图像时,同一图像会渲染 3 次,但我想一张一张地单击图像。
【问题讨论】:
标签: image react-native file-upload image-upload react-native-image-picker