From 7a800bee81b48ac2dabeeb950f238a0c9148440c Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Wed, 4 Aug 2021 16:12:13 +0500 Subject: [PATCH] discard nested flatlist in favour of sectioned list. --- ...icationStyles.js => notificationStyles.ts} | 0 ...tificationView.js => notificationView.tsx} | 47 +++++++++++-------- 2 files changed, 28 insertions(+), 19 deletions(-) rename src/components/notification/view/{notificationStyles.js => notificationStyles.ts} (100%) rename src/components/notification/view/{notificationView.js => notificationView.tsx} (85%) diff --git a/src/components/notification/view/notificationStyles.js b/src/components/notification/view/notificationStyles.ts similarity index 100% rename from src/components/notification/view/notificationStyles.js rename to src/components/notification/view/notificationStyles.ts diff --git a/src/components/notification/view/notificationView.js b/src/components/notification/view/notificationView.tsx similarity index 85% rename from src/components/notification/view/notificationView.js rename to src/components/notification/view/notificationView.tsx index d3965b622..6b3282784 100644 --- a/src/components/notification/view/notificationView.js +++ b/src/components/notification/view/notificationView.tsx @@ -1,6 +1,6 @@ /* eslint-disable react/jsx-wrap-multilines */ -import React, { PureComponent, Fragment } from 'react'; -import { View, FlatList, ActivityIndicator, RefreshControl, Text } from 'react-native'; +import React, { PureComponent } from 'react'; +import { View, FlatList, ActivityIndicator, RefreshControl, Text, SectionList } from 'react-native'; import { injectIntl } from 'react-intl'; // Constants @@ -95,41 +95,40 @@ class NotificationView extends PureComponent { title: intl.formatMessage({ id: 'notification.recent', }), - notifications: [], + data: [], }, { title: intl.formatMessage({ id: 'notification.yesterday', }), - notifications: [], + data: [], }, { title: intl.formatMessage({ id: 'notification.this_week', }), - notifications: [], + data: [], }, { title: intl.formatMessage({ id: 'notification.this_month', }), - notifications: [], + data: [], }, { title: intl.formatMessage({ id: 'notification.older_then', }), - notifications: [], + data: [], }, ]; notifications.forEach((item) => { const listIndex = this._getTimeListIndex(item.timestamp); - - notificationArray[listIndex].notifications.push(item); + notificationArray[listIndex].data.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) => { @@ -152,18 +151,26 @@ class NotificationView extends PureComponent { return 4; }; + _getActivityIndicator = () => ( ); - _renderItem = ({ item, index }) => ( - - - {this._renderList(item.notifications)} - - ); + + _renderSectionHeader = ({ section: { title, index} }) => ( + + ) + + + _renderItem = ({ item }) => ( + + ) + render() { const { readAllNotification, getActivities, isNotificationRefreshing, intl } = this.props; @@ -187,13 +194,14 @@ class NotificationView extends PureComponent { {({ isDarkTheme }) => _notifications && _notifications.length > 0 ? ( - item.title} + item.title + index} onEndReached={() => getActivities(selectedFilter, true)} ListFooterComponent={this._renderFooterLoading} ListEmptyComponent={} contentContainerStyle={styles.listContentContainer} + stickySectionHeadersEnabled={false} refreshControl={ } renderItem={this._renderItem} + renderSectionHeader={this._renderSectionHeader} /> ) : (