From fe55bb7f1c546168726b958928b8b4e1d9afb1a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Fridmansk=C3=BD?= Date: Sat, 22 Jun 2024 11:01:31 +0200 Subject: [PATCH 1/2] fix: wrong content rendered --- src/components/Content/index.tsx | 6 ++++++ src/components/Footer/index.tsx | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/components/Content/index.tsx b/src/components/Content/index.tsx index 6cddf43..b68d367 100644 --- a/src/components/Content/index.tsx +++ b/src/components/Content/index.tsx @@ -23,6 +23,12 @@ const StoryContent: FC = ( { stories, active, activeStory } ) }; + useAnimatedReaction( + () => active.value, + ( res, prev ) => res !== prev && onChange(), + [ active.value, onChange ], + ); + useAnimatedReaction( () => activeStory.value, ( res, prev ) => res !== prev && onChange(), diff --git a/src/components/Footer/index.tsx b/src/components/Footer/index.tsx index 85c6444..4b1aa97 100644 --- a/src/components/Footer/index.tsx +++ b/src/components/Footer/index.tsx @@ -23,6 +23,12 @@ const StoryFooter: FC = ( { stories, active, activeStory } ) }; + useAnimatedReaction( + () => active.value, + ( res, prev ) => res !== prev && onChange(), + [ active.value, onChange ], + ); + useAnimatedReaction( () => activeStory.value, ( res, prev ) => res !== prev && onChange(), From 8e9a1e62e85cb1d54af63989bc0261ab1419aeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Fridmansk=C3=BD?= Date: Sat, 22 Jun 2024 11:37:54 +0200 Subject: [PATCH 2/2] feat: continue on last viewed story when scrolling between users --- src/components/Modal/index.tsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/Modal/index.tsx b/src/components/Modal/index.tsx index 0a4338c..b09b836 100644 --- a/src/components/Modal/index.tsx +++ b/src/components/Modal/index.tsx @@ -33,6 +33,7 @@ const StoryModal = forwardRef( ( { 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( @@ -63,6 +64,7 @@ const StoryModal = forwardRef( ( { { duration: modalAnimationDuration }, () => runOnJS( setVisible )( false ), ); + lastViewed.value = {}; cancelAnimation( animation ); }; @@ -103,6 +105,12 @@ const StoryModal = forwardRef( ( { } + if ( userId.value !== undefined && storyIndex.value! >= 0 ) { + + lastViewed.value = { ...lastViewed.value, [userId.value]: storyIndex.value ?? 0 }; + + } + } animation.value = withTiming( 1, { duration: newDuration } ); @@ -137,12 +145,13 @@ const StoryModal = forwardRef( ( { } - 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 ) {