diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index 3f94ea2ef..b6da7fcb7 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -1,5 +1,5 @@ /* eslint-disable react/jsx-wrap-multilines */ -import React, { useState, useEffect, useCallback } from 'react'; +import React, { useState, useEffect, useCallback, useRef } from 'react'; import { FlatList, View, ActivityIndicator, RefreshControl } from 'react-native'; import { useIntl } from 'react-intl'; import { withNavigation } from 'react-navigation'; @@ -53,6 +53,7 @@ const PostsView = ({ filterOptionsValue && filterOptionsValue[selectedFilterIndex], ); const intl = useIntl(); + const postsList = useRef(null); useEffect(() => { if (isConnected) { @@ -114,14 +115,19 @@ const PostsView = ({ ]); const _handleOnDropdownSelect = async index => { - if (filterOptions && filterOptions.length > 0) { - await setSelectedFilterValue(filterOptionsValue[index]); + if (index === selectedFilterIndex) { + _scrollTop(); + } else { + if (filterOptions && filterOptions.length > 0) { + await setSelectedFilterValue(filterOptionsValue[index]); + } + + setSelectedFilterIndex(index); + setPosts([]); + setStartPermlink(''); + setStartAuthor(''); + setIsNoPost(false); } - setSelectedFilterIndex(index); - setPosts([]); - setStartPermlink(''); - setStartAuthor(''); - setIsNoPost(false); }; const _getPromotePosts = useCallback(async () => { @@ -315,6 +321,10 @@ const PostsView = ({ } }; + const _scrollTop = () => { + postsList.current.scrollToOffset({ x: 0, y: 0, animated: true }); + }; + return ( {({ isDarkTheme }) => ( @@ -335,6 +345,7 @@ const PostsView = ({ )} {