首页 > 解决方案 > 如何添加评论以在本机反应中获取流

问题描述

我想在我的 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 有关,但我不太确定

标签: react-nativegetstream-io

解决方案


您将需要使用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 } }}
      />
    );
  }}
/>

推荐阅读