-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathInverted.tsx
More file actions
130 lines (120 loc) · 3.54 KB
/
Inverted.tsx
File metadata and controls
130 lines (120 loc) · 3.54 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { randParagraph, randUuid } from '@ngneat/falso';
import { BlurView } from 'expo-blur';
import { StatusBar } from 'expo-status-bar';
import {
Header,
ScrollHeaderProps,
SurfaceComponentProps,
FlashListWithHeaders,
} from '@codeherence/react-native-header';
import { Avatar, BackButton } from '../../components';
import { RANDOM_IMAGE_NUM } from '../../constants';
import { range } from '../../utils';
import type { InvertedUsageScreenNavigationProps } from '../../navigation';
const HeaderSurface: React.FC<SurfaceComponentProps> = () => {
return <BlurView style={StyleSheet.absoluteFill} tint="systemChromeMaterialDark" />;
};
const HeaderComponent: React.FC<ScrollHeaderProps> = ({ showNavBar }) => {
const navigation = useNavigation();
const onPressProfile = () => navigation.navigate('Profile');
return (
<Header
showNavBar={showNavBar}
noBottomBorder
headerCenterFadesIn={false}
headerCenter={
<Text style={styles.navBarTitle} numberOfLines={1}>
Elon Musk
</Text>
}
headerRight={
<TouchableOpacity onPress={onPressProfile}>
<Avatar size="sm" source={{ uri: `https://i.pravatar.cc/128?img=${RANDOM_IMAGE_NUM}` }} />
</TouchableOpacity>
}
headerLeft={<BackButton color="white" />}
SurfaceComponent={HeaderSurface}
/>
);
};
interface ChatMessage {
id: string;
message: string;
type: 'sent' | 'received';
}
const data: ChatMessage[] = range({ end: 100 }).map((i) => {
const id = randUuid();
const message = randParagraph();
const type = i % 2 === 0 ? 'sent' : 'received';
return { id, message, type };
});
const ChatMessage: React.FC<ChatMessage> = ({ message, type }) => {
return (
<View style={type === 'sent' ? styles.sentMessageContainer : styles.receivedMessageContainer}>
<Text style={styles.messageText}>{message}</Text>
</View>
);
};
const Inverted: React.FC<InvertedUsageScreenNavigationProps> = () => {
return (
<>
<StatusBar style="light" />
<FlashListWithHeaders
data={data}
renderItem={({ item }) => <ChatMessage {...item} />}
HeaderComponent={HeaderComponent}
keyExtractor={(item) => item.id}
// inverted
absoluteHeader
containerStyle={styles.container}
maintainVisibleContentPosition={{
startRenderingFromBottom: true,
}}
automaticallyAdjustsScrollIndicatorInsets={false}
// eslint-disable-next-line react-native/no-inline-styles
contentContainerStyle={{ paddingHorizontal: 12 }}
showsVerticalScrollIndicator
indicatorStyle={'white'}
/>
</>
);
};
export default Inverted;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'black',
},
contentContainer: {
backgroundColor: 'black',
paddingHorizontal: 12,
},
navBarTitle: { fontSize: 16, fontWeight: 'bold', color: 'white' },
messageText: {
color: 'white',
},
sentMessageContainer: {
backgroundColor: '#186BE7',
alignSelf: 'flex-start',
borderRadius: 12,
maxWidth: '75%',
padding: 12,
marginVertical: 12,
},
receivedMessageContainer: {
backgroundColor: '#1F2329',
alignItems: 'flex-end',
justifyContent: 'flex-end',
alignSelf: 'flex-end',
borderRadius: 12,
maxWidth: '75%',
padding: 12,
marginVertical: 12,
},
separator: {
height: 24,
},
});