【问题标题】:Adding time ago to React Native Elements ListItem将时间前添加到 React Native Elements ListItem
【发布时间】:2018-04-06 09:42:21
【问题描述】:

我使用React Native Elements ListItem 来渲染我的FlatList 项目。我想在与标题相同的行中设置 timeago 文本(例如:20 Minutes Ago)。但是当我将字幕行数设置为 5 时,timeago 文本会出现在字幕行中。我该如何解决这个问题?

<FlatList
  data={this.props.data}
  renderItem={({item}) => (
    <ListItem
      roundAvatar={true}
      avatar={{uri: item.picture.thumbnail}}
      title={`${item.name.first} ${item.name.last}`}
      titleStyle={styles.title}
      rightTitle="20 Minutes Ago"
      rightTitleStyle={styles.rightTitle}
      rightTitleContainerStyle={styles.rightTitleContainer}
      //  subtitle="This is a sample comment which was commented by the developer."
      subtitleStyle={styles.subtitle}
      subtitleContainerStyle={styles.subtitleContainer}
      subtitleNumberOfLines={5}
      hideChevron={true}
      containerStyle={styles.flatListContainer}
    />
  )}
  keyExtractor={item => item.email}
  ItemSeparatorComponent={this.seperator}
  onRefresh={this.handleRefresh}
  refreshing={this.props.refreshing}
  onEndReached={this.handleLoadMore}
  onEndReachedThreshold={50}
/>

【问题讨论】:

  • ListItemstyles能发一下吗,还要不要设置字幕?
  • 我想要5行字幕。副标题是评论。 const styles = StyleSheet.create({ container: { flex: 1 }, listItemContainer: { flex: 1, borderBottomWidth: 0 }, 分隔符: { height: 1, width: "86%", backgroundColor: "#CED0CE", marginLeft : "12%" }, title: { marginLeft: 5, fontSize: 16, fontWeight: "600", color: "black" }, subtitle: { marginLeft: 5, fontSize: 14, fontWeight: "normal" }, rightTitle : { color: "grey", fontSize: 12 } });

标签: react-native react-native-flatlist react-native-elements


【解决方案1】:

垂直居中rightTitle默认行为,就像docs说的那样

提供 rightTitle 以在按钮右侧显示标题

为此,您可以将rightTitleContainerStyle 添加为

{position: 'absolute', top: (YOUR_TITLE_FONT_SIZE - YOUR_RIGHT_TITLE_FONT_SIZE) / 2, right: 0}

【讨论】:

  • 非常感谢Pritish。我花了一整天来解决这个问题。有一个小问题。我想增加头像大小。头像应该是圆形的。但是当我增加尺寸时,它变成了方形。我该如何解决?
  • 如果您也可以为此发布问题,以及头像的相关样式,那就太好了
  • 这是新问题 Pritish 的链接。 stackoverflow.com/questions/49696311/…
  • 是的,我给那个人一个answer
  • 它按照你的解释工作。谢谢普里蒂什。我在这里问了另一个问题。 stackoverflow.com/questions/49719835/…可以帮忙吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-25
相关资源
最近更新 更多