diff --git a/src/components/Image/index.tsx b/src/components/Image/index.tsx index 0894c24..db59749 100644 --- a/src/components/Image/index.tsx +++ b/src/components/Image/index.tsx @@ -14,7 +14,7 @@ const StoryImage: FC = ( { onImageLayout, onLoad, } ) => { - const [ data, setData ] = useState<{ uri: string, isVideo?: boolean }>( + const [ data, setData ] = useState<{ uri: string | undefined, isVideo?: boolean }>( { uri: defaultImage, isVideo: isDefaultVideo }, ); diff --git a/src/components/InstagramStories/index.tsx b/src/components/InstagramStories/index.tsx index e2680ca..489e35a 100644 --- a/src/components/InstagramStories/index.tsx +++ b/src/components/InstagramStories/index.tsx @@ -76,6 +76,12 @@ const InstagramStories = forwardRef = ( { ( ( { const userId = useDerivedValue( () => stories[userIndex.value]?.id ); const previousUserId = useDerivedValue( () => stories[userIndex.value - 1]?.id ); const nextUserId = useDerivedValue( () => stories[userIndex.value + 1]?.id ); - const previousStory = useDerivedValue( - () => stories[userIndex.value]?.stories[storyIndex.value - 1]?.id, - ); - const nextStory = useDerivedValue( - () => stories[userIndex.value]?.stories[storyIndex.value + 1]?.id, - ); + const previousStory = useDerivedValue( () => ( storyIndex.value !== undefined + ? stories[userIndex.value]?.stories[storyIndex.value - 1]?.id + : undefined ) ); + const nextStory = useDerivedValue( () => ( storyIndex.value !== undefined + ? stories[userIndex.value]?.stories[storyIndex.value + 1]?.id + : undefined ) ); const animatedStyles = useAnimatedStyle( () => ( { top: y.value } ) ); const backgroundAnimatedStyles = useAnimatedStyle( () => ( { @@ -91,7 +91,12 @@ const StoryModal = forwardRef( ( { } else { animation.value = 0; - runOnJS( onSeenStoriesChange )( userId.value, currentStory.value ); + + if ( userId.value !== undefined && currentStory.value !== undefined ) { + + runOnJS( onSeenStoriesChange )( userId.value, currentStory.value ); + + } } @@ -111,7 +116,8 @@ const StoryModal = forwardRef( ( { ( story ) => story.id === seenStories.value[id], ); const userStories = stories[newUserIndex]?.stories; - currentStory.value = userStories[newStoryIndex + 1]?.id ?? userStories[0]?.id; + currentStory.value = newStoryIndex !== undefined + ? userStories?.[newStoryIndex + 1]?.id ?? userStories?.[0]?.id : undefined; }; @@ -236,7 +242,11 @@ const StoryModal = forwardRef( ( { } const newUserId = stories[Math.round( newX / WIDTH )]?.id; - scrollTo( newUserId ); + if ( newUserId !== undefined ) { + + scrollTo( newUserId ); + + } } else if ( ctx.pressedAt + LONG_PRESS_DURATION < Date.now() ) { @@ -266,12 +276,16 @@ const StoryModal = forwardRef( ( { if ( visible ) { - onShow?.( currentStory.value ); + if ( currentStory.value !== undefined ) { + + onShow?.( currentStory.value ); + + } onLoad?.(); y.value = withTiming( 0, ANIMATION_CONFIG ); - } else { + } else if ( currentStory.value !== undefined ) { onHide?.( currentStory.value ); diff --git a/src/core/dto/componentsDTO.ts b/src/core/dto/componentsDTO.ts index a047023..3a102c2 100644 --- a/src/core/dto/componentsDTO.ts +++ b/src/core/dto/componentsDTO.ts @@ -58,8 +58,8 @@ export interface AnimationProps { export interface StoryImageProps { stories: InstagramStoryProps['stories']; - activeStory: SharedValue; - defaultImage: string; + activeStory: SharedValue; + defaultImage: string | undefined; isDefaultVideo: boolean; paused: SharedValue; videoProps?: any; @@ -97,14 +97,14 @@ export interface IconProps { export interface StoryContentProps { stories: InstagramStoryProps['stories']; active: SharedValue; - activeStory: SharedValue; + activeStory: SharedValue; } export interface StoryListProps extends InstagramStoryProps, StoryHeaderProps { index: number; x: SharedValue; - activeUser: SharedValue; - activeStory: SharedValue; + activeUser: SharedValue; + activeStory: SharedValue; progress: SharedValue; seenStories: SharedValue; paused: SharedValue; diff --git a/tsconfig.json b/tsconfig.json index 6984bce..3565a31 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "skipLibCheck": false, - "resolveJsonModule": true + "resolveJsonModule": true, + "noUncheckedIndexedAccess": true }, "include": [ "src/**/*.ts", @@ -41,4 +42,4 @@ "jest.config.js", "commitlint.config.js", ] -} \ No newline at end of file +}