react-native:image-crop-picker onPress取消

我正在使用react-native-image-crop-picker,并且想知道在cancel button is pressed时如何设置状态。按下cancel button时有什么方法可以调用函数吗?

cxl13461615166 回答:react-native:image-crop-picker onPress取消

您可以在.catch方法中使用setState,因为openPicker返回一个Promise。

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,cropping: true
}).then(image => {
  if (image) {
    // Image is selected
  } else {
    // Cancel Pressed
  }
});
本文链接:https://www.f2er.com/3155251.html

大家都在问