Created
June 28, 2018 17:09
-
-
Save PrimeTimeTran/41f0c01c3b25e2d22274aaa77d8fc3a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Too many nested conditionals | |
renderCurrentUser() { | |
const { currentUser, avatarSource } = this.state | |
const { size, photoStyle } = styles | |
if (avatarSource) { | |
return ( | |
<Image | |
style={photoStyle} | |
source={avatarSource} | |
/> | |
) | |
} else { | |
if (currentUser && currentUser.uploads && currentUser.uploads.length > 0) { | |
if (currentUser.uploads.length === 1 ) { | |
return ( | |
<Image | |
style={photoStyle} | |
source={{ uri: currentUser.uploads[0].url }} | |
/> | |
) | |
} else { | |
return ( | |
<Carousel | |
autoplay={false} | |
style={size} | |
onAnimateNextPage={p => console.log(p)}> | |
{currentUser.uploads.map(upload => { | |
return ( | |
<Image | |
key={upload.id} | |
style={photoStyle} | |
source={{ uri: upload.url }} | |
/> | |
) | |
})} | |
</Carousel> | |
) | |
} | |
} else { | |
return ( | |
<Image | |
style={photoStyle} | |
source={{ uri: defaultImage }} | |
/> | |
) | |
} | |
} | |
} | |
// Hard to understand | |
renderCurrentUser() { | |
const { currentUser, avatarSource } = this.state | |
const { size, photoStyle } = styles | |
if (avatarSource) { | |
return ( | |
<Image | |
style={photoStyle} | |
source={avatarSource} | |
/> | |
) | |
} else { | |
currentUser && currentUser.uploads && currentUser.uploads.length > 0 | |
? | |
currentUser.uploads.length === 1 | |
? | |
<Image | |
style={photoStyle} | |
source={{ uri: currentUser.uploads[0].url }} | |
/> | |
: | |
<Carousel | |
autoplay={false} | |
style={size} | |
onAnimateNextPage={p => console.log(p)}> | |
{currentUser.uploads.map(upload => { | |
return ( | |
<Image | |
key={upload.id} | |
style={photoStyle} | |
source={{ uri: upload.url }} | |
/> | |
) | |
})} | |
</Carousel> | |
: | |
<Image | |
style={photoStyle} | |
source={{ uri: defaultImage }} | |
/> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment