From 811964e10f9b552c6edf8e73a1809bb27fd86f1c Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Mon, 4 Jan 2021 14:55:34 +0100 Subject: [PATCH] Updates --- src/Index.tsx | 6 +- src/api/client.ts | 1 + src/components/Icon.tsx | 6 +- src/components/Parse/Emojis.tsx | 4 +- src/components/Parse/HTML.tsx | 82 ++++++++----------- src/components/Relationship/Incoming.tsx | 2 +- src/screens/Shared/Compose.tsx | 18 +++- src/screens/Shared/Compose/Attachments.tsx | 23 ++---- .../Shared/Compose/EditAttachment/Image.tsx | 26 ++++-- .../Shared/Compose/EditAttachment/Root.tsx | 12 ++- src/screens/Shared/Compose/addAttachment.ts | 28 +++++-- src/screens/Shared/Compose/utils/post.ts | 8 +- src/screens/Shared/Compose/utils/reducer.ts | 10 +++ src/screens/Shared/Compose/utils/types.d.ts | 6 +- src/utils/styles/constants.ts | 2 +- 15 files changed, 136 insertions(+), 98 deletions(-) diff --git a/src/Index.tsx b/src/Index.tsx index 508518b4..2fd96c70 100644 --- a/src/Index.tsx +++ b/src/Index.tsx @@ -102,7 +102,11 @@ const Index: React.FC = ({ localCorrupt }) => { const queryNotification = useInfiniteQuery( ['Notifications', {}], timelineFetch, - { enabled: localInstance ? true : false } + { + enabled: localInstance ? true : false, + refetchInterval: 1000 * 60, + refetchIntervalInBackground: true + } ) const prevNotification = useSelector(getLocalNotification) useEffect(() => { diff --git a/src/api/client.ts b/src/api/client.ts index fbf09822..3f46730f 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -41,6 +41,7 @@ const client = async ({ instance === 'remote' ? instanceDomain || state.remote.url : state.local.url return axios({ + timeout: method === 'post' ? 1000 * 60 : 1000 * 15, method, baseURL: `https://${domain}/api/${version}/`, url, diff --git a/src/components/Icon.tsx b/src/components/Icon.tsx index 85a5cc2e..5e4e52b2 100644 --- a/src/components/Icon.tsx +++ b/src/components/Icon.tsx @@ -1,3 +1,4 @@ +import { StyleConstants } from '@root/utils/styles/constants' import React, { createElement } from 'react' import { StyleProp, View, ViewStyle } from 'react-native' import * as FeatherIcon from 'react-native-feather' @@ -8,7 +9,6 @@ export interface Props { color: string fill?: string strokeWidth?: number - inline?: boolean // When used in line of text, need to drag it down style?: StyleProp } @@ -18,7 +18,6 @@ const Icon: React.FC = ({ color, fill, strokeWidth = 2, - inline = false, style }) => { return ( @@ -29,8 +28,7 @@ const Icon: React.FC = ({ width: size, height: size, justifyContent: 'center', - alignItems: 'center', - marginBottom: inline ? -size * 0.125 : undefined + alignItems: 'center' } ]} > diff --git a/src/components/Parse/Emojis.tsx b/src/components/Parse/Emojis.tsx index d9305825..e83107fd 100644 --- a/src/components/Parse/Emojis.tsx +++ b/src/components/Parse/Emojis.tsx @@ -27,8 +27,7 @@ const ParseEmojis: React.FC = ({ }, image: { width: StyleConstants.Font.Size[size], - height: StyleConstants.Font.Size[size], - marginBottom: -StyleConstants.Font.Size[size] * 0.125 + height: StyleConstants.Font.Size[size] } }) @@ -51,7 +50,6 @@ const ParseEmojis: React.FC = ({ {/* When emoji starts a paragraph, lineHeight will break */} {i === 0 ? : null} diff --git a/src/components/Parse/HTML.tsx b/src/components/Parse/HTML.tsx index 1d9f4c81..9c10019d 100644 --- a/src/components/Parse/HTML.tsx +++ b/src/components/Parse/HTML.tsx @@ -9,6 +9,8 @@ import React, { useCallback, useMemo, useState } from 'react' import { Pressable, Text, View } from 'react-native' import HTMLView from 'react-native-htmlview' import Animated, { + measure, + useAnimatedRef, useAnimatedStyle, useDerivedValue, useSharedValue, @@ -103,7 +105,6 @@ const renderNode = ({ > {!shouldBeTag ? ( = ({ ) const textComponent = useCallback(({ children }) => { if (children) { - return + return ( + + ) } else { return null } @@ -171,14 +178,15 @@ const ParseHTML: React.FC = ({ ({ children }) => { const lineHeight = StyleConstants.Font.LineHeight[size] + const [lines, setLines] = useState(undefined) const [heightOriginal, setHeightOriginal] = useState() const [heightTruncated, setHeightTruncated] = useState() - const [allowExpand, setAllowExpand] = useState(false) - const [showAllText, setShowAllText] = useState(false) + const [expandAllow, setExpandAllow] = useState(false) + const [expanded, setExpanded] = useState(false) const viewHeight = useDerivedValue(() => { - if (allowExpand) { - if (showAllText) { + if (expandAllow) { + if (expanded) { return heightOriginal as number } else { return heightTruncated as number @@ -186,49 +194,29 @@ const ParseHTML: React.FC = ({ } else { return heightOriginal as number } - }, [heightOriginal, heightTruncated, allowExpand, showAllText]) + }, [heightOriginal, heightTruncated, expandAllow, expanded]) const ViewHeight = useAnimatedStyle(() => { return { - height: allowExpand - ? showAllText + height: expandAllow + ? expanded ? withTiming(viewHeight.value) : withTiming(viewHeight.value) - : undefined + : viewHeight.value } }) - const calNumberOfLines = useMemo(() => { - if (numberOfLines === 0) { - // For spoilers without calculation - return showAllText ? undefined : 1 - } else { - if (heightOriginal) { - if (!heightTruncated) { - return numberOfLines - } else { - return undefined - } - } else { - return undefined - } - } - }, [heightOriginal, heightTruncated, allowExpand, showAllText]) - const onLayout = useCallback( ({ nativeEvent }) => { - if (numberOfLines === 0) { - // For spoilers without calculation - setAllowExpand(true) + if (!heightOriginal) { + setHeightOriginal(nativeEvent.layout.height) + setLines(numberOfLines === 0 ? 1 : numberOfLines) } else { - if (!heightOriginal) { - setHeightOriginal(nativeEvent.layout.height) + if (!heightTruncated) { + setHeightTruncated(nativeEvent.layout.height) + setLines(undefined) } else { - if (!heightTruncated) { - setHeightTruncated(nativeEvent.layout.height) - } else { - if (heightOriginal > heightTruncated) { - setAllowExpand(true) - } + if (heightOriginal > heightTruncated) { + setExpandAllow(true) } } } @@ -239,21 +227,21 @@ const ParseHTML: React.FC = ({ return ( - - {allowExpand ? ( + {expandAllow ? ( setShowAllText(!showAllText)} - style={{ marginTop: showAllText ? 0 : -lineHeight * 1.25 }} + onPress={() => setExpanded(!expanded)} + style={{ marginTop: expanded ? 0 : -lineHeight * 1.25 }} > = ({ color: theme.primary }} > - {`${showAllText ? '折叠' : '展开'}${expandHint}`} + {`${expanded ? '折叠' : '展开'}${expandHint}`} diff --git a/src/components/Relationship/Incoming.tsx b/src/components/Relationship/Incoming.tsx index f0cbcc8d..f013302c 100644 --- a/src/components/Relationship/Incoming.tsx +++ b/src/components/Relationship/Incoming.tsx @@ -32,7 +32,7 @@ const RelationshipIncoming: React.FC = ({ id }) => { onSuccess: ({ body }) => { haptics('Success') queryClient.setQueryData(relationshipQueryKey, body) - queryClient.invalidateQueries(['Notifications', {}]) + queryClient.refetchQueries(['Notifications']) }, onError: (err: any, { type }) => { haptics('Error') diff --git a/src/screens/Shared/Compose.tsx b/src/screens/Shared/Compose.tsx index c48a6675..676afc2d 100644 --- a/src/screens/Shared/Compose.tsx +++ b/src/screens/Shared/Compose.tsx @@ -174,7 +174,23 @@ const Compose: React.FC = ({ route: { params }, navigation }) => { composePost(params, composeState) .then(() => { haptics('Success') - queryClient.invalidateQueries(['Following']) + queryClient.invalidateQueries(['Following', {}]) + if ( + params?.type && + (params.type === 'reply' || params.type === 'conversation') + ) { + queryClient.invalidateQueries( + [ + 'Toot', + { + toot: params.incomingStatus.reblog + ? params.incomingStatus.reblog.id + : params.incomingStatus.id + } + ], + { exact: true, active: true } + ) + } navigation.goBack() }) .catch(() => { diff --git a/src/screens/Shared/Compose/Attachments.tsx b/src/screens/Shared/Compose/Attachments.tsx index dc9cb14c..6c8a6684 100644 --- a/src/screens/Shared/Compose/Attachments.tsx +++ b/src/screens/Shared/Compose/Attachments.tsx @@ -141,19 +141,18 @@ const ComposeAttachments: React.FC = () => { ]} > ) : ( - <> +