【问题标题】:react-native : image-crop-picker onPress cancelreact-native : 图像裁剪选择器 onPress 取消
【发布时间】:2019-11-06 13:50:03
【问题描述】:

我正在使用react-native-image-crop-picker,想知道cancel button is pressed 时如何设置状态。有没有办法在按下cancel button 时调用函数?

【问题讨论】:

  • 本机不处理这个事件,如果你想这样做,你必须修改代码。如果你想在android中怎么做,我可以给出答案。

标签: react-native


【解决方案1】:

您可以在 .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
})

【讨论】:

    【解决方案2】:

    也许你可以通过检查图像是否被选中来处理。

    ImagePicker.openPicker({
      width: 300,
      height: 400,
      cropping: true
    }).then(image => {
      if (image) {
        // Image is selected
      } else {
        // Cancel Pressed
      }
    });
    

    【讨论】:

    • 感谢您的评论。但我不认为 else 里面的代码等于按下取消按钮。
    猜你喜欢
    • 2017-07-08
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 2018-10-24
    • 2019-03-12
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多