如果收到outfitDetail
道具,我会在标题标题处呈现用户的图片和用户名。
class OutfitDetail extends Component {
static navigationOptions = ({navigation, screenProps}) => ({
...
headerTitle: (
!!screenProps.outfitDetail ? (
<View style={styles.container}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('Profile', {id: userId})}>
{this._renderAvatar(screenProps.outfitDetail.user.image)}
</TouchableOpacity>
<View style={styles.content}>
<View style={styles.contentHeader}>
<RkText rkType='header5'>{screenProps.outfitDetail.user.username}</RkText>
<RkText rkType='secondary4 hintColor'>
<TimeAgo time={screenProps.outfitDetail.publish}/>
</RkText>
</View>
<RkText rkType='primary3 mediumLine'>{screenProps.outfitDetail.content}</RkText>
</View>
</View>
): (<Text>Loading</Text>)
),
...
});
因此,如果screenProps.outfitDetail不为null(尚未提取),则会呈现“正在加载”,否则会呈现用户的照片和用户名。
为什么我会Unexpected token, expected , error (React-navigation)
?
错误发生在上面第三行代码上。
答案 0 :(得分:1)
static navigationOptions = ({navigation, screenProps}) => ({
headerTitle: (
!!screenProps.outfitDetail ? (
<View style={styles.container}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('Profile', {id: userId})}>
{this._renderAvatar(screenProps.outfitDetail.user.image)}
</TouchableOpacity>
<View style={styles.content}>
<View style={styles.contentHeader}>
<RkText rkType='header5'>{screenProps.outfitDetail.user.username}</RkText>
<RkText rkType='secondary4 hintColor'>
<TimeAgo time={screenProps.outfitDetail.publish}/>
</RkText>
</View>
<RkText rkType='primary3 mediumLine'>{screenProps.outfitDetail.content}</RkText>
</View>
</View>
):(<Text>Loading</Text>)
),
... other functions ...
})