Avatar R.N图像选择器上的选定图像更新



大家好,我正在使用React原生图像选择器我可以从安卓库中选择图像,但选择后我无法更新我的Avatar个人资料[Image]

选择图像后,这里是我的控制台。log

响应={quot;资产":"rn_image_picker_lib_temp_01a3684e-c92d-47af-957a-d81ded046c65.png";,"文件大小":22968;高度":2340;类型":"image/png"uri":"file:///data/user/0/com.testappimagepicker/cache/rn_image_picker_lib_temp_01a3684e-c92d-47af-957a-d81ded046c65.png","宽度":1080}]}

App.js

import { Icon, Avatar } from "@rneui/themed";
import React, { useState, useEffect } from "react";
import { launchImageLibrary } from "react-native-image-picker";
import {
Button,
SafeAreaView,
ScrollView,
StyleSheet,
View,
KeyboardAvoidingView,
} from "react-native";
export default function ImagePickerExample(props) {
const [image, setImage] = useState("../../assets/image/xyz.png");
openImageGallery = () => {
launchImageLibrary({ noData: false }, (response) => {
console.log('responseponse = ', response);
});
}
return (
<SafeAreaView>
<ScrollView>
<View style={styles.container}>
<KeyboardAvoidingView>
<View>
<View
style={{
flexDirection: "row",
justifyContent: "space-around",
marginBottom: 20,
}}
>
<Avatar
size={150}
rounded
source={{ uri: image }}
containerStyle={{ backgroundColor: "grey" }}
>
<Avatar.Accessory size={30}
onPress={() => { openImageGallery() }}
/>
</Avatar>
</View>
</View>
</KeyboardAvoidingView>
</View>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
});

试试这个,

const openImageGallery = () => {
launchImageLibrary({ noData: false }, (response) => {
setImage(response.assets[0].uri);
});
}

最新更新