diff --git a/native/chat/chat-thread-list.react.js b/native/chat/chat-thread-list.react.js --- a/native/chat/chat-thread-list.react.js +++ b/native/chat/chat-thread-list.react.js @@ -81,32 +81,8 @@ +emptyItem?: React.ComponentType<{}>, }; type SearchStatus = 'inactive' | 'activating' | 'active'; -type Props = { - ...BaseProps, - // Redux state - +searchText: string, - +searchStatus: SearchStatus, - +searchCancelButtonOpen: Value, - +chatThreadList: React.Node, -}; - -class ChatThreadList extends React.PureComponent { - flatList: ?FlatList; - - constructor(props: Props) { - super(props); - } - - render() { - return this.props.chatThreadList; - } - - flatListRef = (flatList: ?FlatList) => { - this.flatList = flatList; - }; -} -function ConnectedChatThreadList(props: BaseProps): React.Node { +function ChatThreadList(props: BaseProps): React.Node { const boundChatListData = useFlattenedChatListData(); const loggedInUserInfo = useLoggedInUserInfo(); const threadSearchIndex = useGlobalThreadSearchIndex(); @@ -177,6 +153,7 @@ ); const scrollPos = React.useRef(0); + const flatListRef = React.useRef(); const onScroll = React.useCallback( (event: ScrollEvent) => { @@ -221,7 +198,9 @@ }, [searchStatus]); const clearSearch = React.useCallback(() => { - // TODO (atul): Scroll to top of flatList (animated: false) + if (scrollPos.current > 0 && flatListRef.current) { + flatListRef.current.scrollToOffset({ offset: 0, animated: false }); + } setSearchStatus('inactive'); }, []); @@ -441,7 +420,6 @@ const viewerID = loggedInUserInfo?.id; const extraData = `${viewerID || ''} ${openedSwipeableID}`; - const flatListRef = React.useRef(); const chatThreadList = React.useMemo( () => ( @@ -548,18 +526,7 @@ } }, [isSearchActivating]); - return ( - - ); + return chatThreadList; } const unboundStyles = { @@ -603,4 +570,4 @@ }, }; -export default ConnectedChatThreadList; +export default ChatThreadList;