我在我的 react-native 应用程序中有一个图像上传器,一旦您上传图像,它就会将您导航到另一个屏幕并在那里预览图像,在图像预览屏幕中,有一个用于为该图像命名的输入和一个保存按钮,单击保存按钮时,它应该返回上一个屏幕并在我拥有的平面列表中显示图像及其名称,我设法执行这些步骤,直到预览图像,但之后我不知道下一步该做什么,这是代码:
第一个画面:
state = {
image: null,
previews: []
};
_pickImage = async () => {
await Permissions.askAsync(Permissions.CAMERA_ROLL);
const {navigate} = await this.props.navigation;
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: false,
aspect: [4, 4],
});
navigate( 'ImagePreview', { uri : result.uri } );
if (!result.cancelled) {
this.setState({ image: result.uri });
}
};
_keyExtractor (item, index) {
return index.toString();
}
_renderItem ({ item, index }) {
return (
<View>
<Image source={require('')}/>
<Text>Image title</Text>
</View>
);
}
<FlatList style={{ flex: 0.5 }}
data={this.state.previews}
keyExtractor={this._keyExtractor.bind(this)}
renderItem={this._renderItem.bind(this)}
numColumns={2}
/>
第二屏:
const uri = navigation.getParam('uri');
<Image source={{uri:uri}} style={{width: 200, height: 200}} />
<Button title="Save" />