npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@stream-io/react-native

v0.2.5

Published

Stream React Native Activity Feed Components ============================================

Downloads

4

Readme

Stream React Native Activity Feed Components

Installation

npm i @stream-io/react-native

Usage

Setup StreamApp component

In order to use Stream React Components in your application, you first need to initialize the StreamApp component. StreamApp holds your application config and acts as a service/data provider.

<StreamApp
  apiKey="{API_KEY}"
  appId="{APP_ID}"
  userId="{USER_ID}"
  token="{TOKEN}"
  analyticsToken="{ANALYTICS_TOKEN}"
>
{/* everything from your application interacting with Stream should be nested here */}
</StreamApp>
  1. API_KEY your Stream application API_KEY
  2. API_ID your Stream application ID
  3. USER_ID current user's ID
  4. TOKEN the authentication token for current user
  5. ANALYTICS_TOKEN [optional] the Analytics auth token

You can find your API_KEY and APP_ID on Stream's dashboard.

Generating user token

The authentication user token cannot be generated client-side (that would require sharing your API secret). You should provision a user token as part of the sign-up / login flow to your application from your backend.

var client = stream.connect(API_KEY, API_SECRET);
var userToken = client.createUserSessionToken(userId);

Generating analytics token

React components have analytics instrumentation built-in, this simplifies the integration with Stream. In order to enable analytics tracking, you need to initialize StreamApp with a valid analytics token. You can generate this server-side as well.

var client = stream.connect(API_KEY, API_SECRET);
var userToken = client.getAnalyticsToken();

Navigation

The components bundled in this library assume that you are using react-navigation for navigation; when reading docs and examples you should expect props.navigation to refer it.

Flat feed component

The FlatFeed component allows you to read a feed using Stream APIs and takes care of rendering the activities.

<FlatFeed
  feedGroup=feedGroup                 {/* the feed group to read (eg. "flat") */}
  userId=userId                       {/* the ID of the user (optional, defaults to StreamApp's userId)  */}
  navigation={this.props.navigation}  {/* your navigation instance */}
  ActivityComponent={Activity}        {/* the activity component to use (optional, defaults to Activity) */}
/>

Activities

Customizing Activities

This library comes with an Activity component; in most cases you will have to make some changes to how activities are rendered. All components rendering activities have a ActivityComponent property that allows you to overwrite how activities should look like in your application.

Adding activities to feeds

TODO: explain how to add an activity to a feed

Follow button component

TODO: follow toggle button component

Notification feeds

Notification status

TODO: how to add the bell component

Notification feed

TODO: how to render notification feeds

Reactions

Both Stream API and the React Native library support adding related data to activities called reactions such as: likes, comments, upvotes...

Likes

Likes can be added to your activities using composition. Here's an example Activity component that includes a like count and a toggle button to like/unlike.

import ReactionCounter from '@stream-io/react-native/lib/components/ReactionCounter';

import LikeIcon from './images/tlike.png';
import LikedIcon from './images/tliked.png';

export default class Activity extends React.Component<Props> {
  render() {
    let {activity} = this.props;

    <ReactionCounter
      value={activity.reaction_counts.like || 0},
      icon={{
        source:
          activity.own_reactions &&
          activity.own_reactions.like &&
          activity.own_reactions.like.length
            ? LikedIcon
            : LikeIcon
      }}
      onPress={ () => {
        this.props.onToggleReaction('like', activity);
      }
    />
  }
 }

You can also include the list of users that liked an activity using the LikesList component.

import LikesList from '@stream-io/react-native/lib/components/LikesList';

//...

render() {
  let {activity} = this.props;

  <LikesList
    onAvatarPress={(id) => this._onAvatarPress(id)}
    likes={activity.likes}
  />
}

//...

Comments

Comments are another use-case for activity reactions.

Show last N comments
import ReactionCounter from '@stream-io/react-native/lib/components/ReactionCounter';

export default class Activity extends React.Component<Props> {
  render() {
    let {activity} = this.props;

    <CommentsContainer
      data={
          activity.latest_reactions &&
          activity.latest_reactions.comment
            ? activity.latest_reactions.comment
            : []
      }
      maxComments={3}
      renderComment={(item, i) => {
          return (
            <Text
              key={`item-${i}`}
            >
              <Text>
                {item.actor.data.Name}
              </Text>{' '}
              <Text>{item.content}</Text>
            </Text>
          );
      }}
      renderMoreLink={() => {
        return (
          <TouchableOpacity>
            <View>
              <Text>More Comments</Text>
            </View>
          </TouchableOpacity>
        );
      }}
    />
  }
 }
Post a new comment

Custom reactions

Likes and Comments are just a very common use case that come bundled with components; Stream APIs allows you to create any kind of reaction to users' activities (eg. share, clap, upvote, ...).

More information about how Reaction APIs work is available here.

Copyright and License Information

Copyright (c) 2015-2018 Stream.io Inc, and individual contributors. All rights reserved.

See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.