mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-30 00:52:42 +03:00
add scroll to top if same filter is selected
This commit is contained in:
parent
e7ee917132
commit
7f3ad510c7
@ -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 (index === selectedFilterIndex) {
|
||||
_scrollTop();
|
||||
} else {
|
||||
if (filterOptions && filterOptions.length > 0) {
|
||||
await setSelectedFilterValue(filterOptionsValue[index]);
|
||||
}
|
||||
|
||||
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 (
|
||||
<ThemeContainer>
|
||||
{({ isDarkTheme }) => (
|
||||
@ -335,6 +345,7 @@ const PostsView = ({
|
||||
)}
|
||||
|
||||
<FlatList
|
||||
ref={postsList}
|
||||
data={posts}
|
||||
showsVerticalScrollIndicator={false}
|
||||
renderItem={({ item, index }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user