React-native-image-crop-picker: Promise setState() is not working

Created on 10 Apr 2018  路  2Comments  路  Source: ivpusic/react-native-image-crop-picker

Version

  • react-native-image-crop-picker v0.20.0
  • react-native v0.51.0

Platform

IOS

Expected behaviour

After open the image picker and pick an image, the api will return promise, so in callback then() i can't setState(). Here is my following code.

showCamera() { const ip = ImagePicker.openPicker({ maxWidth: 1000, maxHeight: 1000, includeBase64: true, mediaType: 'photo', cropping: true, }).then(image => { const { filename, mime, data } = image; const source = `data:image/jpeg;base64,${data}`; this.setState({ pic: source, picType: mime, picName: filename, }); console.log(image, this.state); }); }
It does not show any error, but warning. when i check back the state value, it was empty.
screen shot 2018-04-10 at 10 37 46 am

Actual behaviour

It suppose to set the state value. but it does'nt. im surprised nobody talking about this issue. Could be the way i did something is wrong or what. Please Advice~ Thanks You!

Alternative way are welcome~

Most helpful comment

I found the problem! In my view got this

<TouchableOpacity onPress={this.showCamera}> <Icon style={styles.icon} name='user' size={80} /> </TouchableOpacity>

i should change it to
this.showCamera.bind(this)

All 2 comments

ImagePicker.openPicker({
        xxx
    }).then(image => {
        xxx
    }).catch(err => {
        console.log(err)
    })

catch if there is something error

I found the problem! In my view got this

<TouchableOpacity onPress={this.showCamera}> <Icon style={styles.icon} name='user' size={80} /> </TouchableOpacity>

i should change it to
this.showCamera.bind(this)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manojshrimalla picture manojshrimalla  路  3Comments

pavsidhu picture pavsidhu  路  3Comments

equesteo picture equesteo  路  3Comments

Martian2Lee picture Martian2Lee  路  3Comments

aterribili picture aterribili  路  3Comments