Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: loopingStories property #100

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default YourComponent;
`progressContainerStyle` | ViewStyle | | Additional styles for the story progress container
`hideAvatarList` | boolean | false | A boolean indicating whether to hide avatar scroll list
`hideElementsOnLongPress` | boolean | false | A boolean indicating whether to hide all elements when story is paused by long press
`loopingStories` | `'none'` | `'onlyLast'` | `'all'` | `'none'` | A string indicating whether to continue stories after last story was shown. If set to `'none'` modal will be closed after all stories were played, if set to `'onlyLast'` stories will loop on last user only after all stories were played. If set to `'all'` stories will play from beginning after all stories were played.
`footerComponent` | ReactNode | | A custom component, such as a floating element, that can be added to the modal.
`imageOverlayView` | ReactNode | | Image overlay compontent
`onShow` | ( id: string ) => void | | Callback when a story is shown.
Expand Down
13 changes: 11 additions & 2 deletions src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import ModalStyles from './Modal.styles';
const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
stories, seenStories, duration, videoDuration, storyAvatarSize, textStyle, containerStyle,
backgroundColor, videoProps, closeIconColor, modalAnimationDuration = STORY_ANIMATION_DURATION,
storyAnimationDuration = STORY_ANIMATION_DURATION, hideElementsOnLongPress,
storyAnimationDuration = STORY_ANIMATION_DURATION, hideElementsOnLongPress, loopingStories = 'none',
onLoad, onShow, onHide,
onSeenStoriesChange, onSwipeUp, onStoryStart, onStoryEnd, footerComponent, ...props
}, ref ) => {
Expand Down Expand Up @@ -122,6 +122,7 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
animated = true,
sameUser = false,
previousUser?: string,
index?: number,
) => {

'worklet';
Expand Down Expand Up @@ -151,7 +152,7 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
( story ) => story.id === seenStories.value[id],
) ?? 0 ) + 1 );
const userStories = stories[newUserIndex]?.stories;
const newStory = userStories?.[newStoryIndex]?.id ?? userStories?.[0]?.id;
const newStory = userStories?.[index ?? newStoryIndex]?.id ?? userStories?.[0]?.id;
currentStory.value = newStory;

if ( onStoryStart ) {
Expand All @@ -178,6 +179,14 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {

scrollTo( nextUserId.value );

} else if ( stories[0]?.id && loopingStories === 'all' ) {

scrollTo( stories[0].id, false );

} else if ( userId.value && loopingStories === 'onlyLast' ) {

scrollTo( userId.value, false, undefined, undefined, 0 );

} else {

onClose();
Expand Down
1 change: 1 addition & 0 deletions src/core/dto/componentsDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface StoryModalProps {
imageProps?: ImageProps;
footerComponent?: ReactNode;
hideElementsOnLongPress?: boolean;
loopingStories?: 'none' | 'all' | 'onlyLast';
onLoad: () => void;
onShow?: ( id: string ) => void;
onHide?: ( id: string ) => void;
Expand Down
1 change: 1 addition & 0 deletions src/core/dto/instagramStoriesDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface InstagramStoriesProps {
hideAvatarList?: boolean;
imageOverlayView?: ReactNode;
hideElementsOnLongPress?: boolean;
loopingStories?: 'none' | 'all' | 'onlyLast';
onShow?: ( id: string ) => void;
onHide?: ( id: string ) => void;
onSwipeUp?: ( userId?: string, storyId?: string ) => void;
Expand Down
Loading