当前正在研究SendBird和react-native项目,该模块的工作是将自动生成的个人资料图像profileUrl
更改为从手机相机或图库存储中获取的新图像。但是,我输入的以下代码不起作用,并且显示错误或应用程序冻结。我可以知道我做错了什么吗? (图像是使用react-native-image-picker上传/选择的。)
_changeProfileImg(){
ToastAndroid.show('ClickedImage', ToastAndroid.SHORT);
var _Self = this;
var source = [];
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel){
console.log('user canceled image picker');
}
else if (response.error){
console.log('imagePicker error', response.error);
}
else if (response.customButton){
console.log('customised clicked', response.customButton);
}
else{
source = {uri:response.uri};
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
this.setState({
profileUrl: source,
});
}
});
}
render(){
return(
<View style={styles.container}>
<View style={styles.contentFlex}>
<Text>{this.state.profileUrl}</Text>
<Avatar
rounded
size="xlarge"
source={{uri: this.state.profileUrl}}
onPress={this._changeProfileImg.bind(this)}
activeOpacity={0.7}
/>
</View>
答案 0 :(得分:0)
您应该只在response.uri
中分配profileUrl
,而不要在{uri: response.uri}
中分配uri
,因为您已经在将{{1 }}在source
中。