Try to fix toot id not found

This commit is contained in:
Zhiyuan Zheng 2022-02-11 21:30:45 +01:00
parent ee71733676
commit 9936f6c921
2 changed files with 13 additions and 11 deletions

View File

@ -4,7 +4,7 @@
"native": "220206",
"major": 3,
"minor": 4,
"patch": 2,
"patch": 3,
"expo": "44.0.0"
},
"description": "tooot app for Mastodon",

View File

@ -35,29 +35,30 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
? // @ts-ignore
result.data.pages.flatMap(d => [...d.body])
: []
setItemsLength(flattenData.length)
// Auto go back when toot page is empty
if (flattenData.length === 0) {
navigation.goBack()
}
setItemsLength(flattenData.length)
if (!scrolled.current) {
scrolled.current = true
const pointer = flattenData.findIndex(({ id }) => id === toot.id)
if (pointer === -1) return
try {
pointer < flattenData.length &&
setTimeout(() => {
flRef.current?.scrollToIndex({
index: pointer,
viewOffset: 100
})
}, 500)
setTimeout(() => {
flRef.current?.scrollToIndex({
index: pointer,
viewOffset: 100
})
}, 500)
} catch (err) {
if (Math.random() < 0.1) {
Sentry.Native.setContext('Scroll to Index', {
type: 'original',
index: pointer,
itemsLength: flattenData.length,
flattenData
id: toot.id,
flattenData: flattenData.map(({ id }) => id)
})
Sentry.Native.captureException(err)
}
@ -87,7 +88,8 @@ const TabSharedToot: React.FC<TabSharedStackScreenProps<'Tab-Shared-Toot'>> = ({
Sentry.Native.setContext('Scroll to Index', {
type: 'onScrollToIndexFailed',
index: error.index,
itemsLength
itemsLength,
id: toot.id
})
Sentry.Native.captureException(err)
}