mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-19 19:31:54 +03:00
discard nested flatlist in favour of sectioned list.
This commit is contained in:
parent
698c7c5b07
commit
7a800bee81
@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable react/jsx-wrap-multilines */
|
/* eslint-disable react/jsx-wrap-multilines */
|
||||||
import React, { PureComponent, Fragment } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import { View, FlatList, ActivityIndicator, RefreshControl, Text } from 'react-native';
|
import { View, FlatList, ActivityIndicator, RefreshControl, Text, SectionList } from 'react-native';
|
||||||
import { injectIntl } from 'react-intl';
|
import { injectIntl } from 'react-intl';
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
@ -95,41 +95,40 @@ class NotificationView extends PureComponent {
|
|||||||
title: intl.formatMessage({
|
title: intl.formatMessage({
|
||||||
id: 'notification.recent',
|
id: 'notification.recent',
|
||||||
}),
|
}),
|
||||||
notifications: [],
|
data: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({
|
title: intl.formatMessage({
|
||||||
id: 'notification.yesterday',
|
id: 'notification.yesterday',
|
||||||
}),
|
}),
|
||||||
notifications: [],
|
data: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({
|
title: intl.formatMessage({
|
||||||
id: 'notification.this_week',
|
id: 'notification.this_week',
|
||||||
}),
|
}),
|
||||||
notifications: [],
|
data: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({
|
title: intl.formatMessage({
|
||||||
id: 'notification.this_month',
|
id: 'notification.this_month',
|
||||||
}),
|
}),
|
||||||
notifications: [],
|
data: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: intl.formatMessage({
|
title: intl.formatMessage({
|
||||||
id: 'notification.older_then',
|
id: 'notification.older_then',
|
||||||
}),
|
}),
|
||||||
notifications: [],
|
data: [],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
notifications.forEach((item) => {
|
notifications.forEach((item) => {
|
||||||
const listIndex = this._getTimeListIndex(item.timestamp);
|
const listIndex = this._getTimeListIndex(item.timestamp);
|
||||||
|
notificationArray[listIndex].data.push(item);
|
||||||
notificationArray[listIndex].notifications.push(item);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return notificationArray.filter((item) => item.notifications.length > 0);
|
return notificationArray.filter((item) => item.data.length > 0).map((item, index)=>{item.index = index; return item});
|
||||||
};
|
};
|
||||||
|
|
||||||
_getTimeListIndex = (timestamp) => {
|
_getTimeListIndex = (timestamp) => {
|
||||||
@ -152,18 +151,26 @@ class NotificationView extends PureComponent {
|
|||||||
return 4;
|
return 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
_getActivityIndicator = () => (
|
_getActivityIndicator = () => (
|
||||||
<View style={styles.loading}>
|
<View style={styles.loading}>
|
||||||
<ActivityIndicator animating size="large" />
|
<ActivityIndicator animating size="large" />
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
_renderItem = ({ item, index }) => (
|
|
||||||
<Fragment>
|
_renderSectionHeader = ({ section: { title, index} }) => (
|
||||||
<ContainerHeader hasSeperator={index !== 0} isBoldTitle title={item.title} key={item.title} />
|
<ContainerHeader hasSeperator={index !== 0} isBoldTitle title={title} key={title} />
|
||||||
{this._renderList(item.notifications)}
|
)
|
||||||
</Fragment>
|
|
||||||
);
|
|
||||||
|
_renderItem = ({ item }) => (
|
||||||
|
<NotificationLine
|
||||||
|
notification={item}
|
||||||
|
handleOnPressNotification={this.props.navigateToNotificationRoute}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { readAllNotification, getActivities, isNotificationRefreshing, intl } = this.props;
|
const { readAllNotification, getActivities, isNotificationRefreshing, intl } = this.props;
|
||||||
@ -187,13 +194,14 @@ class NotificationView extends PureComponent {
|
|||||||
<ThemeContainer>
|
<ThemeContainer>
|
||||||
{({ isDarkTheme }) =>
|
{({ isDarkTheme }) =>
|
||||||
_notifications && _notifications.length > 0 ? (
|
_notifications && _notifications.length > 0 ? (
|
||||||
<FlatList
|
<SectionList
|
||||||
data={_notifications}
|
sections={_notifications}
|
||||||
keyExtractor={(item) => item.title}
|
keyExtractor={(item, index) => item.title + index}
|
||||||
onEndReached={() => getActivities(selectedFilter, true)}
|
onEndReached={() => getActivities(selectedFilter, true)}
|
||||||
ListFooterComponent={this._renderFooterLoading}
|
ListFooterComponent={this._renderFooterLoading}
|
||||||
ListEmptyComponent={<ListPlaceHolder />}
|
ListEmptyComponent={<ListPlaceHolder />}
|
||||||
contentContainerStyle={styles.listContentContainer}
|
contentContainerStyle={styles.listContentContainer}
|
||||||
|
stickySectionHeadersEnabled={false}
|
||||||
refreshControl={
|
refreshControl={
|
||||||
<RefreshControl
|
<RefreshControl
|
||||||
refreshing={isNotificationRefreshing}
|
refreshing={isNotificationRefreshing}
|
||||||
@ -205,6 +213,7 @@ class NotificationView extends PureComponent {
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
renderItem={this._renderItem}
|
renderItem={this._renderItem}
|
||||||
|
renderSectionHeader={this._renderSectionHeader}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Text style={globalStyles.hintText}>
|
<Text style={globalStyles.hintText}>
|
Loading…
Reference in New Issue
Block a user