Skip to content

Commit ae616d6

Browse files
committed
feat: scroll to top on bottom tab press
1 parent b4c6bc3 commit ae616d6

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

examples/SampleApp/src/components/BottomTabs.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export const BottomTabs: React.FC<BottomTabBarProps> = (props) => {
8080
const isFocused = state.index === index;
8181

8282
const onPress = () => {
83+
navigation.emit({
84+
target: route.key,
85+
type: 'tabPress',
86+
canPreventDefault: true,
87+
});
8388
if (!isFocused) {
8489
navigation.navigate(route.name);
8590
}

examples/SampleApp/src/components/MessageSearch/MessageSearchList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export type MessageSearchListProps = {
7272
refreshing: boolean;
7373
refreshList: () => void;
7474
showResultCount?: boolean;
75-
scrollRef?: React.Ref<FlatList>;
75+
scrollRef: React.Ref<FlatList<any>>;
7676
};
7777
export const MessageSearchList: React.FC<MessageSearchListProps> = ({
7878
EmptySearchIndicator,

examples/SampleApp/src/screens/ChannelListScreen.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useContext, useMemo, useRef, useState } from 'react';
2-
import { StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
2+
import { FlatList, StyleSheet, Text, TextInput, TouchableOpacity, View } from 'react-native';
33
import { useNavigation, useScrollToTop } from '@react-navigation/native';
44
import { ChannelList, CircleClose, Search, useTheme } from 'stream-chat-react-native';
55

@@ -76,7 +76,7 @@ export const ChannelListScreen: React.FC = () => {
7676
} = useTheme();
7777

7878
const searchInputRef = useRef<TextInput | null>(null);
79-
const scrollRef = useRef(null);
79+
const scrollRef = useRef<FlatList<any>>(null);
8080

8181
const [searchInputText, setSearchInputText] = useState('');
8282
const [searchQuery, setSearchQuery] = useState('');
@@ -108,6 +108,10 @@ export const ChannelListScreen: React.FC = () => {
108108

109109
if (!chatClient) return null;
110110

111+
const setScrollRef = (ref: React.RefObject<FlatList<any>>) => {
112+
scrollRef.current = ref;
113+
};
114+
111115
return (
112116
<View
113117
style={[
@@ -205,7 +209,7 @@ export const ChannelListScreen: React.FC = () => {
205209
options={options}
206210
Preview={ChannelPreview}
207211
sort={sort}
208-
setFlatListRef={(ref) => (scrollRef.current = ref)}
212+
setFlatListRef={setScrollRef}
209213
/>
210214
</View>
211215
</View>

examples/SampleApp/src/screens/MentionsScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const MentionsScreen: React.FC<MentionsScreenProps> = () => {
6262
[chatClient],
6363
);
6464

65-
const scrollRef = useRef<FlatList>(null);
65+
const scrollRef = useRef<FlatList<any>>(null);
6666

6767
useScrollToTop(scrollRef);
6868

0 commit comments

Comments
 (0)