照片头像

时间:2018-05-21 18:12:46

标签: react-native

解决

我可以拍摄照片,在屏幕上打印并成功上传到服务器上。但刚刚重新访问个人资料页面后默认图片未显示

<TouchableOpacity onPress={this.shotPhoto.bind(this)}>
  <Image style={{ height: 200, width: 150 }} source={{ uri: this.props.userpicture } == { uri: 'http://webstudio.web.tr/resimler/resimyok.png' } ? { uri: 'http://webstudio.web.tr/resimler/kullaniciresmi/' + this.state.email + '.jpeg' } : { uri: this.props.userpicture }} />
  <Text style={{ height: 50, width: 150, backgroundColor: 'green' }}>Shot a photo</Text>
</TouchableOpacity>

Photo after camera shot, profile owner photo shown successfully First visit of the page not shown the picture of profile owner

我项目的complate源代码位于https://github.com/EnginYilmaz/kpbduser/blob/master/src/user/HesabimForm.js

(是的,对我来说,给我任何想法很重要)

2 个答案:

答案 0 :(得分:1)

我不确定确切的问题,但是在这里你将对象与另一个对象进行比较,无论userpicture值是什么,它总是为假:

{ uri: this.props.userpicture } == { uri: 'http://webstudio.web.tr/resimler/resimyok.png' } ? { uri: 'http://webstudio.web.tr/resimler/kullaniciresmi/' + this.state.email + '.jpeg' } : { uri: this.props.userpicture }

尝试比较网址:

this.props.userpicture == 'http://webstudio.web.tr/resimler/resimyok.png' ? { uri: 'http://webstudio.web.tr/resimler/kullaniciresmi/' + this.state.email + '.jpeg' } : { uri: this.props.userpicture }

答案 1 :(得分:0)

我找到了一个解决方法,我的解决方案是:

isShotPhoto () {
if (!this.props.userpicture ) {
  return (
    <TouchableOpacity onPress={this.shotPhoto.bind(this)}>
      <Image style={{ height: 200, width: 150 }} source={{ uri:'http://webstudio.web.tr/resimler/kullaniciresmi/'+this.state.email+'.jpeg' }} />
      <Text style={{ height: 50, width: 150, backgroundColor: 'green' }}>Fotoğrafınızı çekin</Text>
    </TouchableOpacity>
    );
} else {
  return (
  <TouchableOpacity onPress={this.shotPhoto.bind(this)}>
    <Image style={{ height: 200, width: 150 }} source={{ uri:this.props.userpicture  }} />
    <Text style={{ height: 50, width: 150, backgroundColor: 'green' }}>Fotoğrafınızı çekin</Text>
  </TouchableOpacity>
  );
}

}