2021-01-04 10:50:24 +01:00
|
|
|
import { HeaderRight } from '@components/Header'
|
2020-12-13 14:04:25 +01:00
|
|
|
import Timeline from '@components/Timelines/Timeline'
|
2021-01-04 10:50:24 +01:00
|
|
|
import SegmentedControl from '@react-native-community/segmented-control'
|
|
|
|
import { useNavigation } from '@react-navigation/native'
|
2020-12-13 14:04:25 +01:00
|
|
|
import sharedScreens from '@screens/Shared/sharedScreens'
|
2021-01-07 19:13:09 +01:00
|
|
|
import { getLocalActiveIndex, getRemoteUrl } from '@utils/slices/instancesSlice'
|
2020-12-13 14:04:25 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2021-01-04 10:50:24 +01:00
|
|
|
import React, { useCallback, useState } from 'react'
|
|
|
|
import { Dimensions, StyleSheet, View } from 'react-native'
|
|
|
|
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
|
2020-12-17 12:04:58 +01:00
|
|
|
import { TabView } from 'react-native-tab-view'
|
2021-01-04 10:50:24 +01:00
|
|
|
import { useSelector } from 'react-redux'
|
2020-10-24 16:44:32 +02:00
|
|
|
|
|
|
|
const Stack = createNativeStackNavigator()
|
|
|
|
|
2020-10-31 21:04:46 +01:00
|
|
|
export interface Props {
|
2021-01-04 10:50:24 +01:00
|
|
|
name: 'Local' | 'Public'
|
2020-11-21 00:40:55 +01:00
|
|
|
content: { title: string; page: App.Pages }[]
|
2020-10-31 21:04:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:19:05 +01:00
|
|
|
const Timelines: React.FC<Props> = ({ name, content }) => {
|
2020-11-24 00:18:47 +01:00
|
|
|
const navigation = useNavigation()
|
2020-12-14 22:33:19 +01:00
|
|
|
const { mode } = useTheme()
|
2021-01-07 19:13:09 +01:00
|
|
|
const localActiveIndex = useSelector(getLocalActiveIndex)
|
2020-11-29 13:11:23 +01:00
|
|
|
const publicDomain = useSelector(getRemoteUrl)
|
2020-10-24 16:44:32 +02:00
|
|
|
const [segment, setSegment] = useState(0)
|
|
|
|
|
2020-11-28 17:07:30 +01:00
|
|
|
const onPressSearch = useCallback(() => {
|
2021-01-04 10:50:24 +01:00
|
|
|
navigation.navigate(`Screen-${name}`, { screen: 'Screen-Shared-Search' })
|
2020-11-28 17:07:30 +01:00
|
|
|
}, [])
|
|
|
|
|
2020-12-20 17:53:24 +01:00
|
|
|
const routes = content
|
2021-01-07 19:13:09 +01:00
|
|
|
.filter(p => (localActiveIndex !== null ? true : p.page === 'RemotePublic'))
|
2020-12-20 17:53:24 +01:00
|
|
|
.map(p => ({ key: p.page }))
|
|
|
|
|
2021-01-01 16:48:16 +01:00
|
|
|
const renderScene = useCallback(
|
|
|
|
({
|
|
|
|
route
|
|
|
|
}: {
|
|
|
|
route: {
|
|
|
|
key: App.Pages
|
|
|
|
}
|
|
|
|
}) => {
|
|
|
|
return (
|
2021-01-07 19:13:09 +01:00
|
|
|
(localActiveIndex !== null || route.key === 'RemotePublic') && (
|
2021-01-01 16:48:16 +01:00
|
|
|
<Timeline page={route.key} />
|
|
|
|
)
|
2020-12-20 17:53:24 +01:00
|
|
|
)
|
2021-01-01 16:48:16 +01:00
|
|
|
},
|
2021-01-07 19:13:09 +01:00
|
|
|
[localActiveIndex]
|
2021-01-01 16:48:16 +01:00
|
|
|
)
|
2020-11-28 17:07:30 +01:00
|
|
|
|
2020-12-20 23:49:35 +01:00
|
|
|
const screenComponent = useCallback(
|
|
|
|
() => (
|
|
|
|
<TabView
|
|
|
|
lazy
|
|
|
|
swipeEnabled
|
|
|
|
renderScene={renderScene}
|
|
|
|
renderTabBar={() => null}
|
|
|
|
onIndexChange={index => setSegment(index)}
|
|
|
|
navigationState={{ index: segment, routes }}
|
|
|
|
initialLayout={{ width: Dimensions.get('window').width }}
|
|
|
|
/>
|
|
|
|
),
|
2021-01-07 19:13:09 +01:00
|
|
|
[segment, localActiveIndex]
|
2020-12-20 23:49:35 +01:00
|
|
|
)
|
|
|
|
|
2020-10-24 16:44:32 +02:00
|
|
|
return (
|
2020-12-25 21:51:46 +01:00
|
|
|
<Stack.Navigator screenOptions={{ headerHideShadow: true }}>
|
2020-10-26 00:27:53 +01:00
|
|
|
<Stack.Screen
|
2021-01-04 10:50:24 +01:00
|
|
|
name={`Screen-${name}-Root`}
|
2020-10-26 00:27:53 +01:00
|
|
|
options={{
|
2021-01-04 10:50:24 +01:00
|
|
|
headerTitle: name === 'Public' ? publicDomain : '',
|
2021-01-07 19:13:09 +01:00
|
|
|
...(localActiveIndex !== null && {
|
2020-12-21 23:30:26 +01:00
|
|
|
headerCenter: () => (
|
|
|
|
<View style={styles.segmentsContainer}>
|
|
|
|
<SegmentedControl
|
|
|
|
appearance={mode}
|
|
|
|
values={[content[0].title, content[1].title]}
|
|
|
|
selectedIndex={segment}
|
|
|
|
onChange={({ nativeEvent }) =>
|
|
|
|
setSegment(nativeEvent.selectedSegmentIndex)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
),
|
|
|
|
headerRight: () => (
|
2021-01-03 02:00:26 +01:00
|
|
|
<HeaderRight content='Search' onPress={onPressSearch} />
|
2020-12-21 23:30:26 +01:00
|
|
|
)
|
|
|
|
})
|
2020-10-26 00:27:53 +01:00
|
|
|
}}
|
|
|
|
>
|
2020-12-20 23:49:35 +01:00
|
|
|
{screenComponent}
|
2020-10-24 16:44:32 +02:00
|
|
|
</Stack.Screen>
|
2020-10-30 20:03:44 +01:00
|
|
|
|
|
|
|
{sharedScreens(Stack)}
|
2020-10-24 16:44:32 +02:00
|
|
|
</Stack.Navigator>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-28 17:07:30 +01:00
|
|
|
const styles = StyleSheet.create({
|
2020-11-29 13:11:23 +01:00
|
|
|
segmentsContainer: {
|
|
|
|
flexBasis: '60%'
|
2020-11-28 17:07:30 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default React.memo(Timelines, () => true)
|