tooot/src/screens/Tabs/Me/Root/index.tsx

64 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-01-30 01:29:15 +01:00
import ComponentInstance from '@components/Instance'
import { useScrollToTop } from '@react-navigation/native'
2021-01-30 01:29:15 +01:00
import Collections from '@screens/Tabs/Me/Root/Collections'
import Logout from '@screens/Tabs/Me/Root/Logout'
import MyInfo from '@screens/Tabs/Me/Root/MyInfo'
import Settings from '@screens/Tabs/Me/Root/Settings'
2021-05-09 21:59:03 +02:00
import AccountInformationSwitch from '@screens/Tabs/Me/Root/Switch'
2023-01-02 02:08:12 +01:00
import AccountContext from '@screens/Tabs/Shared/Account/Context'
2021-01-30 01:29:15 +01:00
import AccountNav from '@screens/Tabs/Shared/Account/Nav'
2021-05-09 21:59:03 +02:00
import { useProfileQuery } from '@utils/queryHooks/profile'
import { useGlobalStorage } from '@utils/storage/actions'
2023-05-15 22:30:18 +02:00
import { StyleConstants } from '@utils/styles/constants'
2023-01-02 02:08:12 +01:00
import React, { useRef } from 'react'
2023-05-15 22:30:18 +02:00
import { View } from 'react-native'
2022-12-21 14:42:44 +01:00
import Animated, { useAnimatedScrollHandler, useSharedValue } from 'react-native-reanimated'
2020-11-21 13:19:05 +01:00
2021-05-09 21:59:03 +02:00
const TabMeRoot: React.FC = () => {
const [accountActive] = useGlobalStorage.string('account.active')
2021-05-09 21:59:03 +02:00
const { data } = useProfileQuery({
options: { enabled: !!accountActive, keepPreviousData: false }
2021-04-24 15:03:17 +02:00
})
2020-11-21 13:19:05 +01:00
const scrollRef = useRef<Animated.ScrollView>(null)
2020-12-13 23:02:54 +01:00
useScrollToTop(scrollRef)
const scrollY = useSharedValue(0)
const onScroll = useAnimatedScrollHandler(event => {
scrollY.value = event.contentOffset.y
})
2020-11-22 00:46:23 +01:00
return (
2023-02-25 23:42:04 +01:00
<AccountContext.Provider value={{ account: data, pageMe: true, localInstance: true }}>
2023-01-02 02:08:12 +01:00
{accountActive && data ? <AccountNav scrollY={scrollY} /> : null}
<Animated.ScrollView
2020-12-18 00:00:45 +01:00
ref={scrollRef}
keyboardShouldPersistTaps='handled'
onScroll={onScroll}
scrollEventThrottle={16}
2020-12-18 00:00:45 +01:00
>
2023-01-02 02:08:12 +01:00
{accountActive ? <MyInfo /> : <ComponentInstance />}
{accountActive ? <Collections /> : null}
2020-12-18 00:00:45 +01:00
<Settings />
2023-05-15 22:30:18 +02:00
{accountActive ? (
<View
style={{
flexDirection: 'row',
marginHorizontal: StyleConstants.Spacing.Global.PagePadding,
marginTop: StyleConstants.Spacing.S,
marginBottom: StyleConstants.Spacing.XL,
gap: StyleConstants.Spacing.M
}}
>
<Logout />
<AccountInformationSwitch />
</View>
) : null}
</Animated.ScrollView>
</AccountContext.Provider>
2020-11-22 00:46:23 +01:00
)
2020-11-21 13:19:05 +01:00
}
2021-05-09 21:59:03 +02:00
export default TabMeRoot