首页 > 解决方案 > react-native : 图像裁剪选择器 onPress 取消

问题描述

我正在使用react-native-image-crop-picker并想知道如何 setState when 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
})

推荐阅读