我正在构建一个具有一些额外功能的简单图像列表应用程序,其中之一是下载图像功能。
但是,我不断收到此“找不到变量项”错误。我该如何解决?
item.image
// ...
downloadImage = () => {
const fileUri = `${FileSystem.documentDirectory}breathtaking.jpg`
FileSystem
.downloadAsync(item.image,fileUri)
.then(({ uri }) => {
console.log('Finished downloading to ',uri)
})
CameraRoll.saveToCameraRoll(fileUri,'photo')
}
// ...
return (
// ...
<Button
icon='file-download'
mode='contained'
onPress={this.downloadImage}
style={{ borderRadius: 0,width: '33.4%' }}
/>
// ...
);
UPDATE
componentDidmount() {
const url = "/* json */";
this.setState({ isLoading: true });
fetch(url)
.then(response => response.json())
.then(responseJson => {
this.setState({
dataSource: shuffle(responseJson.listings),dataBackup: responseJson.listings,isLoading: false
});
})
.catch(error => {
console.log(error);
});
}
renderItem = ({ item }) => {
return (
<View style={{ padding: 15,paddingBottom: 0 }}>
<Card elevation={1}>
<View
style={{
flex: 1,flexDirection: "row",flexWrap: "wrap",alignItems: "flex-start"
}}
>
<View style={{ flex: 1 }}>
<TouchableOpacity
onPress={() => {
this.toggleModal();
this.setState({
webViewurl: item.image
});
}}
onLongPress={() => Linking.openURL(item.image)}
activeColor="blue"
>
<ImageBackground
source={{ uri: item.image }}
style={{ height: 216 }}
>
<IconButton
icon="favorite-border"
size={20}
color="#6200EE"
style={{ alignSelf: "flex-end" }}
onPress={this._savedAlert}
/>
</ImageBackground>
</TouchableOpacity>
</View>
</View>
</Card>
</View>
);
}