Obecnie pracujemy nad projektem SendBird i React-native, w którym moduł polega na zmianie automatycznie generowanego obrazu profilu profileUrl
na nowy obraz pobrany z aparatu telefonu lub magazynu galerii. Jednak poniższy kod, który wpisałem, nie działa i albo wyświetla błąd, albo aplikacja się zawiesza. Czy mogę wiedzieć, gdzie popełniłem błąd? (Obraz jest przesyłany/wybierany za pomocą narzędzia 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
nobody99
29 listopad 2018, 13:41
1 odpowiedź
Najlepsza odpowiedź
Powinieneś przypisać tylko response.uri
w profileUrl
, a nie {uri: response.uri}
, ponieważ już określasz uri
podczas podawania source
profileUrl
w avatar
.
0
Suraj Malviya
29 listopad 2018, 14:00