React Native Advanced Stories
An elegant, performant, and customizable stories component for React Native applications.
Features
- 🖼️ Support for both images and videos
- 🔍 Pause functionality with long press
- 👆 Swipe gestures and touch controls
- 🔄 Progress bar for multiple story items
- 📱 Fully customizable stories
- ⬆️ Swipe up interaction support
- User avatar and username display
- 🔄 Smooth transitions between stories
- TypeScript support
Installation
npm install react-native-advanced-stories react-native-video
# or
yarn add react-native-advanced-stories react-native-video
iOS
cd ios && pod install
Basic Usage
import React, {useState} from 'react';
import {View, TouchableOpacity, Image} from 'react-native';
import {StoryList} from 'react-native-advanced-stories';
const App = () => {
const [modalVisible, setModalVisible] = useState(false);
const [storyIndex, setStoryIndex] = useState(0);
const stories = [
{
key: '1',
user_name: 'John Doe',
user_image: 'https://example.com/avatar1.jpg',
data: [
{
key: '1-1',
type: 'image',
source: 'https://example.com/story1.jpg',
},
{
key: '1-2',
type: 'video',
source: 'https://example.com/story2.mp4',
},
],
},
// More stories...
];
const openStory = index => {
setStoryIndex(index);
setModalVisible(true);
};
return (
<View style={{flex: 1}}>
{/* Story avatars */}
<View style={{flexDirection: 'row', padding: 10}}>
{stories.map((story, index) => (
<TouchableOpacity
key={story.key}
onPress={() => openStory(index)}
style={{marginRight: 12}}>
<Image
source={{uri: story.user_image}}
style={{width: 60, height: 60, borderRadius: 30}}
/>
</TouchableOpacity>
))}
</View>
{/* Story viewer */}
{modalVisible && (
<StoryList
slides={stories}
indexOpen={storyIndex}
closeStory={() => setModalVisible(false)}
imageDuration={5000}
onStorySeen={story => console.log('Story seen:', story)}
onPressAvatar={user => console.log('Avatar pressed:', user)}
/>
)}
</View>
);
};
export default App;
Props
StoryList Props
Prop | Type | Description | Default |
---|
slides | StoryItem[] | Array of story data | Required |
indexOpen | number | Initial story index to show | 0 |
closeStory | function | Function to close story viewer | Required |
onStorySeen | function | Callback when a story is seen | () => {} |
imageDuration | number | Duration for image stories (ms) | 4000 |
userContainer | ViewStyle | Style for user info container | {} |
userAvatarStyle | ImageStyle | Style for user avatar | {} |
userTextStyle | TextStyle | Style for username text | {} |
onPressAvatar | function | Callback when avatar is pressed | () => {} |
renderSwipeUpComponent | function | Component to render on swipe up | () => null |