【问题标题】:How to add comments to get stream in react native如何添加评论以在本机反应中获取流
【发布时间】:2019-09-05 21:59:14
【问题描述】:

我想在我的 react 本机应用程序中添加一个评论部分,类似于 instagram 的应用程序。我正在使用 getstream 活动提要并尝试从 react-native-activity-feed 导入 CommentField,但是在使用它时出现不变的违规错误。但是,我并不完全相信 CommentField 会给我我想要的评论部分类型。 getstream 是否支持这一点,还是我需要创建自己的评论字段并将其保存在数据库中?

编辑:

我有这个活动:

const CustomActivity = (props) => {
  return (
    <Activity
      {...props}
      Footer={
        <>
<CommentList
            CommentItem={({ comment }) => ( <CommentItem comment={comment} /> )}
            activityId={props.activity.id}
            reactions={props.activity.latest_reactions}
      />
          <Image source={ require('./images/logo.png') } style={{width:98, height:22}}/>
          <LikeButton {...props} />
          <CommentBox
            onSubmit={(text) =>
              props.onAddReaction('comment', CustomActivity, { text: text })
            }
            styles={{ container: { height: 78 } }}
          />

        </>

      }
    />
  );

};

然后渲染:

<FlatFeed
   feedGroup = "timeline"
   userID = User ID is put here
   Activity={CustomActivity}
   notify/>

我目前在提交评论时收到此错误:Errors for fields 'activity_id', 'parent'

我认为这可能与 CommentList 中的 activityId 有关,但我不太确定

【问题讨论】:

  • 您能否添加用于此的代码以及有关您想要做什么的更多信息?
  • @TommasoBarbugli 我已经用我现在得到的代码和错误更新了我的问题
  • 我认为CustomActivity的错误在于:props.onAddReaction('comment', CustomActivity, { text: text }),这应该是activity对象,而不是你的自定义组件。

标签: react-native getstream-io


【解决方案1】:

您需要使用CommentBoxCommentList 组件。我们在示例应用程序中做了这样的事情:

<SinglePost
  activity={activity}
  feedGroup={feedGroup}
  userId={userId}
  Activity={(props) => (
    <React.Fragment>
      <Activity
        {...props}
      />
      <CommentList
        CommentItem={({ comment }) => ( <CommentItem comment={comment} /> )}
        activityId={props.activity.id}
        reactions={props.activity.latest_reactions} />
    </React.Fragment>
  )}
  Footer={(props) => {
    return (
      <CommentBox
        onSubmit={(text) =>
          props.onAddReaction('comment', activity, { text: text })
        }
        avatarProps={{
          source: (userData) =>
            userData.data.profileImage,
        }}
        styles={{ container: { height: 78 } }}
      />
    );
  }}
/>

【讨论】:

  • 感谢您的帮助!我对评论和文本的来源感到有些困惑,但我已经用我的代码更新了我的问题,并出现了我目前遇到的错误
  • 我以前从未见过该错误,但您的代码中也有错误。 CommentList 似乎在您的退货声明之外。你能不能先解决这个问题,看看错误是否仍然存在。
  • 我现在已经把它放在了 return 语句中并且得到了同样的东西。我应该添加错误消息以警告框的形式出现,并且终端不会显示任何错误。当我在警报框上单击“确定”时,应用程序仍在运行,但警告说相同的错误消息并且没有显示任何 cmets,因此尚未提交
  • 你确定activityId是正确的吗?你能console.log吗?
猜你喜欢
  • 1970-01-01
  • 2014-07-06
  • 1970-01-01
  • 2022-11-18
  • 2014-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多