From 177afe1dd19f20b677325b6820bd94576c2c865f Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Mon, 14 Dec 2020 22:33:19 +0100 Subject: [PATCH] Fix back button Using customized component, need to get `navigation` from props instead of hooks --- app.config.ts | 18 +++++----- src/api/client.ts | 2 +- src/components/BottomSheet.tsx | 16 ++++++--- src/components/Header/Left.tsx | 20 ++++++++--- src/components/Header/Right.tsx | 2 +- src/components/Menu/Header.tsx | 5 ++- src/components/Timelines.tsx | 2 +- src/components/Timelines/Timeline.tsx | 9 +---- .../Timelines/Timeline/Conversation.tsx | 2 +- src/components/Timelines/Timeline/Default.tsx | 35 ++++++++++++------- .../Timelines/Timeline/Notifications.tsx | 2 +- .../Timelines/Timeline/Shared/Avatar.tsx | 10 +++--- .../Timeline/Shared/HeaderDefault.tsx | 2 +- src/screens/Me.tsx | 24 ++++++------- src/screens/Me/Root/Login.tsx | 1 - src/screens/Shared/Compose.tsx | 5 ++- src/screens/Shared/Compose/EditAttachment.tsx | 7 ++-- src/screens/Shared/Webview.tsx | 6 ++-- src/screens/Shared/sharedScreens.tsx | 10 +++--- 19 files changed, 98 insertions(+), 80 deletions(-) diff --git a/app.config.ts b/app.config.ts index 439d063f..7d440467 100644 --- a/app.config.ts +++ b/app.config.ts @@ -13,7 +13,7 @@ export default (): ExpoConfig => ({ developmentClient: { silentLaunch: true }, scheme: 'mastodonct', ios: { - bundleIdentifier: 'com.xmflsct.mastodon-app', + bundleIdentifier: 'com.xmflsct.mastodon', infoPlist: { CFBundleAllowMixedLocalizations: true }, @@ -23,13 +23,13 @@ export default (): ExpoConfig => ({ backgroundColor: '#ffffff' } }, - locales: { - zh: { - CFBundleDisplayName: '我的嘟嘟' - }, - en: { - CFBundleDisplayName: 'My Toots' - } - }, + // locales: { + // zh: { + // CFBundleDisplayName: '我的嘟嘟' + // }, + // en: { + // CFBundleDisplayName: 'My Toots' + // } + // }, assetBundlePatterns: ['assets/*'] }) diff --git a/src/api/client.ts b/src/api/client.ts index 5e6385cb..4231e991 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -1,5 +1,5 @@ import axios from 'axios' -import { store, RootState } from 'src/store' +import { store, RootState } from '@root/store' const client = async ({ method, diff --git a/src/components/BottomSheet.tsx b/src/components/BottomSheet.tsx index a77af39a..03ab7521 100644 --- a/src/components/BottomSheet.tsx +++ b/src/components/BottomSheet.tsx @@ -67,7 +67,7 @@ const BottomSheet: React.FC = ({ children, visible, handleDismiss }) => { return ( = ({ children, visible, handleDismiss }) => { style={[styles.handle, { backgroundColor: theme.background }]} /> {children} - closeModal.start(() => handleDismiss())} - text='取消' - /> + + closeModal.start(() => handleDismiss())} + text='取消' + /> + @@ -108,6 +110,10 @@ const styles = StyleSheet.create({ height: StyleConstants.Spacing.S / 2, borderRadius: 100, top: -StyleConstants.Spacing.M * 2 + }, + button: { + paddingLeft: StyleConstants.Spacing.Global.PagePadding * 2, + paddingRight: StyleConstants.Spacing.Global.PagePadding * 2 } }) diff --git a/src/components/Header/Left.tsx b/src/components/Header/Left.tsx index 2d9fc6f6..4a124fd0 100644 --- a/src/components/Header/Left.tsx +++ b/src/components/Header/Left.tsx @@ -5,13 +5,25 @@ import { Pressable, StyleSheet, Text } from 'react-native' import { useTheme } from '@utils/styles/ThemeManager' import { StyleConstants } from '@utils/styles/constants' -export interface Props { +type PropsBase = { onPress: () => void - text?: string +} + +export interface PropsText extends PropsBase { + text: string icon?: any } -const HeaderLeft: React.FC = ({ onPress, text, icon }) => { +export interface PropsIcon extends PropsBase { + text?: string + icon: any +} + +const HeaderLeft: React.FC = ({ + onPress, + text, + icon +}) => { const { theme } = useTheme() return ( @@ -21,7 +33,7 @@ const HeaderLeft: React.FC = ({ onPress, text, icon }) => { styles.base, { backgroundColor: theme.backgroundGradientStart, - ...(icon && { height: 44, width: 44 }) + ...(icon && { height: 44, width: 44, marginLeft: -9 }) } ]} > diff --git a/src/components/Header/Right.tsx b/src/components/Header/Right.tsx index b12e1b34..991c0c61 100644 --- a/src/components/Header/Right.tsx +++ b/src/components/Header/Right.tsx @@ -35,7 +35,7 @@ const HeaderRight: React.FC = ({ styles.base, { backgroundColor: theme.backgroundGradientStart, - ...(icon && { height: 44, width: 44 }) + ...(icon && { height: 44, width: 44, marginRight: -9 }) } ]} > diff --git a/src/components/Menu/Header.tsx b/src/components/Menu/Header.tsx index 76be5ede..a908206f 100644 --- a/src/components/Menu/Header.tsx +++ b/src/components/Menu/Header.tsx @@ -12,7 +12,7 @@ const MenuHeader: React.FC = ({ heading }) => { return ( - {heading} + {heading} ) } @@ -23,6 +23,9 @@ const styles = StyleSheet.create({ paddingLeft: StyleConstants.Spacing.Global.PagePadding, paddingRight: StyleConstants.Spacing.Global.PagePadding, paddingBottom: StyleConstants.Spacing.S + }, + text: { + fontSize: StyleConstants.Font.Size.S } }) diff --git a/src/components/Timelines.tsx b/src/components/Timelines.tsx index 175e7107..e6a3f875 100644 --- a/src/components/Timelines.tsx +++ b/src/components/Timelines.tsx @@ -42,7 +42,7 @@ export interface Props { const Timelines: React.FC = ({ name, content }) => { const navigation = useNavigation() - const { mode, theme } = useTheme() + const { mode } = useTheme() const localRegistered = useSelector(getLocalUrl) const publicDomain = useSelector(getRemoteUrl) const [segment, setSegment] = useState(0) diff --git a/src/components/Timelines/Timeline.tsx b/src/components/Timelines/Timeline.tsx index db1d5404..ae682888 100644 --- a/src/components/Timelines/Timeline.tsx +++ b/src/components/Timelines/Timeline.tsx @@ -61,14 +61,7 @@ const Timeline: React.FC = ({ fetchMore, refetch } = useInfiniteQuery(queryKey, timelineFetch, { - getFetchMore: (last, all) => { - const allLastGroup = all[all.length - 1]! - return ( - last?.toots.length > 0 && - allLastGroup.toots[allLastGroup.toots.length - 1].id !== - last?.toots[last?.toots.length - 1].id - ) - } + getFetchMore: last => last?.toots.length > 0 }) const flattenData = data ? data.flatMap(d => [...d?.toots]) : [] const flattenPointer = data ? data.flatMap(d => [d?.pointer]) : [] diff --git a/src/components/Timelines/Timeline/Conversation.tsx b/src/components/Timelines/Timeline/Conversation.tsx index 4b18b4ed..e21c80d6 100644 --- a/src/components/Timelines/Timeline/Conversation.tsx +++ b/src/components/Timelines/Timeline/Conversation.tsx @@ -53,7 +53,7 @@ const TimelineConversation: React.FC = ({ return ( - + = ({ queryKey, highlighted = false }) => { + const isRemotePublic = queryKey[0] === 'RemotePublic' const navigation = useNavigation() let actualStatus = item.reblog ? item.reblog : item @@ -38,6 +39,7 @@ const TimelineDefault: React.FC = ({ const tootOnPress = useCallback( () => + !isRemotePublic && navigation.navigate('Screen-Shared-Toot', { toot: actualStatus }), @@ -75,20 +77,29 @@ const TimelineDefault: React.FC = ({ )} - - + + - + - - - + + {!isRemotePublic && ( + + + + )} ) } diff --git a/src/components/Timelines/Timeline/Notifications.tsx b/src/components/Timelines/Timeline/Notifications.tsx index cdb564aa..f0afbda4 100644 --- a/src/components/Timelines/Timeline/Notifications.tsx +++ b/src/components/Timelines/Timeline/Notifications.tsx @@ -86,7 +86,7 @@ const TimelineNotifications: React.FC = ({ /> - + diff --git a/src/components/Timelines/Timeline/Shared/Avatar.tsx b/src/components/Timelines/Timeline/Shared/Avatar.tsx index 552f6669..5a2ad366 100644 --- a/src/components/Timelines/Timeline/Shared/Avatar.tsx +++ b/src/components/Timelines/Timeline/Shared/Avatar.tsx @@ -4,16 +4,18 @@ import { useNavigation } from '@react-navigation/native' import { StyleConstants } from '@utils/styles/constants' export interface Props { + queryKey?: App.QueryKey account: Mastodon.Account } -const TimelineAvatar: React.FC = ({ account }) => { +const TimelineAvatar: React.FC = ({ queryKey, account }) => { const navigation = useNavigation() // Need to fix go back root const onPress = useCallback(() => { - navigation.navigate('Screen-Shared-Account', { - id: account.id - }) + queryKey && + navigation.navigate('Screen-Shared-Account', { + id: account.id + }) }, []) return ( diff --git a/src/components/Timelines/Timeline/Shared/HeaderDefault.tsx b/src/components/Timelines/Timeline/Shared/HeaderDefault.tsx index 684269f3..c01f4ae7 100644 --- a/src/components/Timelines/Timeline/Shared/HeaderDefault.tsx +++ b/src/components/Timelines/Timeline/Shared/HeaderDefault.tsx @@ -61,7 +61,7 @@ const TimelineHeaderDefault: React.FC = ({ queryKey, status }) => { return ( - + {emojis?.length ? ( { - const navigation = useNavigation() const { t } = useTranslation() return ( @@ -34,7 +32,7 @@ const ScreenMe: React.FC = () => { ({ headerTitle: t('meConversations:heading'), headerLeft: () => ( { onPress={() => navigation.goBack()} /> ) - }} + })} /> ({ headerTitle: t('meBookmarks:heading'), headerLeft: () => ( { onPress={() => navigation.goBack()} /> ) - }} + })} /> ({ headerTitle: t('meFavourites:heading'), headerLeft: () => ( { onPress={() => navigation.goBack()} /> ) - }} + })} /> ({ headerTitle: t('meLists:heading'), headerLeft: () => ( { onPress={() => navigation.goBack()} /> ) - }} + })} /> ({ + options={({ route, navigation }: any) => ({ headerTitle: t('meListsList:heading', { list: route.params.title }), headerLeft: () => ( { ({ headerTitle: t('meSettings:heading'), headerLeft: () => ( { onPress={() => navigation.goBack()} /> ) - }} + })} /> {sharedScreens(Stack)} diff --git a/src/screens/Me/Root/Login.tsx b/src/screens/Me/Root/Login.tsx index 8bac8f3c..6ef33042 100644 --- a/src/screens/Me/Root/Login.tsx +++ b/src/screens/Me/Root/Login.tsx @@ -185,7 +185,6 @@ const Login: React.FC = () => { onChangeText={onChangeText} autoCapitalize='none' autoCorrect={false} - autoFocus clearButtonMode='never' keyboardType='url' textContentType='URL' diff --git a/src/screens/Shared/Compose.tsx b/src/screens/Shared/Compose.tsx index c49a2d2a..a9765517 100644 --- a/src/screens/Shared/Compose.tsx +++ b/src/screens/Shared/Compose.tsx @@ -19,7 +19,6 @@ import { } from 'react-native' import { SafeAreaView } from 'react-native-safe-area-context' import { createNativeStackNavigator } from 'react-native-screens/native-stack' -import { useNavigation } from '@react-navigation/native' import sha256 from 'crypto-js/sha256' import { store } from '@root/store' @@ -308,10 +307,10 @@ export interface Props { } | undefined } + navigation: any } -const Compose: React.FC = ({ route: { params } }) => { - const navigation = useNavigation() +const Compose: React.FC = ({ route: { params }, navigation }) => { const { theme } = useTheme() const [hasKeyboard, setHasKeyboard] = useState(false) diff --git a/src/screens/Shared/Compose/EditAttachment.tsx b/src/screens/Shared/Compose/EditAttachment.tsx index c51aeea5..c4fb33b3 100644 --- a/src/screens/Shared/Compose/EditAttachment.tsx +++ b/src/screens/Shared/Compose/EditAttachment.tsx @@ -1,4 +1,3 @@ -import { useNavigation } from '@react-navigation/native' import React, { Dispatch, useCallback, @@ -39,15 +38,15 @@ export interface Props { composeDispatch: Dispatch } } + navigation: any } const ComposeEditAttachment: React.FC = ({ route: { params: { attachment, composeDispatch } - } + }, + navigation }) => { - const navigation = useNavigation() - const { theme } = useTheme() const [altText, setAltText] = useState( diff --git a/src/screens/Shared/Webview.tsx b/src/screens/Shared/Webview.tsx index 7e1ae790..a4ed24a3 100644 --- a/src/screens/Shared/Webview.tsx +++ b/src/screens/Shared/Webview.tsx @@ -1,4 +1,3 @@ -import { useNavigation } from '@react-navigation/native' import React, { useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { ActionSheetIOS } from 'react-native' @@ -24,7 +23,6 @@ const ScreenSharedWebview: React.FC = ({ params: { uri } } }) => { - const navigation = useNavigation() const { t } = useTranslation('sharedWebview') const [title, setTitle] = useState(t('heading.loading')) const [bottomSheet, showBottomSheet] = useState(false) @@ -34,7 +32,7 @@ const ScreenSharedWebview: React.FC = ({ ({ title, headerLeft: () => ( = ({ onPress={() => showBottomSheet(true)} /> ) - }} + })} > {() => ( <> diff --git a/src/screens/Shared/sharedScreens.tsx b/src/screens/Shared/sharedScreens.tsx index 1d691274..935f7589 100644 --- a/src/screens/Shared/sharedScreens.tsx +++ b/src/screens/Shared/sharedScreens.tsx @@ -8,11 +8,9 @@ import Compose from '@screens/Shared/Compose' import ComposeEditAttachment from '@screens/Shared/Compose/EditAttachment' import ScreenSharedSearch from '@screens/Shared/Search' import { useTranslation } from 'react-i18next' -import { useNavigation } from '@react-navigation/native' import { HeaderLeft } from '@root/components/Header' const sharedScreens = (Stack: any) => { - const navigation = useNavigation() const { t } = useTranslation() return [ @@ -20,20 +18,20 @@ const sharedScreens = (Stack: any) => { key='Screen-Shared-Account' name='Screen-Shared-Account' component={ScreenSharedAccount} - options={{ + options={({ navigation }: any) => ({ headerTranslucent: true, headerStyle: { backgroundColor: 'rgba(255, 255, 255, 0)' }, headerCenter: () => null, headerLeft: () => ( navigation.goBack()} /> ) - }} + })} />, ({ + options={({ route, navigation }: any) => ({ title: `#${decodeURIComponent(route.params.hashtag)}`, headerLeft: () => ( navigation.goBack()} /> @@ -44,7 +42,7 @@ const sharedScreens = (Stack: any) => { key='Screen-Shared-Toot' name='Screen-Shared-Toot' component={ScreenSharedToot} - options={() => ({ + options={({ navigation }: any) => ({ title: t('sharedToot:heading'), headerLeft: () => ( navigation.goBack()} />