2021-01-30 01:29:15 +01:00
|
|
|
import ComponentInstance from '@components/Instance'
|
2021-01-03 02:00:26 +01:00
|
|
|
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'
|
2021-01-30 01:29:15 +01:00
|
|
|
import AccountNav from '@screens/Tabs/Shared/Account/Nav'
|
|
|
|
import AccountContext from '@screens/Tabs/Shared/Account/utils/createContext'
|
|
|
|
import accountInitialState from '@screens/Tabs/Shared/Account/utils/initialState'
|
|
|
|
import accountReducer from '@screens/Tabs/Shared/Account/utils/reducer'
|
2021-05-09 21:59:03 +02:00
|
|
|
import { useProfileQuery } from '@utils/queryHooks/profile'
|
|
|
|
import { getInstanceActive } from '@utils/slices/instancesSlice'
|
2021-12-31 12:29:41 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
2021-04-24 15:03:17 +02:00
|
|
|
import React, { useReducer, useRef } from 'react'
|
2021-01-04 10:50:24 +01:00
|
|
|
import Animated, {
|
|
|
|
useAnimatedScrollHandler,
|
|
|
|
useSharedValue
|
|
|
|
} from 'react-native-reanimated'
|
2021-01-30 01:29:15 +01:00
|
|
|
import { useSelector } from 'react-redux'
|
2021-05-09 21:59:03 +02:00
|
|
|
import Update from './Root/Update'
|
2020-11-21 13:19:05 +01:00
|
|
|
|
2021-05-09 21:59:03 +02:00
|
|
|
const TabMeRoot: React.FC = () => {
|
2021-02-20 19:12:44 +01:00
|
|
|
const instanceActive = useSelector(getInstanceActive)
|
2021-05-09 21:59:03 +02:00
|
|
|
|
|
|
|
const { data } = useProfileQuery({
|
2021-04-24 15:03:17 +02:00
|
|
|
options: { enabled: instanceActive !== -1, keepPreviousData: false }
|
|
|
|
})
|
2020-11-21 13:19:05 +01:00
|
|
|
|
2021-01-04 10:50:24 +01:00
|
|
|
const scrollRef = useRef<Animated.ScrollView>(null)
|
2020-12-13 23:02:54 +01:00
|
|
|
useScrollToTop(scrollRef)
|
|
|
|
|
2021-01-03 02:00:26 +01:00
|
|
|
const [accountState, accountDispatch] = useReducer(
|
|
|
|
accountReducer,
|
|
|
|
accountInitialState
|
|
|
|
)
|
|
|
|
|
2021-01-04 10:50:24 +01:00
|
|
|
const scrollY = useSharedValue(0)
|
|
|
|
const onScroll = useAnimatedScrollHandler(event => {
|
|
|
|
scrollY.value = event.contentOffset.y
|
|
|
|
})
|
|
|
|
|
2020-11-22 00:46:23 +01:00
|
|
|
return (
|
2021-01-03 02:00:26 +01:00
|
|
|
<AccountContext.Provider value={{ accountState, accountDispatch }}>
|
2021-02-20 19:12:44 +01:00
|
|
|
{instanceActive !== -1 && data ? (
|
2021-01-03 02:00:26 +01:00
|
|
|
<AccountNav scrollY={scrollY} account={data} />
|
2020-12-18 00:00:45 +01:00
|
|
|
) : null}
|
2021-01-04 10:50:24 +01:00
|
|
|
<Animated.ScrollView
|
2020-12-18 00:00:45 +01:00
|
|
|
ref={scrollRef}
|
|
|
|
keyboardShouldPersistTaps='handled'
|
2021-01-04 10:50:24 +01:00
|
|
|
onScroll={onScroll}
|
|
|
|
scrollEventThrottle={16}
|
2021-12-31 12:29:41 +01:00
|
|
|
style={{ marginBottom: StyleConstants.Spacing.L }}
|
2020-12-18 00:00:45 +01:00
|
|
|
>
|
2021-02-20 19:12:44 +01:00
|
|
|
{instanceActive !== -1 ? (
|
2021-04-24 15:03:17 +02:00
|
|
|
<MyInfo account={data} />
|
2021-01-07 19:13:09 +01:00
|
|
|
) : (
|
2021-02-09 01:16:12 +01:00
|
|
|
<ComponentInstance />
|
2021-01-07 19:13:09 +01:00
|
|
|
)}
|
2021-02-20 19:12:44 +01:00
|
|
|
{instanceActive !== -1 ? <Collections /> : null}
|
2021-05-09 21:59:03 +02:00
|
|
|
<Update />
|
2020-12-18 00:00:45 +01:00
|
|
|
<Settings />
|
2021-05-09 21:59:03 +02:00
|
|
|
{instanceActive !== -1 ? <AccountInformationSwitch /> : null}
|
2021-02-20 19:12:44 +01:00
|
|
|
{instanceActive !== -1 ? <Logout /> : null}
|
2021-01-04 10:50:24 +01:00
|
|
|
</Animated.ScrollView>
|
2021-01-03 02:00:26 +01:00
|
|
|
</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
|