【发布时间】:2019-11-06 13:50:03
【问题描述】:
我正在使用react-native-image-crop-picker,想知道cancel button is pressed 时如何设置状态。有没有办法在按下cancel button 时调用函数?
【问题讨论】:
-
本机不处理这个事件,如果你想这样做,你必须修改代码。如果你想在android中怎么做,我可以给出答案。
标签: react-native
我正在使用react-native-image-crop-picker,想知道cancel button is pressed 时如何设置状态。有没有办法在按下cancel button 时调用函数?
【问题讨论】:
标签: react-native
您可以在 .catch 方法中使用 setState,因为 openPicker 返回一个承诺。
ImagePicker.openPicker({
width: 300,
height: 400,
cropping: true
}).then(image => {
// Here you handle the image
}).catch(err => {
// Here you handle if the user cancels or any other errors
})
【讨论】:
也许你可以通过检查图像是否被选中来处理。
ImagePicker.openPicker({
width: 300,
height: 400,
cropping: true
}).then(image => {
if (image) {
// Image is selected
} else {
// Cancel Pressed
}
});
【讨论】: