React Native:状态已更改,组件未重新呈现

时间:2017-09-15 12:19:30

标签: react-native

通过Image Picker选择图像后,打开拾取器的按钮必须由Image替换。我是按照以下方式这样做的

{ this.state.userImage === null ?  
        <IconButton  
          icon={{name: "photo-camera", size: 32}}
          buttonStyle={{backgroundColor: "#397af8", borderRadius: 2,marginLeft: 50,height: 50, width: 200}}
          textStyle={{textAlign: 'center',color: "#000000"}}
          title={this.state.textBttn}
          onPress={() => this._selectImage()}/> : <Image style={styles.userimg} source={this.state.userImage} />
          }

能够确认在选择图像后userImage发生了变化,但组件没有渲染。有什么解决方案吗?

编辑:更新状态

ImagePicker.showImagePicker(options, (response) => {
  console.log('Response = ', response);

  if (response.didCancel) {
    console.log('User cancelled image picker');
  }
  else if (response.error) {
    console.log('ImagePicker Error: ', response.error);
  }
  else {
    let source = { uri: response.uri };

    // let source = { uri: 'data:image/jpeg;base64,' + response.data };

    this.setState({
      userImage: source,
      testVal : 'changed'

      });
  console.log("state = "+this.state.userImage);
  console.log("state = "+this.state.testVal);
  }
});

0 个答案:

没有答案