From 371830ff19a5d2b4164440081047c779d1c7aa8a Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Sun, 29 Aug 2021 16:08:02 +0200 Subject: [PATCH] Done #79 --- src/components/Instance/Auth.tsx | 5 ++++- src/components/Timeline/Shared/Attachment.tsx | 3 ++- src/components/openLink.ts | 20 +------------------ src/utils/navigation/navigators.ts | 4 ++++ 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/components/Instance/Auth.tsx b/src/components/Instance/Auth.tsx index 14ffae4f..765d20ef 100644 --- a/src/components/Instance/Auth.tsx +++ b/src/components/Instance/Auth.tsx @@ -1,4 +1,5 @@ import { useNavigation } from '@react-navigation/native' +import { TabMeStackNavigationProp } from '@utils/navigation/navigators' import addInstance from '@utils/slices/instances/add' import { Instance } from '@utils/slices/instancesSlice' import * as AuthSession from 'expo-auth-session' @@ -21,7 +22,9 @@ const InstanceAuth = React.memo( useProxy: false }) - const navigation = useNavigation() + const navigation = useNavigation< + TabMeStackNavigationProp<'Tab-Me-Root' | 'Tab-Me-Switch'> + >() const queryClient = useQueryClient() const dispatch = useDispatch() diff --git a/src/components/Timeline/Shared/Attachment.tsx b/src/components/Timeline/Shared/Attachment.tsx index aad3c1fc..347709ef 100644 --- a/src/components/Timeline/Shared/Attachment.tsx +++ b/src/components/Timeline/Shared/Attachment.tsx @@ -6,6 +6,7 @@ import AttachmentImage from '@components/Timeline/Shared/Attachment/Image' import AttachmentUnsupported from '@components/Timeline/Shared/Attachment/Unsupported' import AttachmentVideo from '@components/Timeline/Shared/Attachment/Video' import { useNavigation } from '@react-navigation/native' +import { RootStackParamList } from '@utils/navigation/navigators' import { StyleConstants } from '@utils/styles/constants' import layoutAnimation from '@utils/styles/layoutAnimation' import React, { useCallback, useMemo, useRef, useState } from 'react' @@ -35,7 +36,7 @@ const TimelineAttachment = React.memo( }, []) const imageUrls = useRef< - Nav.RootStackParamList['Screen-ImagesViewer']['imageUrls'] + RootStackParamList['Screen-ImagesViewer']['imageUrls'] >([]) const navigation = useNavigation() useEffect(() => { diff --git a/src/components/openLink.ts b/src/components/openLink.ts index cbc07f23..7474ba3c 100644 --- a/src/components/openLink.ts +++ b/src/components/openLink.ts @@ -1,6 +1,5 @@ import apiInstance from '@api/instance' import navigationRef from '@helpers/navigationRef' -import { NavigationProp, ParamListBase } from '@react-navigation/native' import { store } from '@root/store' import { SearchResult } from '@utils/queryHooks/search' import { getInstanceUrl } from '@utils/slices/instancesSlice' @@ -22,24 +21,7 @@ const matcherAccount = new RegExp( export let loadingLink = false -const openLink = async ( - url: string, - navigation?: NavigationProp< - ParamListBase, - string, - Readonly<{ - key: string - index: number - routeNames: string[] - history?: unknown[] | undefined - routes: any[] - type: string - stale: false - }>, - {}, - {} - > -) => { +const openLink = async (url: string, navigation?: any) => { if (loadingLink) { return } diff --git a/src/utils/navigation/navigators.ts b/src/utils/navigation/navigators.ts index c9b35abb..37081cdf 100644 --- a/src/utils/navigation/navigators.ts +++ b/src/utils/navigation/navigators.ts @@ -1,6 +1,7 @@ import { BottomTabScreenProps } from '@react-navigation/bottom-tabs' import { NavigatorScreenParams } from '@react-navigation/native' import { NativeStackScreenProps } from '@react-navigation/native-stack' +import { StackNavigationProp } from '@react-navigation/stack' import { QueryKeyTimeline } from '@utils/queryHooks/timeline' export type RootStackParamList = { @@ -155,6 +156,9 @@ export type TabMeStackParamList = { export type TabMeStackScreenProps< T extends keyof TabMeStackParamList > = NativeStackScreenProps +export type TabMeStackNavigationProp< + RouteName extends keyof TabMeStackParamList +> = StackNavigationProp export type TabMeProfileStackParamList = { 'Tab-Me-Profile-Root': undefined