2021-01-14 00:43:35 +01:00
|
|
|
import { HeaderCenter } from '@components/Header'
|
2021-02-08 23:47:20 +01:00
|
|
|
import Timeline from '@components/Timeline'
|
2021-02-27 16:33:54 +01:00
|
|
|
import TimelineNotifications from '@components/Timeline/Notifications'
|
2021-01-30 01:29:15 +01:00
|
|
|
import sharedScreens from '@screens/Tabs/Shared/sharedScreens'
|
2021-02-27 16:33:54 +01:00
|
|
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
2021-02-20 19:12:44 +01:00
|
|
|
import { updateInstanceNotification } from '@utils/slices/instancesSlice'
|
2021-02-08 23:19:55 +01:00
|
|
|
import React, { useCallback, useMemo } from 'react'
|
2020-11-29 13:11:23 +01:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2021-02-08 23:19:55 +01:00
|
|
|
import { Platform, ViewToken } from 'react-native'
|
2021-01-07 19:13:09 +01:00
|
|
|
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
|
2021-02-08 23:19:55 +01:00
|
|
|
import { useDispatch } from 'react-redux'
|
2020-10-24 18:07:09 +02:00
|
|
|
|
2021-01-30 01:29:15 +01:00
|
|
|
const Stack = createNativeStackNavigator<Nav.TabNotificationsStackParamList>()
|
2020-10-23 09:22:17 +02:00
|
|
|
|
2021-02-08 23:19:55 +01:00
|
|
|
const TabNotifications = React.memo(
|
|
|
|
() => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const dispatch = useDispatch()
|
2020-10-24 18:07:09 +02:00
|
|
|
|
2021-02-08 23:19:55 +01:00
|
|
|
const screenOptions = useMemo(
|
|
|
|
() => ({
|
2020-12-25 21:51:46 +01:00
|
|
|
headerTitle: t('notifications:heading'),
|
2021-01-14 00:43:35 +01:00
|
|
|
...(Platform.OS === 'android' && {
|
|
|
|
headerCenter: () => (
|
|
|
|
<HeaderCenter content={t('notifications:heading')} />
|
|
|
|
)
|
|
|
|
}),
|
2021-01-13 01:03:46 +01:00
|
|
|
headerHideShadow: true,
|
|
|
|
headerTopInsetEnabled: false
|
2021-02-08 23:19:55 +01:00
|
|
|
}),
|
|
|
|
[]
|
|
|
|
)
|
2021-02-27 16:33:54 +01:00
|
|
|
|
|
|
|
const queryKey: QueryKeyTimeline = ['Timeline', { page: 'Notifications' }]
|
|
|
|
const renderItem = useCallback(
|
|
|
|
({ item }) => (
|
|
|
|
<TimelineNotifications notification={item} queryKey={queryKey} />
|
|
|
|
),
|
|
|
|
[]
|
|
|
|
)
|
2021-02-08 23:19:55 +01:00
|
|
|
const children = useCallback(
|
|
|
|
({ navigation }) => (
|
|
|
|
<Timeline
|
2021-02-27 16:33:54 +01:00
|
|
|
queryKey={queryKey}
|
2021-02-08 23:19:55 +01:00
|
|
|
customProps={{
|
2021-02-28 17:41:21 +01:00
|
|
|
renderItem
|
|
|
|
// viewabilityConfigCallbackPairs: [
|
|
|
|
// {
|
|
|
|
// onViewableItemsChanged: ({
|
|
|
|
// viewableItems
|
|
|
|
// }: {
|
|
|
|
// viewableItems: ViewToken[]
|
|
|
|
// }) => {
|
|
|
|
// if (
|
|
|
|
// navigation.isFocused() &&
|
|
|
|
// viewableItems.length &&
|
|
|
|
// viewableItems[0].index === 0
|
|
|
|
// ) {
|
|
|
|
// dispatch(
|
|
|
|
// updateInstanceNotification({
|
|
|
|
// readTime: viewableItems[0].item.created_at
|
|
|
|
// })
|
|
|
|
// )
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
// viewabilityConfig: {
|
|
|
|
// minimumViewTime: 100,
|
|
|
|
// itemVisiblePercentThreshold: 60
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// ]
|
2021-02-08 23:19:55 +01:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
[]
|
|
|
|
)
|
2020-10-30 20:03:44 +01:00
|
|
|
|
2021-02-08 23:19:55 +01:00
|
|
|
return (
|
|
|
|
<Stack.Navigator screenOptions={screenOptions}>
|
|
|
|
<Stack.Screen name='Tab-Notifications-Root' children={children} />
|
|
|
|
{sharedScreens(Stack as any)}
|
|
|
|
</Stack.Navigator>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
() => true
|
|
|
|
)
|
2020-10-31 21:04:46 +01:00
|
|
|
|
2021-01-30 01:29:15 +01:00
|
|
|
export default TabNotifications
|