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'
|
|
|
|
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-02-20 19:12:44 +01:00
|
|
|
import { getInstanceActive } from '@utils/slices/instancesSlice'
|
2021-01-30 01:29:15 +01:00
|
|
|
import React, { useReducer, useRef, useState } 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'
|
2020-11-21 13:19:05 +01:00
|
|
|
|
2021-01-30 01:29:15 +01:00
|
|
|
const ScreenMeRoot: React.FC = () => {
|
2021-02-20 19:12:44 +01:00
|
|
|
const instanceActive = useSelector(getInstanceActive)
|
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)
|
|
|
|
|
2020-12-18 00:00:45 +01:00
|
|
|
const [data, setData] = useState<Mastodon.Account>()
|
|
|
|
|
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}
|
2020-12-18 00:00:45 +01:00
|
|
|
>
|
2021-02-20 19:12:44 +01:00
|
|
|
{instanceActive !== -1 ? (
|
2021-01-07 19:13:09 +01:00
|
|
|
<MyInfo setData={setData} />
|
|
|
|
) : (
|
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}
|
2020-12-18 00:00:45 +01:00
|
|
|
<Settings />
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export default ScreenMeRoot
|