2021-01-03 02:00:26 +01:00
|
|
|
import BottomSheet from '@components/BottomSheet'
|
|
|
|
import { HeaderRight } from '@components/Header'
|
|
|
|
import HeaderDefaultActionsAccount from '@components/Timelines/Timeline/Shared/HeaderDefault/ActionsAccount'
|
|
|
|
import { accountFetch } from '@utils/fetches/accountFetch'
|
|
|
|
import { getLocalAccountId } from '@utils/slices/instancesSlice'
|
2020-12-21 21:47:15 +01:00
|
|
|
import React, { useEffect, useReducer, useRef, useState } from 'react'
|
2020-12-26 00:53:49 +01:00
|
|
|
import { Animated, ScrollView } from 'react-native'
|
2020-11-04 22:26:38 +01:00
|
|
|
import { useQuery } from 'react-query'
|
2021-01-03 02:00:26 +01:00
|
|
|
import { useSelector } from 'react-redux'
|
|
|
|
import AccountHeader from './Account/Header'
|
|
|
|
import AccountInformation from './Account/Information'
|
2020-12-17 09:44:03 +01:00
|
|
|
import AccountNav from './Account/Nav'
|
|
|
|
import AccountSegmentedControl from './Account/SegmentedControl'
|
2021-01-03 02:00:26 +01:00
|
|
|
import AccountToots from './Account/Toots'
|
|
|
|
import AccountContext from './Account/utils/createContext'
|
|
|
|
import accountInitialState from './Account/utils/initialState'
|
|
|
|
import accountReducer from './Account/utils/reducer'
|
2020-10-28 00:02:37 +01:00
|
|
|
|
|
|
|
// Moved account example: https://m.cmx.im/web/accounts/27812
|
|
|
|
|
2020-10-31 21:04:46 +01:00
|
|
|
export interface Props {
|
|
|
|
route: {
|
|
|
|
params: {
|
2020-12-29 12:33:22 +01:00
|
|
|
account: Pick<Mastodon.Account, 'id' | 'username' | 'acct' | 'url'>
|
2020-10-31 21:04:46 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-21 21:47:15 +01:00
|
|
|
navigation: any
|
2020-10-31 21:04:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:19:05 +01:00
|
|
|
const ScreenSharedAccount: React.FC<Props> = ({
|
2020-10-26 00:27:53 +01:00
|
|
|
route: {
|
2020-12-21 21:47:15 +01:00
|
|
|
params: { account }
|
|
|
|
},
|
|
|
|
navigation
|
2020-10-31 21:04:46 +01:00
|
|
|
}) => {
|
2020-12-21 21:47:15 +01:00
|
|
|
const localAccountId = useSelector(getLocalAccountId)
|
|
|
|
const { data } = useQuery(['Account', { id: account.id }], accountFetch)
|
2020-11-04 22:26:38 +01:00
|
|
|
|
2021-01-03 02:00:26 +01:00
|
|
|
const scrollY = useRef(new Animated.Value(0))
|
2020-12-17 09:44:03 +01:00
|
|
|
const [accountState, accountDispatch] = useReducer(
|
|
|
|
accountReducer,
|
2021-01-03 02:00:26 +01:00
|
|
|
accountInitialState
|
2020-12-17 09:44:03 +01:00
|
|
|
)
|
2020-10-26 00:27:53 +01:00
|
|
|
|
2020-12-21 21:47:15 +01:00
|
|
|
const [modalVisible, setBottomSheetVisible] = useState(false)
|
|
|
|
useEffect(() => {
|
|
|
|
const updateHeaderRight = () =>
|
|
|
|
navigation.setOptions({
|
|
|
|
headerRight: () => (
|
|
|
|
<HeaderRight
|
2021-01-03 02:00:26 +01:00
|
|
|
content='MoreHorizontal'
|
2020-12-21 21:47:15 +01:00
|
|
|
onPress={() => setBottomSheetVisible(true)}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
return updateHeaderRight()
|
|
|
|
}, [])
|
|
|
|
|
2020-11-22 00:46:23 +01:00
|
|
|
return (
|
2021-01-03 02:00:26 +01:00
|
|
|
<AccountContext.Provider value={{ accountState, accountDispatch }}>
|
|
|
|
<AccountNav scrollY={scrollY} account={data} />
|
2020-12-21 22:58:53 +01:00
|
|
|
{accountState.informationLayout?.height &&
|
|
|
|
accountState.informationLayout.y ? (
|
2021-01-03 02:00:26 +01:00
|
|
|
<AccountSegmentedControl scrollY={scrollY} />
|
2020-12-21 22:58:53 +01:00
|
|
|
) : null}
|
2020-12-17 09:44:03 +01:00
|
|
|
<ScrollView
|
2021-01-01 16:48:16 +01:00
|
|
|
scrollEventThrottle={16}
|
|
|
|
showsVerticalScrollIndicator={false}
|
2020-12-17 09:44:03 +01:00
|
|
|
onScroll={Animated.event(
|
2021-01-03 02:00:26 +01:00
|
|
|
[{ nativeEvent: { contentOffset: { y: scrollY.current } } }],
|
2020-12-17 09:44:03 +01:00
|
|
|
{ useNativeDriver: false }
|
|
|
|
)}
|
|
|
|
>
|
2021-01-03 02:00:26 +01:00
|
|
|
<AccountHeader account={data} />
|
|
|
|
<AccountInformation account={data} />
|
|
|
|
<AccountToots id={account.id} />
|
2020-12-17 09:44:03 +01:00
|
|
|
</ScrollView>
|
2020-12-21 21:47:15 +01:00
|
|
|
|
|
|
|
<BottomSheet
|
|
|
|
visible={modalVisible}
|
|
|
|
handleDismiss={() => setBottomSheetVisible(false)}
|
|
|
|
>
|
|
|
|
{/* 添加到列表 */}
|
|
|
|
{localAccountId !== account.id && (
|
|
|
|
<HeaderDefaultActionsAccount
|
|
|
|
account={account}
|
|
|
|
setBottomSheetVisible={setBottomSheetVisible}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</BottomSheet>
|
2021-01-03 02:00:26 +01:00
|
|
|
</AccountContext.Provider>
|
2020-10-26 00:27:53 +01:00
|
|
|
)
|
|
|
|
}
|
2020-10-28 00:02:37 +01:00
|
|
|
|
2020-11-21 13:19:05 +01:00
|
|
|
export default ScreenSharedAccount
|