From 38ebcdbe969b56254a923fe80323e1b23d8c3092 Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 11 Apr 2024 14:54:13 -0700 Subject: [PATCH] simplify to `playHaptic` --- src/lib/haptics.ts | 47 ++----------------- .../Profile/Header/ProfileHeaderLabeler.tsx | 4 +- src/view/com/util/post-ctrls/PostCtrls.tsx | 8 ++-- src/view/screens/ProfileFeed.tsx | 8 ++-- src/view/screens/ProfileList.tsx | 4 +- src/view/screens/SavedFeeds.tsx | 4 +- src/view/shell/bottom-bar/BottomBar.tsx | 4 +- 7 files changed, 21 insertions(+), 58 deletions(-) diff --git a/src/lib/haptics.ts b/src/lib/haptics.ts index 6525803e41..3971c7e085 100644 --- a/src/lib/haptics.ts +++ b/src/lib/haptics.ts @@ -1,10 +1,4 @@ -import { - impactAsync, - ImpactFeedbackStyle, - notificationAsync, - NotificationFeedbackType, - selectionAsync, -} from 'expo-haptics' +import {impactAsync, ImpactFeedbackStyle} from 'expo-haptics' import {isIOS, isWeb} from 'platform/detection' @@ -12,40 +6,9 @@ const hapticImpact: ImpactFeedbackStyle = isIOS ? ImpactFeedbackStyle.Medium : ImpactFeedbackStyle.Light // Users said the medium impact was too strong on Android; see APP-537s -export class Haptics { - static default(disabled: boolean) { - if (disabled || isWeb) { - return - } - - impactAsync(hapticImpact) - } - static impact(type: ImpactFeedbackStyle = hapticImpact, disabled: boolean) { - if (disabled || isWeb) { - return - } - impactAsync(type) - } - static selection(disabled: boolean) { - if (disabled || isWeb) { - return - } - selectionAsync() - } - static notification = ( - type: 'success' | 'warning' | 'error', - enabled: boolean, - ) => { - if (!enabled || isWeb) { - return - } - switch (type) { - case 'success': - return notificationAsync(NotificationFeedbackType.Success) - case 'warning': - return notificationAsync(NotificationFeedbackType.Warning) - case 'error': - return notificationAsync(NotificationFeedbackType.Error) - } +export function playHaptic(disabled: boolean) { + if (disabled || isWeb) { + return } + impactAsync(hapticImpact) } diff --git a/src/screens/Profile/Header/ProfileHeaderLabeler.tsx b/src/screens/Profile/Header/ProfileHeaderLabeler.tsx index ec3ada6708..8878504990 100644 --- a/src/screens/Profile/Header/ProfileHeaderLabeler.tsx +++ b/src/screens/Profile/Header/ProfileHeaderLabeler.tsx @@ -10,7 +10,6 @@ import { import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {Haptics} from '#/lib/haptics' import {isAppLabeler} from '#/lib/moderation' import {pluralize} from '#/lib/strings/helpers' import {logger} from '#/logger' @@ -21,6 +20,7 @@ import {useLikeMutation, useUnlikeMutation} from '#/state/queries/like' import {usePreferencesQuery} from '#/state/queries/preferences' import {useSession} from '#/state/session' import {useAnalytics} from 'lib/analytics/analytics' +import {playHaptic} from 'lib/haptics' import {useProfileShadow} from 'state/cache/profile-shadow' import {useHapticsDisabled} from 'state/preferences/disable-haptics' import {ProfileMenu} from '#/view/com/profile/ProfileMenu' @@ -95,7 +95,7 @@ let ProfileHeaderLabeler = ({ return } try { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) if (likeUri) { await unlikeMod({uri: likeUri}) diff --git a/src/view/com/util/post-ctrls/PostCtrls.tsx b/src/view/com/util/post-ctrls/PostCtrls.tsx index 68ea1e22c5..cb49f36615 100644 --- a/src/view/com/util/post-ctrls/PostCtrls.tsx +++ b/src/view/com/util/post-ctrls/PostCtrls.tsx @@ -16,7 +16,7 @@ import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {HITSLOP_10, HITSLOP_20} from '#/lib/constants' -import {Haptics} from '#/lib/haptics' +import {playHaptic} from '#/lib/haptics' import {CommentBottomArrow, HeartIcon, HeartIconSolid} from '#/lib/icons' import {makeProfileLink} from '#/lib/routes/links' import {shareUrl} from '#/lib/sharing' @@ -86,7 +86,7 @@ let PostCtrls = ({ const onPressToggleLike = React.useCallback(async () => { try { if (!post.viewer?.like) { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) await queueLike() } else { await queueUnlike() @@ -102,7 +102,7 @@ let PostCtrls = ({ closeModal() try { if (!post.viewer?.repost) { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) await queueRepost() } else { await queueUnrepost() @@ -131,7 +131,7 @@ let PostCtrls = ({ indexedAt: post.indexedAt, }, }) - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) }, [ closeModal, openComposer, diff --git a/src/view/screens/ProfileFeed.tsx b/src/view/screens/ProfileFeed.tsx index d50a64e6bb..ad6ebd81f8 100644 --- a/src/view/screens/ProfileFeed.tsx +++ b/src/view/screens/ProfileFeed.tsx @@ -27,7 +27,7 @@ import {truncateAndInvalidate} from '#/state/queries/util' import {useSession} from '#/state/session' import {useComposerControls} from '#/state/shell/composer' import {useAnalytics} from 'lib/analytics/analytics' -import {Haptics} from 'lib/haptics' +import {playHaptic} from 'lib/haptics' import {usePalette} from 'lib/hooks/usePalette' import {useSetTitle} from 'lib/hooks/useSetTitle' import {ComposeIcon2} from 'lib/icons' @@ -203,7 +203,7 @@ export function ProfileFeedScreenInner({ const onToggleSaved = React.useCallback(async () => { try { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) if (isSaved) { await removeFeed({uri: feedInfo.uri}) @@ -235,7 +235,7 @@ export function ProfileFeedScreenInner({ const onTogglePinned = React.useCallback(async () => { try { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) if (isPinned) { await unpinFeed({uri: feedInfo.uri}) @@ -540,7 +540,7 @@ function AboutSection({ const onToggleLiked = React.useCallback(async () => { try { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) if (isLiked && likeUri) { await unlikeFeed({uri: likeUri}) diff --git a/src/view/screens/ProfileList.tsx b/src/view/screens/ProfileList.tsx index c361acdbdd..f6c10c06f2 100644 --- a/src/view/screens/ProfileList.tsx +++ b/src/view/screens/ProfileList.tsx @@ -33,7 +33,7 @@ import {truncateAndInvalidate} from '#/state/queries/util' import {useSession} from '#/state/session' import {useSetMinimalShellMode} from '#/state/shell' import {useComposerControls} from '#/state/shell/composer' -import {Haptics} from 'lib/haptics' +import {playHaptic} from 'lib/haptics' import {usePalette} from 'lib/hooks/usePalette' import {useSetTitle} from 'lib/hooks/useSetTitle' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' @@ -266,7 +266,7 @@ function Header({rkey, list}: {rkey: string; list: AppBskyGraphDefs.ListView}) { const isSaved = preferences?.feeds?.saved?.includes(list.uri) const onTogglePinned = React.useCallback(async () => { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) try { if (isPinned) { diff --git a/src/view/screens/SavedFeeds.tsx b/src/view/screens/SavedFeeds.tsx index 54e73ddede..872a07428a 100644 --- a/src/view/screens/SavedFeeds.tsx +++ b/src/view/screens/SavedFeeds.tsx @@ -16,7 +16,7 @@ import { } from '#/state/queries/preferences' import {useSetMinimalShellMode} from '#/state/shell' import {useAnalytics} from 'lib/analytics/analytics' -import {Haptics} from 'lib/haptics' +import {playHaptic} from 'lib/haptics' import {usePalette} from 'lib/hooks/usePalette' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' import {CommonNavigatorParams} from 'lib/routes/types' @@ -198,7 +198,7 @@ function ListItem({ const isPending = isPinPending || isUnpinPending const onTogglePinned = React.useCallback(async () => { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) try { resetSaveFeedsMutationState() diff --git a/src/view/shell/bottom-bar/BottomBar.tsx b/src/view/shell/bottom-bar/BottomBar.tsx index 1e889f7721..072357d71f 100644 --- a/src/view/shell/bottom-bar/BottomBar.tsx +++ b/src/view/shell/bottom-bar/BottomBar.tsx @@ -8,7 +8,7 @@ import {BottomTabBarProps} from '@react-navigation/bottom-tabs' import {StackActions} from '@react-navigation/native' import {useAnalytics} from '#/lib/analytics/analytics' -import {Haptics} from '#/lib/haptics' +import {playHaptic} from '#/lib/haptics' import {useDedupe} from '#/lib/hooks/useDedupe' import {useMinimalShellMode} from '#/lib/hooks/useMinimalShellMode' import {useNavigationTabState} from '#/lib/hooks/useNavigationTabState' @@ -106,7 +106,7 @@ export function BottomBar({navigation}: BottomTabBarProps) { }, [onPressTab]) const onLongPressProfile = React.useCallback(() => { - Haptics.default(isHapticsDisabled) + playHaptic(isHapticsDisabled) accountSwitchControl.open() }, [accountSwitchControl, isHapticsDisabled])