Skip to content

Commit c23bc65

Browse files
committed
feat: separate all footer sections into own components
1 parent 15a81ca commit c23bc65

File tree

5 files changed

+92
-49
lines changed

5 files changed

+92
-49
lines changed

src/CuteChat.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function CuteChat(props: CuteChatProps) {
5959
const memoizedUser = useMemo(() => ({ _id: user.id, ...user }), [user]);
6060
const startDate = useMemo(() => new Date(), []);
6161

62-
const chatRef = useRef<FlatList<IMessage>>(null);
62+
const chatListRef = useRef<FlatList<IMessage>>(null);
6363

6464
const setIsLoadingBool = useCallback(
6565
(isLoading: boolean) => {
@@ -311,7 +311,7 @@ export function CuteChat(props: CuteChatProps) {
311311
scrollToBottomComponent={props.scrollToBottomComponent}
312312
scrollToBottomStyle={props.scrollToBottomStyle}
313313
closeToTop={closeToTop}
314-
chatRef={chatRef}
314+
chatRef={chatListRef}
315315
/>
316316
{props.renderChatFooter?.()}
317317
</>
@@ -321,7 +321,7 @@ export function CuteChat(props: CuteChatProps) {
321321
user={memoizedUser}
322322
inverted={true}
323323
listViewProps={{
324-
ref: chatRef,
324+
ref: chatListRef,
325325
onScroll: ({ nativeEvent }: { nativeEvent: NativeScrollEvent }) => {
326326
if (isCloseToBottom(nativeEvent)) fetchMoreMessages();
327327

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import { ReactNode, RefObject } from 'react';
2-
import {
3-
FlatList,
4-
StyleProp,
5-
TouchableOpacity,
6-
View,
7-
ViewStyle,
8-
} from 'react-native';
1+
import React, { ReactNode, RefObject } from 'react';
2+
import { FlatList, StyleProp, View, ViewStyle } from 'react-native';
93
import { IMessage } from 'react-native-gifted-chat';
4+
import { RightSection } from './RightSection';
5+
import { MiddleSection } from './MiddleSection';
6+
import { LeftSection } from './LeftSection';
107

118
export const ChatFooter = (props: {
129
newMessagesBannerComponent?: () => ReactNode;
@@ -28,48 +25,26 @@ export const ChatFooter = (props: {
2825
position: 'absolute',
2926
flexDirection: 'row',
3027
justifyContent: 'flex-start',
31-
backgroundColor: 'rgba(255, 255, 255, 0.8)',
3228
width: '100%',
33-
height: 100,
34-
bottom: 0,
29+
bottom: 40,
3530
left: 0,
3631
}}
3732
>
38-
<View style={{ display: 'flex', flex: 1 }}></View>
39-
<View style={{ display: 'flex', flex: 1 }}>
40-
{!props.closeToTop && props.newMessagesBannerComponent && (
41-
<TouchableOpacity
42-
onPress={scrollToBottom}
43-
style={
44-
props.newMessagesBannerStyles ?? {
45-
alignSelf: 'center',
46-
backgroundColor: 'rgba(255, 255, 255, 0.8)',
47-
padding: 10,
48-
borderRadius: 100,
49-
}
50-
}
51-
>
52-
{props.newMessagesBannerComponent()}
53-
</TouchableOpacity>
54-
)}
55-
</View>
56-
<View style={{ display: 'flex', flex: 1 }}>
57-
{!props.closeToTop && props.scrollToBottomComponent && (
58-
<TouchableOpacity
59-
onPress={scrollToBottom}
60-
style={
61-
props.scrollToBottomStyle ?? {
62-
alignSelf: 'flex-end',
63-
backgroundColor: 'rgba(255, 255, 255, 0.8)',
64-
padding: 10,
65-
borderRadius: 100,
66-
}
67-
}
68-
>
69-
{props.scrollToBottomComponent()}
70-
</TouchableOpacity>
71-
)}
72-
</View>
33+
<LeftSection />
34+
35+
<MiddleSection
36+
newMessagesBannerComponent={props.newMessagesBannerComponent}
37+
newMessagesBannerStyles={props.newMessagesBannerStyles}
38+
onNewMessagesBannerPress={scrollToBottom}
39+
closeToTop={props.closeToTop}
40+
/>
41+
42+
<RightSection
43+
scrollToBottom={scrollToBottom}
44+
scrollToBottomComponent={props.scrollToBottomComponent}
45+
scrollToBottomStyle={props.scrollToBottomStyle}
46+
closeToTop={props.closeToTop}
47+
/>
7348
</View>
7449
);
7550
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { View } from 'react-native';
2+
3+
export const LeftSection = () => {
4+
return <View style={{ display: 'flex', flex: 1 }}></View>;
5+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { ReactNode } from 'react';
2+
import { StyleProp, TouchableOpacity, View, ViewStyle } from 'react-native';
3+
4+
type Props = {
5+
newMessagesBannerComponent?: () => ReactNode;
6+
newMessagesBannerStyles?: StyleProp<ViewStyle>;
7+
onNewMessagesBannerPress?: () => void;
8+
9+
closeToTop: boolean;
10+
};
11+
12+
export const MiddleSection = (props: Props) => {
13+
return (
14+
<View style={{ display: 'flex', flex: 1 }}>
15+
{!props.closeToTop && props.newMessagesBannerComponent && (
16+
<TouchableOpacity
17+
onPress={props.onNewMessagesBannerPress}
18+
style={
19+
props.newMessagesBannerStyles ?? {
20+
alignSelf: 'center',
21+
backgroundColor: 'rgba(255, 255, 255, 0.9)',
22+
padding: 10,
23+
borderRadius: 100,
24+
}
25+
}
26+
>
27+
{props.newMessagesBannerComponent()}
28+
</TouchableOpacity>
29+
)}
30+
</View>
31+
);
32+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { ReactNode } from 'react';
2+
import { StyleProp, TouchableOpacity, View, ViewStyle } from 'react-native';
3+
4+
type Props = {
5+
scrollToBottomComponent?: () => ReactNode;
6+
scrollToBottomStyle?: StyleProp<ViewStyle>;
7+
scrollToBottom?: () => void;
8+
closeToTop: boolean;
9+
};
10+
11+
export const RightSection = (props: Props) => {
12+
return (
13+
<View style={{ display: 'flex', flex: 1 }}>
14+
{!props.closeToTop && props.scrollToBottomComponent && (
15+
<TouchableOpacity
16+
onPress={props.scrollToBottom}
17+
style={
18+
props.scrollToBottomStyle ?? {
19+
alignSelf: 'flex-end',
20+
backgroundColor: 'rgba(255, 255, 255, 0.9)',
21+
padding: 10,
22+
borderRadius: 100,
23+
}
24+
}
25+
>
26+
{props.scrollToBottomComponent()}
27+
</TouchableOpacity>
28+
)}
29+
</View>
30+
);
31+
};

0 commit comments

Comments
 (0)