-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathStoryScreen.tsx
93 lines (86 loc) · 2.64 KB
/
StoryScreen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React, { useRef, useState } from 'react';
import {
Linking,
Modal,
SafeAreaView,
Text,
TouchableOpacity,
View
} from 'react-native';
import {
StoryAvatar,
StoryContainer,
StoryRef,
StoryType
} from 'react-native-story-view';
import { Footer, Header, Overlay } from '../../components';
import { stories } from '../../constants';
import styles from './styles';
const StoryScreen = () => {
const [isStoryViewVisible, setIsStoryViewShow] = useState<boolean>(false);
const ref = useRef<StoryRef>(null);
const index = 0;
const [userStories, setUserStories] = useState(
JSON.parse(JSON.stringify(stories[index]))
);
const viewedStories = useRef(
Array(userStories.stories.length)
.fill(userStories.stories)
.map((item, index) => item[index].isSeen ?? false)
);
const openStories = () => {
setIsStoryViewShow(true);
};
const closeStory = () => {
viewedStories.current = ref?.current?.viewedStories ?? [];
const clonedUserStories = { ...userStories };
clonedUserStories.stories.map((item: StoryType, index: number) => {
item.isSeen = viewedStories.current?.[index] ?? false;
});
setUserStories({ ...clonedUserStories });
setIsStoryViewShow(false);
};
const storyInitialIndex: number = viewedStories?.current?.findIndex(
(val: boolean) => !val
);
return (
<SafeAreaView style={styles.container}>
<View style={styles.storyAvatarContainer}>
<StoryAvatar
{...{
openStories,
index,
item: userStories,
viewedStories: [viewedStories.current]
}}
/>
</View>
<Modal
visible={isStoryViewVisible}
statusBarTranslucent={true}
onRequestClose={closeStory}>
<SafeAreaView style={styles.storyContainer}>
<StoryContainer
visible
ref={ref}
extended
progressIndex={storyInitialIndex < 0 ? 0 : storyInitialIndex}
stories={userStories.stories}
maxVideoDuration={10}
renderHeaderComponent={({ progressIndex }) => (
<Header userStories={userStories} onClosePress={closeStory} />
)}
renderFooterComponent={({ progressIndex, story }) => (
<Footer userStories={userStories} {...{ story, progressIndex }} />
)}
//Callback when status view completes
onComplete={closeStory}
overlayViewPostion={'top'}
renderOverlayView={(item: StoryType) => <Overlay item={item} />}
/>
</SafeAreaView>
</Modal>
</SafeAreaView>
);
};
export default StoryScreen;