Skip to main content

Stories Pro

StoryTray and StoryViewer are Instagram's stories: a row of avatars at the top of a feed, ringed in Instagram's gradient until you've seen them, and a full-screen viewer that plays each person's slides with segmented bars across the top. Tap the right side to go on and the left to go back, hold to pause, swipe sideways to the next person with a cube turn, and drag down to close. On wide screens the viewer is a phone-shaped frame in the middle with arrows beside it, as on Instagram's web.

Use it for social apps, but also for product updates ("What's new"), creators in a marketplace, daily recaps, or a course's lessons.

import { StoryTray, StoryViewer } from '@patine-ui/pro';
Loading…
<View>
  <StoryTray users={users} onPress={(_, index) => setOpen(index)} onAddPress={() => {}} ownAvatar="https://i.pravatar.cc/150?img=5" />
  <StoryViewer
    users={users}
    visible={open !== null}
    initialUser={open ?? 0}
    onClose={() => setOpen(null)}
    onSlideSeen={markSeen}
    onReply={(user, slide, text) => console.log('reply', user.name, text)}
    onReact={(user, slide, emoji) => console.log('react', user.name, emoji)}
  />
</View>

Open a story, then try it: tap the right and left sides, hold to pause, drag sideways, drag down to close. On the web, the arrow keys step, Space pauses and Escape closes.

Example: a shop's stories​

A clothing shop's app: each collection is a story in the tray, the slides are product photos with a Shop now card, and replies go to the shop's inbox. A collection turns grey once you've seen its last slide.

Loading…
<View style={{ gap: 8 }}>
  <StoryTray users={users} onPress={(_, index) => setOpen(index)} />
  <Text size="sm" color="textSecondary">{replies ? `${replies} replies sent to the shop` : 'Press a collection to watch it.'}</Text>
  <StoryViewer
    users={users}
    visible={open !== null}
    initialUser={open ?? 0}
    onClose={() => setOpen(null)}
    onSlideSeen={(user, slide) =>
      setUsers((list) => list.map((u) => (u.id === user.id && u.slides[u.slides.length - 1].id === slide.id ? { ...u, seen: true } : u)))
    }
    onReply={() => setReplies((n) => n + 1)}
  />
</View>

Seen and unseen​

The tray puts people you haven't seen first, each in Instagram's gradient ring; once their seen is true the ring goes grey and they move to the end. onSlideSeen fires as each slide shows: mark the person seen when their last slide does, and send the view to your API.

Custom slides​

A slide can be a photo (image, a URL or a require()) or anything you render: a poll, a product with a Shop button, a quote, a chart, or a video player of your own. render gets { paused, muted, active }, so a video can pause while the slide is held and follow the mute button. Set hasAudio to show that button, and duration for a slide that needs longer than five seconds.

{
id: 'drop',
duration: 8000,
hasAudio: true,
render: ({ paused, muted }) => <ProductVideo source={drop.video} paused={paused} muted={muted} />,
}

Replies and reactions​

Give onReply for the reply bar and onReact for the heart and quick reactions. Focusing the reply pauses the story and shows the reactions above it; sending shows "Sent", and a reaction pops on the slide.

Transition​

People change with a cube turn, as on Instagram. transition="slide" slides them side by side instead.

Accessibility​

  • Each slide is one button that reads the person's name and the slide's place ("Maya's story, 2 of 3"), with Next and Previous actions for screen readers, and a photo's alt as its label.
  • The viewer is a modal dialog; Android's back button and Escape close it.
  • Close, mute, like and send are 44-point buttons with names.
  • Bars fill and pages turn on the native driver; with reduce motion on, they move without animating, and the clock still runs.

Props​

StoryTray​

PropTypeDefault
usersStoryUser[]
onPress(user, index) => void
onAddPress() => void: adds "Your story" first
ownAvatarstring | ImageSource
sizenumber, the avatar64

StoryViewer​

PropTypeDefault
usersStoryUser[]
visibleboolean
initialUsernumber0
onClose() => void
onSlideSeen(user, slide) => void
onReply(user, slide, text) => void: shows the reply bar
onReact(user, slide, emoji) => void: shows the heart and reactions
transition'cube' | 'slide''cube'
reactionsstring[]😂 😮 😍 😢 👏 🔥
nownumber: pins "2h" in testsnow

StoryUser and StorySlide​

StoryUser: { id, name, avatar?, slides, seen?, verified? }. StorySlide: { id, image?, render?, duration? (5000), createdAt?, hasAudio?, alt? }.

  • Image viewer: a full-screen photo with zoom, free.
  • Swipe deck: Tinder's cards, the other half of a social app.
  • Avatar: avatars and their fallbacks, free.