From 57efc4c868527d23be4525272a64f6a6bc91cbe3 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Mon, 30 Jan 2023 12:55:35 +0100 Subject: [PATCH 1/5] Fix crashes --- src/components/Timeline/Shared/FullConversation.tsx | 4 ++-- src/components/Timeline/Shared/HeaderShared/Replies.tsx | 2 +- src/components/contextMenu/status.ts | 2 +- src/screens/Tabs/Me/Root/Collections.tsx | 4 ++-- src/utils/helpers/appendRemote.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/Timeline/Shared/FullConversation.tsx b/src/components/Timeline/Shared/FullConversation.tsx index 8842ad77..f3e0bbb1 100644 --- a/src/components/Timeline/Shared/FullConversation.tsx +++ b/src/components/Timeline/Shared/FullConversation.tsx @@ -15,8 +15,8 @@ const TimelineFullConversation = () => { return queryKey && queryKey[1].page !== 'Toot' && status.in_reply_to_account_id && - (status.mentions.length === 0 || - status.mentions.filter(mention => mention.id !== status.in_reply_to_account_id).length) ? ( + (status.mentions?.length === 0 || + status.mentions?.filter(mention => mention.id !== status.in_reply_to_account_id).length) ? ( { excludeMentions && (excludeMentions.current = mentionsBeginning?.length && status?.mentions - ? status.mentions.filter(mention => mentionsBeginning.includes(`@${mention.username}`)) + ? status.mentions?.filter(mention => mentionsBeginning.includes(`@${mention.username}`)) : []) return excludeMentions?.current.length ? ( diff --git a/src/components/contextMenu/status.ts b/src/components/contextMenu/status.ts index 8e8a964f..ab804699 100644 --- a/src/components/contextMenu/status.ts +++ b/src/components/contextMenu/status.ts @@ -197,7 +197,7 @@ const menuStatus = ({ hidden: !ownAccount && queryKey[1].page !== 'Notifications' && - !status.mentions.find( + !status.mentions?.find( mention => mention.acct === accountAcct && mention.username === accountAcct ) && !status.muted diff --git a/src/screens/Tabs/Me/Root/Collections.tsx b/src/screens/Tabs/Me/Root/Collections.tsx index 1e181b9e..85e34b02 100644 --- a/src/screens/Tabs/Me/Root/Collections.tsx +++ b/src/screens/Tabs/Me/Root/Collections.tsx @@ -96,10 +96,10 @@ const Collections: React.FC = () => { iconBack='chevron-right' title={t('screenTabs:me.stacks.push.name')} content={ - typeof instancePush.global === 'boolean' + typeof instancePush?.global === 'boolean' ? t('screenTabs:me.root.push.content', { defaultValue: 'false', - context: instancePush.global.toString() + context: instancePush?.global.toString() }) : undefined } diff --git a/src/utils/helpers/appendRemote.ts b/src/utils/helpers/appendRemote.ts index 2ebf92cf..5447abe1 100644 --- a/src/utils/helpers/appendRemote.ts +++ b/src/utils/helpers/appendRemote.ts @@ -19,5 +19,5 @@ export const appendRemote = { _remote: true }), mentions: (mentions: Mastodon.Mention[]) => - mentions.map(mention => ({ ...mention, _remote: true })) + mentions?.map(mention => ({ ...mention, _remote: true })) } From 646b539949bfb8359f2d86bdb501555afea24799 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Mon, 30 Jan 2023 13:40:43 +0100 Subject: [PATCH 2/5] Improve notify animation --- src/components/Timeline/Refresh.tsx | 35 ++++++++-------------- src/components/Timeline/index.tsx | 46 ++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/components/Timeline/Refresh.tsx b/src/components/Timeline/Refresh.tsx index 221cd6bb..1a183df4 100644 --- a/src/components/Timeline/Refresh.tsx +++ b/src/components/Timeline/Refresh.tsx @@ -20,7 +20,6 @@ import Animated, { SharedValue, useAnimatedReaction, useAnimatedStyle, - useDerivedValue, useSharedValue, withTiming } from 'react-native-reanimated' @@ -28,10 +27,10 @@ import Animated, { export interface Props { flRef: RefObject> queryKey: QueryKeyTimeline - fetchingActive: React.MutableRefObject + isFetchingPrev: SharedValue setFetchedCount: React.Dispatch> - scrollY: Animated.SharedValue - fetchingType: Animated.SharedValue<0 | 1 | 2> + scrollY: SharedValue + fetchingType: SharedValue<0 | 1 | 2> disableRefresh?: boolean readMarker?: 'read_marker_following' } @@ -43,7 +42,7 @@ export const SEPARATION_Y_2 = -(CONTAINER_HEIGHT * 1.5 + StyleConstants.Font.Siz const TimelineRefresh: React.FC = ({ flRef, queryKey, - fetchingActive, + isFetchingPrev, setFetchedCount, scrollY, fetchingType, @@ -58,20 +57,11 @@ const TimelineRefresh: React.FC = ({ } const PREV_PER_BATCH = 1 - const prevActive = useRef(false) const prevCache = useRef<(Mastodon.Status | Mastodon.Notification | Mastodon.Conversation)[]>() const prevStatusId = useRef() const queryClient = useQueryClient() - const { refetch, isRefetching } = useTimelineQuery({ ...queryKey[1] }) - - useDerivedValue(() => { - if (prevActive.current || isRefetching) { - fetchingActive.current = true - } else { - fetchingActive.current = false - } - }, [prevActive.current, isRefetching]) + const { refetch } = useTimelineQuery({ ...queryKey[1] }) const { t } = useTranslation('componentTimeline') const { colors } = useTheme() @@ -99,7 +89,7 @@ const TimelineRefresh: React.FC = ({ const arrowStage = useSharedValue(0) useAnimatedReaction( () => { - if (fetchingActive.current) { + if (isFetchingPrev.value) { return false } switch (arrowStage.value) { @@ -131,13 +121,12 @@ const TimelineRefresh: React.FC = ({ if (data) { runOnJS(haptics)('Light') } - }, - [fetchingActive.current] + } ) const fetchAndScrolled = useSharedValue(false) const runFetchPrevious = async () => { - if (prevActive.current) return + if (isFetchingPrev.value) return const firstPage = queryClient.getQueryData< @@ -146,7 +135,7 @@ const TimelineRefresh: React.FC = ({ > >(queryKey)?.pages[0] - prevActive.current = true + isFetchingPrev.value = true prevStatusId.current = firstPage?.body[0]?.id await queryFunctionTimeline({ @@ -154,7 +143,7 @@ const TimelineRefresh: React.FC = ({ pageParam: firstPage?.links?.prev, meta: {} }) - .then(res => { + .then(async res => { setFetchedCount(res.body.length) if (!res.body.length) return @@ -177,7 +166,7 @@ const TimelineRefresh: React.FC = ({ }) .then(async nextLength => { if (!nextLength) { - prevActive.current = false + isFetchingPrev.value = false return } @@ -214,7 +203,7 @@ const TimelineRefresh: React.FC = ({ } }) } - prevActive.current = false + isFetchingPrev.value = false }) } diff --git a/src/components/Timeline/index.tsx b/src/components/Timeline/index.tsx index 7478727b..c307a131 100644 --- a/src/components/Timeline/index.tsx +++ b/src/components/Timeline/index.tsx @@ -18,6 +18,7 @@ import { FlatList, FlatListProps, Platform, RefreshControl } from 'react-native' import Animated, { Easing, runOnJS, + useAnimatedReaction, useAnimatedScrollHandler, useAnimatedStyle, useDerivedValue, @@ -70,26 +71,44 @@ const Timeline: React.FC = ({ }) const flRef = useRef(null) - const fetchingActive = useRef(false) + const isFetchingPrev = useSharedValue(false) const [fetchedCount, setFetchedCount] = useState(null) const fetchedNoticeHeight = useSharedValue(100) + const notifiedFetchedNotice = useSharedValue(false) + useAnimatedReaction( + () => isFetchingPrev.value, + (curr, prev) => { + if (curr === true && prev === false) { + notifiedFetchedNotice.value = true + } + } + ) + useAnimatedReaction( + () => fetchedCount, + (curr, prev) => { + if (curr !== null && prev === null) { + notifiedFetchedNotice.value = false + } + }, + [fetchedCount] + ) const fetchedNoticeTop = useDerivedValue(() => { - if ((!isLoading && !isRefetching && isFetching) || fetchedCount !== null) { + if (notifiedFetchedNotice.value || fetchedCount !== null) { return withSequence( withTiming(fetchedNoticeHeight.value + 16 + 4), withDelay( 2000, - withTiming(0, { easing: Easing.out(Easing.ease) }, finished => { - if (finished) { - runOnJS(setFetchedCount)(null) - } - }) + withTiming( + 0, + { easing: Easing.out(Easing.ease) }, + finished => finished && runOnJS(setFetchedCount)(null) + ) ) ) } else { return 0 } - }, [isLoading, isRefetching, isFetching, fetchedCount]) + }, [fetchedCount]) const fetchedNoticeAnimate = useAnimatedStyle(() => ({ transform: [{ translateY: fetchedNoticeTop.value }] })) @@ -130,7 +149,12 @@ const Timeline: React.FC = ({ const marker = readMarker ? getAccountStorage.string(readMarker) : undefined const firstItemId = viewableItems.filter(item => item.isViewable)[0]?.item.id - if (!fetchingActive.current && firstItemId && firstItemId > (marker || '0')) { + if ( + !isFetchingPrev.value && + !isRefetching && + firstItemId && + firstItemId > (marker || '0') + ) { setAccountStorage([{ key: readMarker, value: firstItemId }]) } else { // setAccountStorage([{ key: readMarker, value: '109519141378761752' }]) @@ -170,7 +194,7 @@ const Timeline: React.FC = ({ = ({ }) => (fetchedNoticeHeight.value = height)} > Date: Mon, 30 Jan 2023 13:44:29 +0100 Subject: [PATCH 3/5] Fix #683 Affects both platforms --- src/screens/Compose/Root/Footer/Attachments.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/screens/Compose/Root/Footer/Attachments.tsx b/src/screens/Compose/Root/Footer/Attachments.tsx index 3aae6988..4ce53446 100644 --- a/src/screens/Compose/Root/Footer/Attachments.tsx +++ b/src/screens/Compose/Root/Footer/Attachments.tsx @@ -169,7 +169,8 @@ const ComposeAttachments: React.FC = ({ accessibleRefAttachments }) => { haptics('Success') }} /> - {composeState.type === 'edit' && featureCheck('edit_media_details') ? ( + {composeState.type !== 'edit' || + (composeState.type === 'edit' && featureCheck('edit_media_details')) ? (