【发布时间】:2021-03-08 19:05:46
【问题描述】:
我正在尝试在屏幕上显示图像之前实现触发事件。下面的 sn-p 可以正常选择图像并显示在屏幕上。单击 CROP 后,图像将显示在屏幕上。但是,点击CROP后,会显示一个自定义事件,如输入字段以获取有关图像的一些信息,然后图像将显示在屏幕上。如何实现此功能?
import React, { useState, useEffect } from 'react';
import { Button, Image, View, Platform, Alert } from 'react-native';
import * as ImagePicker from 'expo-image-picker';
export default function ImagePickerExample() {
const [image, setImage] = useState(null);
useEffect(() => {
(async () => {
if (Platform.OS !== 'web') {
const { status } = await ImagePicker.requestCameraPermissionsAsync();
await Alert.alert("Hello")
if (status !== 'granted') {
alert('Sorry, we need camera roll permissions to make this work!');
}
}
})();
}, []);
const pickImage = async () => {
let result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
quality: 1,
});
console.log(result);
if (!result.cancelled) {
setImage(result.uri);
}
};
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button title="Pick an image from camera roll" onPress={pickImage} />
{image && <Image source={{ uri: image }} style={{ width: 200, height: 200 }} />}
</View>
);
}
【问题讨论】:
-
有人至少给我一些提示,我该怎么做?
-
所以基本上你希望用户在裁剪图像后立即添加有关图像的附加信息?
标签: reactjs react-native expo react-native-image-picker