From 122dae74043dd4be3f56ffde77f42e8a298e2c92 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Sun, 29 Aug 2021 15:25:38 +0200 Subject: [PATCH] Basic new react-navigation types --- ios/Podfile.lock | 29 +- package.json | 26 +- src/@types/react-navigation.d.ts | 152 ---- src/Screens.tsx | 15 +- src/api/general.ts | 2 +- src/api/instance.ts | 2 +- src/components/Account.tsx | 3 +- src/components/Timeline/Default.tsx | 3 +- src/components/openLink.ts | 2 +- src/helpers/navigationRef.ts | 6 +- src/screens/Actions.tsx | 244 +++++- src/screens/Actions/Root.tsx | 241 ------ src/screens/Actions/Status.tsx | 5 +- src/screens/Announcements.tsx | 9 +- src/screens/Compose.tsx | 9 +- src/screens/Compose/DraftsList.tsx | 9 +- src/screens/Compose/EditAttachment.tsx | 9 +- src/screens/Compose/Root/Drafts.tsx | 2 +- .../Compose/Root/Footer/Attachments.tsx | 2 +- src/screens/Compose/utils/parseState.ts | 3 +- src/screens/Compose/utils/post.ts | 3 +- src/screens/ImageViewer/Root.tsx | 9 +- src/screens/ImageViewer/save.ts | 3 +- src/screens/ImagesViewer.tsx | 20 +- src/screens/Tabs.tsx | 23 +- src/screens/Tabs/Local.tsx | 19 +- src/screens/Tabs/Me.tsx | 7 +- src/screens/Tabs/Me/Lists.tsx | 9 +- src/screens/Tabs/Me/ListsList.tsx | 7 +- src/screens/Tabs/Me/Profile.tsx | 14 +- src/screens/Tabs/Me/Profile/Fields.tsx | 5 +- src/screens/Tabs/Me/Profile/Name.tsx | 5 +- src/screens/Tabs/Me/Profile/Note.tsx | 5 +- src/screens/Tabs/Me/Profile/Root.tsx | 5 +- src/screens/Tabs/Me/Root/Collections.tsx | 2 +- src/screens/Tabs/Me/Root/Settings.tsx | 2 +- src/screens/Tabs/Me/Root/Switch.tsx | 2 +- src/screens/Tabs/Me/Settings/Analytics.tsx | 2 +- src/screens/Tabs/Me/Settings/App.tsx | 2 +- src/screens/Tabs/Me/Settings/Tooot.tsx | 2 +- src/screens/Tabs/Me/SettingsFontsize.tsx | 7 +- src/screens/Tabs/Notifications.tsx | 12 +- src/screens/Tabs/Public.tsx | 19 +- src/screens/Tabs/Shared/Account.tsx | 6 +- .../Tabs/Shared/Account/Attachments.tsx | 3 +- .../Shared/Account/Information/Actions.tsx | 4 +- .../Shared/Account/Information/Avatar.tsx | 3 +- .../Tabs/Shared/Account/Information/Stats.tsx | 3 +- src/screens/Tabs/Shared/Attachments.tsx | 6 +- src/screens/Tabs/Shared/Hashtag.tsx | 6 +- .../Shared/{sharedScreens.tsx => Root.tsx} | 100 +-- src/screens/Tabs/Shared/Search.tsx | 6 +- src/screens/Tabs/Shared/Toot.tsx | 4 +- src/screens/Tabs/Shared/Users.tsx | 4 +- src/store.ts | 34 +- src/utils/navigation/navigators.ts | 173 ++++ src/utils/push/useConnect.ts | 15 +- src/utils/push/useNavigate.ts | 11 +- src/utils/push/useReceive.ts | 6 +- src/utils/push/useRespond.ts | 11 +- src/utils/queryHooks/timeline.ts | 14 +- src/utils/queryHooks/users.ts | 3 +- src/utils/slices/instances/add.ts | 8 + .../slices/instances/updatePushDecode.ts | 4 +- src/utils/slices/instancesSlice.ts | 2 +- src/utils/slices/settingsSlice.ts | 4 +- src/utils/slices/versionSlice.ts | 2 +- yarn.lock | 774 ++++++++++-------- 68 files changed, 1099 insertions(+), 1064 deletions(-) delete mode 100644 src/@types/react-navigation.d.ts delete mode 100644 src/screens/Actions/Root.tsx rename src/screens/Tabs/Shared/{sharedScreens.tsx => Root.tsx} (72%) create mode 100644 src/utils/navigation/navigators.ts diff --git a/ios/Podfile.lock b/ios/Podfile.lock index bfd15c88..bebafcac 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -47,6 +47,9 @@ PODS: - EXNotifications (0.12.3): - ExpoModulesCore - UMCore + - EXPermissions (12.1.1): + - ExpoModulesCore + - UMCore - ExpoModulesCore (0.2.0): - ExpoModulesCore/Core (= 0.2.0) - ExpoModulesCore/Interfaces (= 0.2.0) @@ -377,9 +380,9 @@ PODS: - React-Core - react-native-cameraroll (4.0.4): - React-Core - - react-native-netinfo (6.0.0): + - react-native-netinfo (6.0.1): - React-Core - - react-native-pager-view (5.4.0): + - react-native-pager-view (5.4.1): - React-Core - react-native-safe-area-context (3.2.0): - React-Core @@ -449,10 +452,8 @@ PODS: - React-cxxreact (= 0.64.2) - React-jsi (= 0.64.2) - React-perflogger (= 0.64.2) - - RNCAsyncStorage (1.15.6): + - RNCAsyncStorage (1.15.7): - React-Core - - RNCMaskedView (0.1.11): - - React - RNFastImage (8.3.7): - React-Core - SDWebImage (~> 5.8) @@ -488,7 +489,7 @@ PODS: - React-RCTVibration - ReactCommon/turbomodule/core - Yoga - - RNScreens (3.5.0): + - RNScreens (3.6.0): - React-Core - React-RCTImage - RNSentry (2.6.2): @@ -534,6 +535,7 @@ DEPENDENCIES: - EXKeepAwake (from `../node_modules/expo-keep-awake/ios`) - EXLocalization (from `../node_modules/expo-localization/ios`) - EXNotifications (from `../node_modules/expo-notifications/ios`) + - EXPermissions (from `../node_modules/expo-permissions/ios`) - ExpoModulesCore (from `../node_modules/expo-modules-core/ios`) - EXRandom (from `../node_modules/expo-random/ios`) - EXScreenCapture (from `../node_modules/expo-screen-capture/ios`) @@ -584,7 +586,6 @@ DEPENDENCIES: - React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`) - ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`) - "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)" - - "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)" - RNFastImage (from `../node_modules/react-native-fast-image`) - RNGestureHandler (from `../node_modules/react-native-gesture-handler`) - RNReanimated (from `../node_modules/react-native-reanimated`) @@ -654,6 +655,8 @@ EXTERNAL SOURCES: :path: "../node_modules/expo-localization/ios" EXNotifications: :path: "../node_modules/expo-notifications/ios" + EXPermissions: + :path: "../node_modules/expo-permissions/ios" ExpoModulesCore: :path: "../node_modules/expo-modules-core/ios" EXRandom: @@ -744,8 +747,6 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon" RNCAsyncStorage: :path: "../node_modules/@react-native-async-storage/async-storage" - RNCMaskedView: - :path: "../node_modules/@react-native-community/masked-view" RNFastImage: :path: "../node_modules/react-native-fast-image" RNGestureHandler: @@ -789,6 +790,7 @@ SPEC CHECKSUMS: EXKeepAwake: f4105ef469be7b283f66ce2d7234bb71ac80cd26 EXLocalization: 356f4e16a606cec21a77d6250528fde526152b45 EXNotifications: 171ccaf17643811673c78f4c4830560d6e5a92aa + EXPermissions: 916efb5b817cb0a40160c0cd2f369af3c23a78be ExpoModulesCore: 2734852616127a6c1fc23012197890a6f3763dc7 EXRandom: ecb71f5d01991f29bb0277f8a2c35d168f85d637 EXScreenCapture: c51844407fbac8bbca4415467bc43f2b7764d225 @@ -830,8 +832,8 @@ SPEC CHECKSUMS: react-native-blur: cad4d93b364f91e7b7931b3fa935455487e5c33c react-native-blurhash: d978f8017ed091d9e1179775fe7bac14297e6e1e react-native-cameraroll: 88f4e62d9ecd0e1f253abe4f685474f2ea14bfa2 - react-native-netinfo: e849fc21ca2f4128a5726c801a82fc6f4a6db50d - react-native-pager-view: 54970cc27fdef14db2dcfedadb091d711e88065d + react-native-netinfo: 7cb7877ff31ebeb3d03ce0b4fbb616f121ddd859 + react-native-pager-view: 43f51f45f37ec9715f6c188e4af46ccdf79872e8 react-native-safe-area-context: f0906bf8bc9835ac9a9d3f97e8bde2a997d8da79 react-native-segmented-control: 65df6cd0619b780b3843d574a72d4c7cec396097 React-perflogger: 25373e382fed75ce768a443822f07098a15ab737 @@ -846,12 +848,11 @@ SPEC CHECKSUMS: React-RCTVibration: 24600e3b1aaa77126989bc58b6747509a1ba14f3 React-runtimeexecutor: a9904c6d0218fb9f8b19d6dd88607225927668f9 ReactCommon: 149906e01aa51142707a10665185db879898e966 - RNCAsyncStorage: b7c6564ce662366dd44d0189456183ef7eda2d4d - RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489 + RNCAsyncStorage: 7102fe8985f889579a3ae148d957bbb3f308122b RNFastImage: a7384db75df352500261e8e8f1ac2026def26102 RNGestureHandler: a479ebd5ed4221a810967000735517df0d2db211 RNReanimated: 9c13c86454bfd54dab7505c1a054470bfecd2563 - RNScreens: 01ab149b5dd5c27f5ff26741b1d2bdf2cee1af35 + RNScreens: eb0dfb2d6b21d2d7f980ad46b14eb306d2f1062e RNSentry: 68644ef607b780551cc555f084869764f2566652 RNSVG: 551acb6562324b1d52a4e0758f7ca0ec234e278f SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d diff --git a/package.json b/package.json index 45fe61f1..3145d6d7 100644 --- a/package.json +++ b/package.json @@ -26,11 +26,10 @@ "dependencies": { "@expo/react-native-action-sheet": "3.10.0", "@neverdull-agency/expo-unlimited-secure-store": "1.0.10", - "@react-native-async-storage/async-storage": "1.15.6", + "@react-native-async-storage/async-storage": "1.15.7", "@react-native-community/blur": "3.6.0", "@react-native-community/cameraroll": "4.0.4", - "@react-native-community/masked-view": "0.1.11", - "@react-native-community/netinfo": "6.0.0", + "@react-native-community/netinfo": "6.0.1", "@react-native-community/segmented-control": "2.2.2", "@react-navigation/bottom-tabs": "6.0.5", "@react-navigation/native": "6.0.2", @@ -52,6 +51,7 @@ "expo-linking": "2.3.1", "expo-localization": "10.2.0", "expo-notifications": "0.12.3", + "expo-permissions": "^12.1.1", "expo-random": "11.2.0", "expo-screen-capture": "3.2.0", "expo-secure-store": "10.2.0", @@ -75,10 +75,10 @@ "react-native-flash-message": "0.1.23", "react-native-gesture-handler": "1.10.3", "react-native-htmlview": "0.16.0", - "react-native-pager-view": "5.4.0", + "react-native-pager-view": "5.4.1", "react-native-reanimated": "2.2.0", "react-native-safe-area-context": "3.2.0", - "react-native-screens": "3.5.0", + "react-native-screens": "3.6.0", "react-native-svg": "12.1.1", "react-native-swipe-list-view": "3.2.9", "react-native-tab-view": "3.1.1", @@ -96,8 +96,8 @@ "@babel/core": "7.15.0", "@babel/plugin-proposal-optional-chaining": "7.14.5", "@babel/preset-typescript": "7.15.0", - "@expo/config": "5.0.8", - "@jest/types": "27.0.6", + "@expo/config": "5.0.9", + "@jest/types": "27.1.0", "@testing-library/jest-native": "4.0.2", "@testing-library/react-hooks": "7.0.1", "@testing-library/react-native": "7.2.0", @@ -111,19 +111,19 @@ "@types/react-test-renderer": "17.0.1", "@types/react-timeago": "4.1.3", "@types/valid-url": "1.0.3", - "@welldone-software/why-did-you-render": "6.2.0", - "babel-jest": "27.0.6", + "@welldone-software/why-did-you-render": "6.2.1", + "babel-jest": "27.1.0", "babel-plugin-module-resolver": "4.1.0", "babel-plugin-transform-remove-console": "6.9.4", "chalk": "4.1.2", "dotenv": "10.0.0", - "jest": "27.0.6", + "jest": "27.1.0", "jest-expo": "42.1.0", - "nock": "13.1.2", - "react-native-clean-project": "3.6.4", + "nock": "13.1.3", + "react-native-clean-project": "3.6.7", "react-navigation": "4.4.4", "react-navigation-stack": "2.10.4", "react-test-renderer": "17.0.2", - "typescript": "4.3.5" + "typescript": "4.4.2" } } diff --git a/src/@types/react-navigation.d.ts b/src/@types/react-navigation.d.ts deleted file mode 100644 index 5f522ea1..00000000 --- a/src/@types/react-navigation.d.ts +++ /dev/null @@ -1,152 +0,0 @@ -declare namespace Nav { - type RootStackParamList = { - 'Screen-Tabs': undefined - 'Screen-Actions': - | { - type: 'status' - queryKey: QueryKeyTimeline - rootQueryKey?: QueryKeyTimeline - status: Mastodon.Status - } - | { - type: 'account' - account: Mastodon.Account - } - | { - type: 'notifications_filter' - } - 'Screen-Announcements': { showAll: boolean } - 'Screen-Compose': - | { - type: 'edit' - incomingStatus: Mastodon.Status - replyToStatus?: Mastodon.Status - queryKey?: [ - 'Timeline', - { - page: App.Pages - hashtag?: Mastodon.Tag['name'] - list?: Mastodon.List['id'] - toot?: Mastodon.Status['id'] - account?: Mastodon.Account['id'] - } - ] - } - | { - type: 'reply' - incomingStatus: Mastodon.Status - accts: Mastodon.Account['acct'][] - queryKey?: [ - 'Timeline', - { - page: App.Pages - hashtag?: Mastodon.Tag['name'] - list?: Mastodon.List['id'] - toot?: Mastodon.Status['id'] - account?: Mastodon.Account['id'] - } - ] - } - | { - type: 'conversation' - accts: Mastodon.Account['acct'][] - } - | undefined - 'Screen-ImagesViewer': { - imageUrls: { - id: Mastodon.Attachment['id'] - preview_url: Mastodon.AttachmentImage['preview_url'] - url: Mastodon.AttachmentImage['url'] - remote_url?: Mastodon.AttachmentImage['remote_url'] - blurhash: Mastodon.AttachmentImage['blurhash'] - width?: number - height?: number - }[] - id: Mastodon.Attachment['id'] - } - } - - type ScreenComposeStackParamList = { - 'Screen-Compose-Root': undefined - 'Screen-Compose-EditAttachment': { index: number } - 'Screen-Compose-DraftsList': { timestamp: number } - } - - type ScreenTabsStackParamList = { - 'Tab-Local': undefined - 'Tab-Public': undefined - 'Tab-Compose': undefined - 'Tab-Notifications': undefined - 'Tab-Me': undefined - } - - type TabSharedStackParamList = { - 'Tab-Shared-Account': { - account: Mastodon.Account | Mastodon.Mention - } - 'Tab-Shared-Attachments': { account: Mastodon.Account } - 'Tab-Shared-Hashtag': { - hashtag: Mastodon.Tag['name'] - } - 'Tab-Shared-Search': { text: string | undefined } - 'Tab-Shared-Toot': { - toot: Mastodon.Status - rootQueryKey?: QueryKeyTimeline - } - 'Tab-Shared-Users': - | { - reference: 'accounts' - id: Mastodon.Account['id'] - type: 'following' | 'followers' - count: number - } - | { - reference: 'statuses' - id: Mastodon.Status['id'] - type: 'reblogged_by' | 'favourited_by' - count: number - } - } - - type TabLocalStackParamList = { - 'Tab-Local-Root': undefined - } & TabSharedStackParamList - - type TabPublicStackParamList = { - 'Tab-Public-Root': undefined - } & TabSharedStackParamList - - type TabNotificationsStackParamList = { - 'Tab-Notifications-Root': undefined - } & TabSharedStackParamList - - type TabMeStackParamList = { - 'Tab-Me-Root': undefined - 'Tab-Me-Bookmarks': undefined - 'Tab-Me-Conversations': undefined - 'Tab-Me-Favourites': undefined - 'Tab-Me-Lists': undefined - 'Tab-Me-Lists-List': { - list: Mastodon.List['id'] - title: Mastodon.List['title'] - } - 'Tab-Me-Profile': undefined - 'Tab-Me-Push': undefined - 'Tab-Me-Settings': undefined - 'Tab-Me-Settings-Fontsize': undefined - 'Tab-Me-Switch': undefined - } & TabSharedStackParamList - - type TabMeProfileStackParamList = { - 'Tab-Me-Profile-Root': undefined - 'Tab-Me-Profile-Name': { - display_name: Mastodon.Account['display_name'] - } - 'Tab-Me-Profile-Note': { - note: Mastodon.Source['note'] - } - 'Tab-Me-Profile-Fields': { - fields?: Mastodon.Source['fields'] - } - } -} diff --git a/src/Screens.tsx b/src/Screens.tsx index 6603fddd..b5fc58f5 100644 --- a/src/Screens.tsx +++ b/src/Screens.tsx @@ -9,6 +9,7 @@ import ScreenAnnouncements from '@screens/Announcements' import ScreenCompose from '@screens/Compose' import ScreenImagesViewer from '@screens/ImagesViewer' import ScreenTabs from '@screens/Tabs' +import { RootStackParamList } from '@utils/navigation/navigators' import pushUseConnect from '@utils/push/useConnect' import pushUseReceive from '@utils/push/useReceive' import pushUseRespond from '@utils/push/useRespond' @@ -27,7 +28,7 @@ import { onlineManager, useQueryClient } from 'react-query' import { useDispatch, useSelector } from 'react-redux' import * as Sentry from 'sentry-expo' -const Stack = createNativeStackNavigator() +const Stack = createNativeStackNavigator() export interface Props { localCorrupt?: string @@ -71,9 +72,9 @@ const Screens: React.FC = ({ localCorrupt }) => { (prev, next) => prev.length === next.length ) const queryClient = useQueryClient() - pushUseConnect({ navigationRef, mode, t, instances, dispatch }) - pushUseReceive({ navigationRef, queryClient, instances }) - pushUseRespond({ navigationRef, queryClient, instances, dispatch }) + pushUseConnect({ mode, t, instances, dispatch }) + pushUseReceive({ queryClient, instances }) + pushUseRespond({ queryClient, instances, dispatch }) // Prevent screenshot alert useEffect(() => { @@ -96,7 +97,7 @@ const Screens: React.FC = ({ localCorrupt }) => { type: 'error', mode }) - navigationRef.current?.navigate('Screen-Tabs', { + navigationRef.navigate('Screen-Tabs', { screen: 'Tab-Me' }) } @@ -114,7 +115,7 @@ const Screens: React.FC = ({ localCorrupt }) => { // Callbacks const navigationContainerOnReady = useCallback(() => { - const currentRoute = navigationRef.current?.getCurrentRoute() + const currentRoute = navigationRef.getCurrentRoute() routeRef.current = { name: currentRoute?.name, params: currentRoute?.params @@ -124,7 +125,7 @@ const Screens: React.FC = ({ localCorrupt }) => { }, []) const navigationContainerOnStateChange = useCallback(() => { const previousRoute = routeRef.current - const currentRoute = navigationRef.current?.getCurrentRoute() + const currentRoute = navigationRef.getCurrentRoute() const matchTabName = currentRoute?.name?.match(/(Tab-.*)-Root/) if (matchTabName) { diff --git a/src/api/general.ts b/src/api/general.ts index 6d3c3b6e..445a4d08 100644 --- a/src/api/general.ts +++ b/src/api/general.ts @@ -46,7 +46,7 @@ const apiGeneral = async ({ params, headers: { 'Content-Type': 'application/json', - 'User-Agent': `tooot/${Constants.manifest.version}`, + 'User-Agent': `tooot/${Constants.manifest?.version}`, Accept: '*/*', ...headers }, diff --git a/src/api/instance.ts b/src/api/instance.ts index cd3a3c9e..e8a95d87 100644 --- a/src/api/instance.ts +++ b/src/api/instance.ts @@ -68,7 +68,7 @@ const apiInstance = async ({ params, headers: { 'Content-Type': 'application/json', - 'User-Agent': `tooot/${Constants.manifest.version}`, + 'User-Agent': `tooot/${Constants.manifest?.version}`, Accept: '*/*', ...headers, ...(token && { diff --git a/src/components/Account.tsx b/src/components/Account.tsx index 1b4d78f7..ca9d2f17 100644 --- a/src/components/Account.tsx +++ b/src/components/Account.tsx @@ -1,6 +1,7 @@ import { ParseEmojis } from '@components/Parse' import { useNavigation } from '@react-navigation/native' import { StackNavigationProp } from '@react-navigation/stack' +import { TabLocalStackParamList } from '@utils/navigation/navigators' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useCallback } from 'react' @@ -21,7 +22,7 @@ const ComponentAccount: React.FC = ({ }) => { const { theme } = useTheme() const navigation = useNavigation< - StackNavigationProp + StackNavigationProp >() const onPress = useCallback(() => { diff --git a/src/components/Timeline/Default.tsx b/src/components/Timeline/Default.tsx index 36260389..47e18c98 100644 --- a/src/components/Timeline/Default.tsx +++ b/src/components/Timeline/Default.tsx @@ -10,10 +10,9 @@ import TimelinePoll from '@components/Timeline/Shared/Poll' import { useNavigation } from '@react-navigation/native' import { StackNavigationProp } from '@react-navigation/stack' import { QueryKeyTimeline } from '@utils/queryHooks/timeline' -import { getInstance, getInstanceAccount } from '@utils/slices/instancesSlice' +import { getInstanceAccount } from '@utils/slices/instancesSlice' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' -import htmlparser2 from 'htmlparser2-without-node-native' import { uniqBy } from 'lodash' import React, { useCallback } from 'react' import { Pressable, StyleSheet, View } from 'react-native' diff --git a/src/components/openLink.ts b/src/components/openLink.ts index 4edbdce8..cbc07f23 100644 --- a/src/components/openLink.ts +++ b/src/components/openLink.ts @@ -52,7 +52,7 @@ const openLink = async ( // @ts-ignore navigation.push(page, options) } else { - navigationRef.current?.navigate(page, options) + navigationRef.navigate(page, options) } } diff --git a/src/helpers/navigationRef.ts b/src/helpers/navigationRef.ts index 48f0f8c5..348eea27 100644 --- a/src/helpers/navigationRef.ts +++ b/src/helpers/navigationRef.ts @@ -1,6 +1,6 @@ -import { NavigationContainerRef } from '@react-navigation/native' -import { createRef } from 'react' +import { createNavigationContainerRef } from '@react-navigation/native' +import { RootStackParamList } from '@utils/navigation/navigators' -const navigationRef = createRef() +const navigationRef = createNavigationContainerRef() export default navigationRef diff --git a/src/screens/Actions.tsx b/src/screens/Actions.tsx index da01dd77..9741e3b4 100644 --- a/src/screens/Actions.tsx +++ b/src/screens/Actions.tsx @@ -1,22 +1,244 @@ -import { StackScreenProps } from '@react-navigation/stack' -import React from 'react' -import { SafeAreaProvider } from 'react-native-safe-area-context' -import ScreenActionsRoot from './Actions/Root' - -export type ScreenAccountProp = StackScreenProps< - Nav.RootStackParamList, - 'Screen-Actions' -> +import analytics from '@components/analytics' +import Button from '@components/Button' +import { RootStackScreenProps } from '@utils/navigation/navigators' +import { + getInstanceAccount, + getInstanceUrl +} from '@utils/slices/instancesSlice' +import { StyleConstants } from '@utils/styles/constants' +import { useTheme } from '@utils/styles/ThemeManager' +import React, { useCallback, useEffect, useMemo } from 'react' +import { useTranslation } from 'react-i18next' +import { Dimensions, StyleSheet, View } from 'react-native' +import { + PanGestureHandler, + State, + TapGestureHandler +} from 'react-native-gesture-handler' +import Animated, { + Extrapolate, + interpolate, + runOnJS, + useAnimatedGestureHandler, + useAnimatedStyle, + useSharedValue, + withTiming +} from 'react-native-reanimated' +import { + SafeAreaProvider, + useSafeAreaInsets +} from 'react-native-safe-area-context' +import { useSelector } from 'react-redux' +import ActionsAccount from './Actions/Account' +import ActionsDomain from './Actions/Domain' +import ActionsNotificationsFilter from './Actions/NotificationsFilter' +import ActionsShare from './Actions/Share' +import ActionsStatus from './Actions/Status' const ScreenActions = React.memo( - (props: ScreenAccountProp) => { + ({ + route: { params }, + navigation + }: RootStackScreenProps<'Screen-Actions'>) => { + const { t } = useTranslation() + + const instanceAccount = useSelector( + getInstanceAccount, + (prev, next) => prev?.id === next?.id + ) + let sameAccount = false + switch (params.type) { + case 'status': + sameAccount = instanceAccount?.id === params.status.account.id + break + case 'account': + sameAccount = instanceAccount?.id === params.account.id + break + } + + const instanceDomain = useSelector(getInstanceUrl) + let sameDomain = true + let statusDomain: string + switch (params.type) { + case 'status': + statusDomain = params.status.uri + ? params.status.uri.split(new RegExp(/\/\/(.*?)\//))[1] + : '' + sameDomain = instanceDomain === statusDomain + break + } + + const { theme } = useTheme() + const insets = useSafeAreaInsets() + + const DEFAULT_VALUE = 350 + const screenHeight = Dimensions.get('screen').height + const panY = useSharedValue(DEFAULT_VALUE) + useEffect(() => { + panY.value = withTiming(0) + }, []) + const styleTop = useAnimatedStyle(() => { + return { + bottom: interpolate( + panY.value, + [0, screenHeight], + [0, -screenHeight], + Extrapolate.CLAMP + ) + } + }) + const dismiss = useCallback(() => { + navigation.goBack() + }, []) + const onGestureEvent = useAnimatedGestureHandler({ + onActive: ({ translationY }) => { + panY.value = translationY + }, + onEnd: ({ velocityY }) => { + if (velocityY > 500) { + runOnJS(dismiss)() + } else { + panY.value = withTiming(0) + } + } + }) + + const actions = useMemo(() => { + switch (params.type) { + case 'status': + return ( + <> + {!sameAccount ? ( + + ) : null} + {sameAccount && params.status ? ( + + ) : null} + {!sameDomain && statusDomain ? ( + + ) : null} + {params.status.visibility !== 'direct' ? ( + + ) : null} +