blob: 493412e7b4bc19dc3792b831a329d193564b4e1d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import React from 'react'
import {observer} from 'mobx-react-lite'
import {Text, View, FlatList} from 'react-native'
import {
NotificationsViewModel,
NotificationsViewItemModel,
} from '../../../state/models/notifications-view'
import {FeedItem} from './FeedItem'
export const Feed = observer(function Feed({
view,
}: {
view: NotificationsViewModel
}) {
// TODO optimize renderItem or FeedItem, we're getting this notice from RN: -prf
// VirtualizedList: You have a large list that is slow to update - make sure your
// renderItem function renders components that follow React performance best practices
// like PureComponent, shouldComponentUpdate, etc
const renderItem = ({item}: {item: NotificationsViewItemModel}) => (
<FeedItem item={item} />
)
const onRefresh = () => {
view.refresh().catch(err => console.error('Failed to refresh', err))
}
const onEndReached = () => {
view.loadMore().catch(err => console.error('Failed to load more', err))
}
return (
<View>
{view.isLoading && !view.isRefreshing && !view.hasContent && (
<Text>Loading...</Text>
)}
{view.hasError && <Text>{view.error}</Text>}
{view.hasContent && (
<FlatList
data={view.notifications}
keyExtractor={item => item._reactKey}
renderItem={renderItem}
refreshing={view.isRefreshing}
onRefresh={onRefresh}
onEndReached={onEndReached}
/>
)}
{view.isEmpty && <Text>This feed is empty!</Text>}
</View>
)
})
|