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

83 navigate back to a user with multiple stories #84

Merged
merged 2 commits into from
Jun 24, 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
6 changes: 6 additions & 0 deletions src/components/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const StoryContent: FC<StoryContentProps> = ( { stories, active, activeStory } )

};

useAnimatedReaction(
() => active.value,
( res, prev ) => res !== prev && onChange(),
[ active.value, onChange ],
);

useAnimatedReaction(
() => activeStory.value,
( res, prev ) => res !== prev && onChange(),
Expand Down
6 changes: 6 additions & 0 deletions src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const StoryFooter: FC<StoryContentProps> = ( { stories, active, activeStory } )

};

useAnimatedReaction(
() => active.value,
( res, prev ) => res !== prev && onChange(),
[ active.value, onChange ],
);

useAnimatedReaction(
() => activeStory.value,
( res, prev ) => res !== prev && onChange(),
Expand Down
19 changes: 14 additions & 5 deletions src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
const durationValue = useSharedValue( duration );
const isLongPress = useSharedValue( false );
const hideElements = useSharedValue( false );
const lastViewed = useSharedValue<{ [key: string]:number }>( {} );

const userIndex = useDerivedValue( () => Math.round( x.value / WIDTH ) );
const storyIndex = useDerivedValue( () => stories[userIndex.value]?.stories.findIndex(
Expand Down Expand Up @@ -63,6 +64,7 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {
{ duration: modalAnimationDuration },
() => runOnJS( setVisible )( false ),
);
lastViewed.value = {};
cancelAnimation( animation );

};
Expand Down Expand Up @@ -103,6 +105,12 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {

}

if ( userId.value !== undefined && storyIndex.value! >= 0 ) {

lastViewed.value = { ...lastViewed.value, [userId.value]: storyIndex.value ?? 0 };

}

}

animation.value = withTiming( 1, { duration: newDuration } );
Expand Down Expand Up @@ -137,12 +145,13 @@ const StoryModal = forwardRef<StoryModalPublicMethods, StoryModalProps>( ( {

}

const newStoryIndex = stories[newUserIndex]?.stories.findIndex(
( story ) => story.id === seenStories.value[id],
);
const newStoryIndex = lastViewed.value[id] !== undefined
? lastViewed.value[id]!
: ( ( stories[newUserIndex]?.stories.findIndex(
( story ) => story.id === seenStories.value[id],
) ?? 0 ) + 1 );
const userStories = stories[newUserIndex]?.stories;
const newStory = newStoryIndex !== undefined
? userStories?.[newStoryIndex + 1]?.id ?? userStories?.[0]?.id : undefined;
const newStory = userStories?.[newStoryIndex]?.id ?? userStories?.[0]?.id;
currentStory.value = newStory;

if ( onStoryStart ) {
Expand Down
Loading