2022-12-03 16:50:54 +01:00
|
|
|
import { HeaderLeft } from '@components/Header'
|
2022-12-31 14:00:52 +01:00
|
|
|
import Icon from '@components/Icon'
|
2023-01-15 20:34:22 +01:00
|
|
|
import { Loading } from '@components/Loading'
|
2022-12-28 23:41:36 +01:00
|
|
|
import ComponentSeparator from '@components/Separator'
|
2022-12-31 00:07:28 +01:00
|
|
|
import CustomText from '@components/Text'
|
2021-02-27 16:33:54 +01:00
|
|
|
import TimelineDefault from '@components/Timeline/Default'
|
2022-12-31 15:53:02 +01:00
|
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
import apiGeneral from '@utils/api/general'
|
|
|
|
import apiInstance from '@utils/api/instance'
|
2023-01-29 16:59:14 +01:00
|
|
|
import { appendRemote } from '@utils/helpers/appendRemote'
|
2023-01-03 23:57:23 +01:00
|
|
|
import { urlMatcher } from '@utils/helpers/urlMatcher'
|
2021-08-29 15:25:38 +02:00
|
|
|
import { TabSharedStackScreenProps } from '@utils/navigation/navigators'
|
2023-01-06 01:01:10 +01:00
|
|
|
import { queryClient } from '@utils/queryHooks'
|
2023-01-01 16:44:55 +01:00
|
|
|
import { QueryKeyTimeline } from '@utils/queryHooks/timeline'
|
2023-01-02 23:18:22 +01:00
|
|
|
import { getAccountStorage } from '@utils/storage/actions'
|
2022-12-28 23:41:36 +01:00
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
2022-12-31 00:07:28 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2022-12-31 15:53:02 +01:00
|
|
|
import React, { useEffect, useRef, useState } from 'react'
|
2022-12-03 16:50:54 +01:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2023-01-15 18:00:58 +01:00
|
|
|
import { Alert, FlatList, Platform, Pressable, View } from 'react-native'
|
2022-12-31 00:07:28 +01:00
|
|
|
import { Path, Svg } from 'react-native-svg'
|
2020-10-29 14:52:28 +01:00
|
|
|
|
2021-08-29 15:25:38 +02:00
|
|
|
const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
|
2022-12-03 16:50:54 +01:00
|
|
|
navigation,
|
2020-10-29 14:52:28 +01:00
|
|
|
route: {
|
2023-01-04 22:39:29 +01:00
|
|
|
params: { toot }
|
2020-10-29 14:52:28 +01:00
|
|
|
}
|
2020-10-31 21:04:46 +01:00
|
|
|
}) => {
|
2022-12-31 00:07:28 +01:00
|
|
|
const { colors } = useTheme()
|
2022-12-31 14:00:52 +01:00
|
|
|
const { t } = useTranslation(['componentTimeline', 'screenTabs'])
|
2022-12-03 16:50:54 +01:00
|
|
|
|
2023-02-12 17:08:44 +01:00
|
|
|
const [hasRemoteContent, setHasRemoteContent] = useState<boolean>(toot._remote || false)
|
2023-01-04 22:39:29 +01:00
|
|
|
const queryKey: { local: QueryKeyTimeline; remote: QueryKeyTimeline } = {
|
|
|
|
local: ['Timeline', { page: 'Toot', toot: toot.id, remote: false }],
|
|
|
|
remote: ['Timeline', { page: 'Toot', toot: toot.id, remote: true }]
|
|
|
|
}
|
2022-12-31 15:53:02 +01:00
|
|
|
|
2023-02-24 13:54:27 +01:00
|
|
|
const flRef = useRef<FlatList<Mastodon.Status & { _level?: number }>>(null)
|
2023-01-15 18:00:58 +01:00
|
|
|
|
2022-12-03 16:50:54 +01:00
|
|
|
useEffect(() => {
|
|
|
|
navigation.setOptions({
|
2022-12-31 15:53:02 +01:00
|
|
|
headerTitle: () => (
|
2023-01-02 02:08:12 +01:00
|
|
|
<Pressable
|
|
|
|
style={{ flexDirection: 'row', alignItems: 'center' }}
|
|
|
|
disabled={!hasRemoteContent}
|
|
|
|
onPress={() =>
|
|
|
|
Alert.alert(
|
|
|
|
t('screenTabs:shared.toot.remoteFetch.title'),
|
|
|
|
t('screenTabs:shared.toot.remoteFetch.message')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
2022-12-31 15:53:02 +01:00
|
|
|
{hasRemoteContent ? (
|
|
|
|
<Icon
|
2023-01-25 00:15:46 +01:00
|
|
|
name='wifi'
|
2022-12-31 15:53:02 +01:00
|
|
|
size={StyleConstants.Font.Size.M}
|
|
|
|
color={colors.primaryDefault}
|
|
|
|
style={{ marginRight: StyleConstants.Spacing.S }}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<CustomText
|
|
|
|
style={{ color: colors.primaryDefault }}
|
|
|
|
fontSize='L'
|
|
|
|
fontWeight='Bold'
|
|
|
|
numberOfLines={1}
|
|
|
|
children={t('screenTabs:shared.toot.name')}
|
|
|
|
/>
|
2023-01-02 02:08:12 +01:00
|
|
|
</Pressable>
|
2022-12-31 15:53:02 +01:00
|
|
|
),
|
2023-01-26 23:35:52 +01:00
|
|
|
headerLeft: () => <HeaderLeft onPress={() => navigation.goBack()} />,
|
|
|
|
headerBackVisible: false
|
2022-12-03 16:50:54 +01:00
|
|
|
})
|
2023-02-12 17:08:44 +01:00
|
|
|
navigation.setParams({ queryKey: queryKey.local })
|
2022-12-31 15:53:02 +01:00
|
|
|
}, [hasRemoteContent])
|
2022-12-03 16:50:54 +01:00
|
|
|
|
2023-01-15 18:00:58 +01:00
|
|
|
const PREV_PER_BATCH = 1
|
2023-02-24 13:54:27 +01:00
|
|
|
const ancestorsCache = useRef<(Mastodon.Status & { _level?: number })[]>()
|
2023-01-15 18:00:58 +01:00
|
|
|
const loaded = useRef<boolean>(false)
|
2023-01-16 22:52:30 +01:00
|
|
|
const prependContent = async () => {
|
|
|
|
loaded.current = true
|
|
|
|
|
|
|
|
if (ancestorsCache.current?.length) {
|
|
|
|
switch (Platform.OS) {
|
|
|
|
case 'ios':
|
2023-02-26 18:09:51 +01:00
|
|
|
await new Promise<void>(promise => setTimeout(promise, 128))
|
2023-01-16 22:52:30 +01:00
|
|
|
for (let [] of Array(
|
|
|
|
Math.ceil(ancestorsCache.current.length / PREV_PER_BATCH)
|
|
|
|
).entries()) {
|
2023-02-26 18:09:51 +01:00
|
|
|
await new Promise<void>(promise => setTimeout(promise, 8))
|
2023-01-16 22:52:30 +01:00
|
|
|
queryClient.setQueryData<{ pages: { body: Mastodon.Status[] }[] }>(
|
|
|
|
queryKey.local,
|
|
|
|
old => {
|
|
|
|
const insert = ancestorsCache.current?.slice(-PREV_PER_BATCH)
|
|
|
|
ancestorsCache.current = ancestorsCache.current?.slice(0, -PREV_PER_BATCH)
|
|
|
|
if (insert) {
|
|
|
|
old?.pages[0].body.unshift(...insert)
|
|
|
|
}
|
|
|
|
|
|
|
|
return old
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
queryClient.setQueryData<{ pages: { body: Mastodon.Status[] }[] }>(
|
|
|
|
queryKey.local,
|
|
|
|
old => {
|
|
|
|
ancestorsCache.current && old?.pages[0].body.unshift(...ancestorsCache.current)
|
|
|
|
|
|
|
|
return old
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2023-03-08 21:40:40 +01:00
|
|
|
flRef.current?.props.data?.length && setTimeout(() => {
|
2023-01-16 22:52:30 +01:00
|
|
|
flRef.current?.scrollToIndex({
|
|
|
|
index: ancestorsCache.current?.length || 0,
|
|
|
|
viewOffset: 50
|
|
|
|
})
|
|
|
|
}, 50)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-16 00:21:53 +01:00
|
|
|
|
2023-01-03 23:57:23 +01:00
|
|
|
const match = urlMatcher(toot.url || toot.uri)
|
2023-01-16 22:52:30 +01:00
|
|
|
const remoteQueryEnabled =
|
|
|
|
['public', 'unlisted'].includes(toot.visibility) &&
|
|
|
|
match?.domain !== getAccountStorage.string('auth.domain')
|
2023-01-16 14:30:00 +01:00
|
|
|
const query = useQuery<{
|
2023-02-24 13:54:27 +01:00
|
|
|
pages: { body: (Mastodon.Status & { _level?: number })[] }[]
|
2023-01-16 14:30:00 +01:00
|
|
|
}>(
|
2023-01-01 16:44:55 +01:00
|
|
|
queryKey.local,
|
2022-12-31 15:53:02 +01:00
|
|
|
async () => {
|
|
|
|
const context = await apiInstance<{
|
|
|
|
ancestors: Mastodon.Status[]
|
|
|
|
descendants: Mastodon.Status[]
|
|
|
|
}>({
|
|
|
|
method: 'get',
|
|
|
|
url: `statuses/${toot.id}/context`
|
2023-01-06 01:01:10 +01:00
|
|
|
}).then(res => res.body)
|
2022-12-31 15:53:02 +01:00
|
|
|
|
2023-01-15 18:00:58 +01:00
|
|
|
ancestorsCache.current = [...context.ancestors]
|
|
|
|
const statuses = [{ ...toot }, ...context.descendants]
|
2022-12-31 15:53:02 +01:00
|
|
|
|
2023-01-06 01:01:10 +01:00
|
|
|
return {
|
|
|
|
pages: [
|
|
|
|
{
|
|
|
|
body: statuses.map((status, index) => {
|
2023-01-15 18:00:58 +01:00
|
|
|
if (index === 0) {
|
2023-01-07 11:32:50 +01:00
|
|
|
status._level = 0
|
|
|
|
return status
|
2023-01-06 01:01:10 +01:00
|
|
|
} else {
|
|
|
|
const repliedLevel: number =
|
|
|
|
statuses.find(s => s.id === status.in_reply_to_id)?._level || 0
|
2023-01-07 11:32:50 +01:00
|
|
|
status._level = repliedLevel + 1
|
|
|
|
return status
|
2023-01-06 01:01:10 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
]
|
2022-12-31 15:53:02 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2023-01-02 02:08:12 +01:00
|
|
|
enabled: !toot._remote,
|
2022-12-31 15:53:02 +01:00
|
|
|
staleTime: 0,
|
|
|
|
refetchOnMount: true,
|
2023-01-16 22:52:30 +01:00
|
|
|
onSuccess: async data => {
|
2022-12-31 14:00:52 +01:00
|
|
|
if (data.pages[0].body.length < 1) {
|
2021-02-27 16:33:54 +01:00
|
|
|
navigation.goBack()
|
2022-02-12 11:12:05 +01:00
|
|
|
return
|
2021-02-27 16:33:54 +01:00
|
|
|
}
|
2023-01-16 22:52:30 +01:00
|
|
|
|
|
|
|
if (!remoteQueryEnabled) {
|
|
|
|
await prependContent()
|
|
|
|
}
|
2021-02-27 16:33:54 +01:00
|
|
|
}
|
2022-12-31 00:07:28 +01:00
|
|
|
}
|
2022-12-31 15:53:02 +01:00
|
|
|
)
|
2023-01-15 20:34:22 +01:00
|
|
|
const remoteQuery = useQuery<Mastodon.Status[]>(
|
2023-01-01 16:44:55 +01:00
|
|
|
queryKey.remote,
|
2022-12-31 15:53:02 +01:00
|
|
|
async () => {
|
2023-01-03 23:57:23 +01:00
|
|
|
const domain = match?.domain
|
2023-01-03 00:10:44 +01:00
|
|
|
if (!domain?.length) {
|
|
|
|
return Promise.reject('Cannot parse remote doamin')
|
|
|
|
}
|
2023-01-03 23:57:23 +01:00
|
|
|
const id = match?.status?.id
|
2023-01-03 00:10:44 +01:00
|
|
|
if (!id?.length) {
|
|
|
|
return Promise.reject('Cannot parse remote toot id')
|
|
|
|
}
|
2022-12-31 15:53:02 +01:00
|
|
|
|
2023-01-03 00:10:44 +01:00
|
|
|
const context = await apiGeneral<{
|
|
|
|
ancestors: Mastodon.Status[]
|
|
|
|
descendants: Mastodon.Status[]
|
|
|
|
}>({
|
|
|
|
method: 'get',
|
|
|
|
domain,
|
|
|
|
url: `api/v1/statuses/${id}/context`
|
|
|
|
}).then(res => res.body)
|
2022-12-31 15:53:02 +01:00
|
|
|
|
2023-01-06 01:01:10 +01:00
|
|
|
if (!context?.ancestors.length && !context?.descendants.length) {
|
2023-01-10 00:52:50 +01:00
|
|
|
return Promise.resolve([{ ...toot }])
|
2022-12-31 15:53:02 +01:00
|
|
|
}
|
|
|
|
|
2023-01-15 21:51:27 +01:00
|
|
|
if ((ancestorsCache.current?.length || 0) < context.ancestors.length) {
|
|
|
|
ancestorsCache.current = context.ancestors.map(ancestor => {
|
|
|
|
const localMatch = ancestorsCache.current?.find(local => local.uri === ancestor.uri)
|
|
|
|
if (localMatch) {
|
|
|
|
return localMatch
|
|
|
|
} else {
|
2023-02-25 23:42:04 +01:00
|
|
|
return appendRemote.status(ancestor, domain)
|
2023-01-15 18:00:58 +01:00
|
|
|
}
|
2023-01-15 21:51:27 +01:00
|
|
|
})
|
|
|
|
}
|
2022-12-31 15:53:02 +01:00
|
|
|
|
2023-01-15 18:00:58 +01:00
|
|
|
const statuses = [{ ...toot }, ...context.descendants]
|
2023-01-06 01:01:10 +01:00
|
|
|
return statuses.map((status, index) => {
|
2023-01-15 18:00:58 +01:00
|
|
|
if (index === 0) {
|
2023-01-07 11:32:50 +01:00
|
|
|
status._level = 0
|
|
|
|
return status
|
2023-01-15 18:00:58 +01:00
|
|
|
} else {
|
|
|
|
const repliedLevel: number =
|
|
|
|
statuses.find(s => s.id === status.in_reply_to_id)?._level || 0
|
|
|
|
status._level = repliedLevel + 1
|
|
|
|
return status
|
2022-12-31 15:53:02 +01:00
|
|
|
}
|
2023-01-06 01:01:10 +01:00
|
|
|
})
|
2022-12-31 15:53:02 +01:00
|
|
|
},
|
|
|
|
{
|
2023-01-16 22:52:30 +01:00
|
|
|
enabled: (toot._remote ? true : query.isFetched) && remoteQueryEnabled,
|
2022-12-31 15:53:02 +01:00
|
|
|
staleTime: 0,
|
2023-01-02 02:08:12 +01:00
|
|
|
refetchOnMount: true,
|
2023-01-16 22:52:30 +01:00
|
|
|
retry: false,
|
2023-01-15 18:00:58 +01:00
|
|
|
onSuccess: async data => {
|
2023-01-07 13:08:33 +01:00
|
|
|
if ((query.data?.pages[0].body.length || 0) < 1 && data.length < 1) {
|
2022-12-31 15:53:02 +01:00
|
|
|
navigation.goBack()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-12 17:08:44 +01:00
|
|
|
if ((query.data?.pages[0].body.length || 0) <= data.length) {
|
2023-02-13 21:43:02 +01:00
|
|
|
if (
|
|
|
|
!hasRemoteContent &&
|
|
|
|
(query.data?.pages[0].body.length || 0) <= data.length &&
|
|
|
|
data.length > 1
|
|
|
|
) {
|
2023-02-12 17:08:44 +01:00
|
|
|
setHasRemoteContent(true)
|
|
|
|
}
|
|
|
|
|
2023-01-06 01:01:10 +01:00
|
|
|
queryClient.cancelQueries(queryKey.local)
|
2023-01-15 18:00:58 +01:00
|
|
|
queryClient.setQueryData<{ pages: { body: Mastodon.Status[] }[] }>(
|
|
|
|
queryKey.local,
|
|
|
|
old => {
|
|
|
|
return {
|
|
|
|
pages: [
|
|
|
|
{
|
|
|
|
body: data.map(remote => {
|
|
|
|
const localMatch = old?.pages[0].body.find(local => local.uri === remote.uri)
|
|
|
|
if (localMatch) {
|
2023-02-24 13:54:27 +01:00
|
|
|
return { ...localMatch, _level: remote._level }
|
2023-01-15 18:00:58 +01:00
|
|
|
} else {
|
2023-02-25 23:42:04 +01:00
|
|
|
return appendRemote.status(remote, match!.domain)
|
2023-01-06 01:01:10 +01:00
|
|
|
}
|
2023-01-15 18:00:58 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-01-01 17:20:35 +01:00
|
|
|
}
|
2023-01-15 18:00:58 +01:00
|
|
|
)
|
2022-12-31 15:53:02 +01:00
|
|
|
}
|
2023-01-15 21:51:27 +01:00
|
|
|
},
|
|
|
|
onSettled: async () => {
|
2023-01-16 22:52:30 +01:00
|
|
|
await prependContent()
|
2022-12-31 15:53:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2022-12-31 00:07:28 +01:00
|
|
|
|
2023-01-09 16:52:29 +01:00
|
|
|
const [heights, setHeights] = useState<{ [key: number]: number }>({})
|
2022-12-31 12:56:10 +01:00
|
|
|
const MAX_LEVEL = 10
|
|
|
|
const ARC = StyleConstants.Avatar.XS / 4
|
2021-02-27 16:33:54 +01:00
|
|
|
|
2021-02-13 01:26:02 +01:00
|
|
|
return (
|
2023-01-06 14:00:50 +01:00
|
|
|
<FlatList
|
2022-12-31 00:07:28 +01:00
|
|
|
ref={flRef}
|
2023-01-06 18:38:52 +01:00
|
|
|
data={query.data?.pages?.[0].body}
|
2023-02-24 13:54:27 +01:00
|
|
|
keyExtractor={(item, index) => `${item.id}_${index}`}
|
2022-12-31 00:07:28 +01:00
|
|
|
renderItem={({ item, index }) => {
|
2023-01-07 13:08:33 +01:00
|
|
|
const prev = query.data?.pages[0].body[index - 1]?._level || 0
|
2023-01-15 18:00:58 +01:00
|
|
|
const curr = item._level || 0
|
2023-01-07 13:08:33 +01:00
|
|
|
const next = query.data?.pages[0].body[index + 1]?._level || 0
|
2022-12-31 00:07:28 +01:00
|
|
|
|
2023-01-27 21:54:48 +01:00
|
|
|
const height = heights[index] || 300
|
|
|
|
let path = ''
|
|
|
|
|
|
|
|
if (curr > 1 || next > 1) {
|
|
|
|
Array.from({ length: curr }).forEach((_, i) => {
|
|
|
|
if (i > MAX_LEVEL) return null
|
|
|
|
|
|
|
|
const lastLine = curr === i + 1
|
|
|
|
if (lastLine) {
|
|
|
|
if (curr === prev + 1 || curr === next - 1) {
|
|
|
|
if (curr > next) return
|
|
|
|
|
|
|
|
path =
|
|
|
|
path +
|
|
|
|
` M ${curr * StyleConstants.Spacing.S + ARC} ${
|
|
|
|
StyleConstants.Spacing.M + StyleConstants.Avatar.XS / 2
|
|
|
|
} ` +
|
|
|
|
`a ${ARC} ${ARC} 0 0 0 -${ARC} ${ARC} ` +
|
|
|
|
`v ${height}`
|
|
|
|
} else {
|
|
|
|
if (i >= curr - 2) return
|
|
|
|
|
|
|
|
path =
|
|
|
|
path +
|
|
|
|
` M ${(i + 1) * StyleConstants.Spacing.S} 0 ` +
|
|
|
|
`v ${
|
|
|
|
height -
|
|
|
|
(StyleConstants.Spacing.S * 1.5 + StyleConstants.Font.Size.L) / 2 -
|
|
|
|
StyleConstants.Avatar.XS / 2
|
|
|
|
} ` +
|
|
|
|
`a ${ARC} ${ARC} 0 0 0 ${ARC} ${ARC}`
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (i >= next - 1) {
|
|
|
|
path =
|
|
|
|
path +
|
|
|
|
` M ${(i + 1) * StyleConstants.Spacing.S} 0 ` +
|
|
|
|
`v ${
|
|
|
|
height -
|
|
|
|
(StyleConstants.Spacing.S * 1.5 + StyleConstants.Font.Size.L * 1.35) / 2
|
|
|
|
} ` +
|
|
|
|
`h ${ARC}`
|
|
|
|
} else {
|
|
|
|
path = path + ` M ${(i + 1) * StyleConstants.Spacing.S} 0 ` + `v ${height}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-31 00:07:28 +01:00
|
|
|
return (
|
|
|
|
<View
|
2023-01-15 18:00:58 +01:00
|
|
|
style={{ paddingLeft: Math.min(curr - 1, MAX_LEVEL) * StyleConstants.Spacing.S }}
|
2022-12-31 00:07:28 +01:00
|
|
|
onLayout={({
|
|
|
|
nativeEvent: {
|
|
|
|
layout: { height }
|
|
|
|
}
|
2023-01-09 16:52:29 +01:00
|
|
|
}) => setHeights({ ...heights, [index]: height })}
|
2022-12-31 00:07:28 +01:00
|
|
|
>
|
2023-01-27 21:54:48 +01:00
|
|
|
{path.length ? (
|
|
|
|
<Svg style={{ position: 'absolute' }} fill='none'>
|
|
|
|
<Path d={path} strokeWidth={1} stroke={colors.border} strokeOpacity={0.6} />
|
|
|
|
</Svg>
|
|
|
|
) : null}
|
2023-01-15 19:59:48 +01:00
|
|
|
<TimelineDefault
|
|
|
|
item={item}
|
2023-02-12 17:08:44 +01:00
|
|
|
queryKey={queryKey.local}
|
2023-01-29 19:27:15 +01:00
|
|
|
highlighted={toot.id === item.id}
|
|
|
|
suppressSpoiler={
|
|
|
|
toot.id !== item.id &&
|
|
|
|
!!toot.spoiler_text?.length &&
|
|
|
|
toot.spoiler_text === item.spoiler_text
|
|
|
|
}
|
|
|
|
isConversation={toot.id !== item.id}
|
2023-01-15 19:59:48 +01:00
|
|
|
noBackground
|
|
|
|
/>
|
2023-01-09 22:28:53 +01:00
|
|
|
{/* <CustomText
|
2023-01-07 13:08:33 +01:00
|
|
|
children={query.data?.pages[0].body[index - 1]?._level}
|
2022-12-31 00:07:28 +01:00
|
|
|
style={{ position: 'absolute', top: 4, left: 4, color: colors.red }}
|
|
|
|
/>
|
|
|
|
<CustomText
|
|
|
|
children={item._level}
|
|
|
|
style={{ position: 'absolute', top: 20, left: 4, color: colors.yellow }}
|
|
|
|
/>
|
|
|
|
<CustomText
|
2023-01-07 13:08:33 +01:00
|
|
|
children={query.data?.pages[0].body[index + 1]?._level}
|
2022-12-31 00:07:28 +01:00
|
|
|
style={{ position: 'absolute', top: 36, left: 4, color: colors.green }}
|
2023-01-09 22:28:53 +01:00
|
|
|
/> */}
|
2022-12-31 00:07:28 +01:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}}
|
2023-01-25 00:29:36 +01:00
|
|
|
initialNumToRender={3}
|
2023-01-06 14:00:50 +01:00
|
|
|
maxToRenderPerBatch={3}
|
2022-12-31 00:07:28 +01:00
|
|
|
ItemSeparatorComponent={({ leadingItem }) => {
|
|
|
|
return (
|
|
|
|
<>
|
2022-12-18 23:15:58 +01:00
|
|
|
<ComponentSeparator
|
|
|
|
extraMarginLeft={
|
2022-12-31 12:56:10 +01:00
|
|
|
leadingItem.id === toot.id
|
2022-12-18 23:15:58 +01:00
|
|
|
? 0
|
|
|
|
: StyleConstants.Avatar.XS +
|
|
|
|
StyleConstants.Spacing.S +
|
2023-01-15 18:00:58 +01:00
|
|
|
Math.min(Math.max(0, (leadingItem._level || 0) - 1), MAX_LEVEL) *
|
2022-12-31 12:56:10 +01:00
|
|
|
StyleConstants.Spacing.S
|
2022-12-18 23:15:58 +01:00
|
|
|
}
|
2022-12-16 17:00:07 +01:00
|
|
|
/>
|
2022-12-31 00:07:28 +01:00
|
|
|
{leadingItem._level > 1
|
|
|
|
? [...new Array(leadingItem._level - 1)].map((_, i) => (
|
|
|
|
<Svg key={i} style={{ position: 'absolute', top: -1 }}>
|
|
|
|
<Path
|
|
|
|
d={`M ${(i + 1) * StyleConstants.Spacing.S} 0 ` + `v 1`}
|
|
|
|
strokeWidth={1}
|
|
|
|
stroke={colors.border}
|
|
|
|
strokeOpacity={0.6}
|
|
|
|
/>
|
|
|
|
</Svg>
|
|
|
|
))
|
|
|
|
: null}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}}
|
2022-12-31 15:53:02 +01:00
|
|
|
ListFooterComponent={
|
2023-01-15 20:34:22 +01:00
|
|
|
query.isFetching || remoteQuery.isFetching ? (
|
|
|
|
<View style={{ flex: 1, alignItems: 'center' }} children={<Loading />} />
|
|
|
|
) : null
|
2022-12-31 15:53:02 +01:00
|
|
|
}
|
2023-01-15 18:00:58 +01:00
|
|
|
{...(loaded.current && { maintainVisibleContentPosition: { minIndexForVisible: 0 } })}
|
|
|
|
{...(Platform.OS !== 'ios' && {
|
|
|
|
onScrollToIndexFailed: error => {
|
|
|
|
const offset = error.averageItemLength * error.index
|
|
|
|
flRef.current?.scrollToOffset({ offset })
|
|
|
|
error.index < (ancestorsCache.current?.length || 0) &&
|
|
|
|
setTimeout(
|
|
|
|
() =>
|
|
|
|
flRef.current?.scrollToIndex({
|
|
|
|
index: error.index,
|
|
|
|
viewOffset: 50
|
|
|
|
}),
|
|
|
|
50
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})}
|
2021-02-13 01:26:02 +01:00
|
|
|
/>
|
|
|
|
)
|
2020-10-29 14:52:28 +01:00
|
|
|
}
|
2020-10-31 21:04:46 +01:00
|
|
|
|
2021-01-30 01:29:15 +01:00
|
|
|
export default TabSharedToot
|