From dfcdd37087c0be4055c92a0f88431b32646ced6f Mon Sep 17 00:00:00 2001 From: Ansh Nanda Date: Mon, 22 May 2023 18:46:36 -0700 Subject: add haptics to save, like, and pin actions on feed --- src/lib/haptics.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/lib/haptics.ts (limited to 'src/lib/haptics.ts') diff --git a/src/lib/haptics.ts b/src/lib/haptics.ts new file mode 100644 index 000000000..23a321796 --- /dev/null +++ b/src/lib/haptics.ts @@ -0,0 +1,24 @@ +import { isIOS } from 'platform/detection' +import ReactNativeHapticFeedback, { + HapticFeedbackTypes, +} from 'react-native-haptic-feedback' + + +const hapticImpact: HapticFeedbackTypes = isIOS ? 'impactMedium' : 'impactLight' // Users said the medium impact was too strong on Android; see APP-537s + + +export class Haptics { + static default = () => ReactNativeHapticFeedback.trigger(hapticImpact) + static impact = (type: HapticFeedbackTypes = hapticImpact) => ReactNativeHapticFeedback.trigger(type) + static selection = () => ReactNativeHapticFeedback.trigger('selection') + static notification = (type: 'success' | 'warning' | 'error') => { + switch (type) { + case 'success': + return ReactNativeHapticFeedback.trigger('notificationSuccess') + case 'warning': + return ReactNativeHapticFeedback.trigger('notificationWarning') + case 'error': + return ReactNativeHapticFeedback.trigger('notificationError') + } + } +} \ No newline at end of file -- cgit 1.4.1 From 58a0489ce3028c6e6d205557e3edcf03c85f6626 Mon Sep 17 00:00:00 2001 From: Ansh Nanda Date: Wed, 24 May 2023 13:59:53 -0700 Subject: add isWeb check to disable haptics on web --- src/lib/haptics.ts | 30 +++++++++++++++++++++++------- src/view/com/util/post-ctrls/PostCtrls.tsx | 16 ++++------------ 2 files changed, 27 insertions(+), 19 deletions(-) (limited to 'src/lib/haptics.ts') diff --git a/src/lib/haptics.ts b/src/lib/haptics.ts index 23a321796..516940c1c 100644 --- a/src/lib/haptics.ts +++ b/src/lib/haptics.ts @@ -1,17 +1,33 @@ -import { isIOS } from 'platform/detection' +import {isIOS, isWeb} from 'platform/detection' import ReactNativeHapticFeedback, { HapticFeedbackTypes, } from 'react-native-haptic-feedback' - const hapticImpact: HapticFeedbackTypes = isIOS ? 'impactMedium' : 'impactLight' // Users said the medium impact was too strong on Android; see APP-537s - export class Haptics { - static default = () => ReactNativeHapticFeedback.trigger(hapticImpact) - static impact = (type: HapticFeedbackTypes = hapticImpact) => ReactNativeHapticFeedback.trigger(type) - static selection = () => ReactNativeHapticFeedback.trigger('selection') + static default() { + if (isWeb) { + return + } + ReactNativeHapticFeedback.trigger(hapticImpact) + } + static impact(type: HapticFeedbackTypes = hapticImpact) { + if (isWeb) { + return + } + ReactNativeHapticFeedback.trigger(type) + } + static selection() { + if (isWeb) { + return + } + ReactNativeHapticFeedback.trigger('selection') + } static notification = (type: 'success' | 'warning' | 'error') => { + if (isWeb) { + return + } switch (type) { case 'success': return ReactNativeHapticFeedback.trigger('notificationSuccess') @@ -21,4 +37,4 @@ export class Haptics { return ReactNativeHapticFeedback.trigger('notificationError') } } -} \ No newline at end of file +} diff --git a/src/view/com/util/post-ctrls/PostCtrls.tsx b/src/view/com/util/post-ctrls/PostCtrls.tsx index 0d2f83ce7..41d66641f 100644 --- a/src/view/com/util/post-ctrls/PostCtrls.tsx +++ b/src/view/com/util/post-ctrls/PostCtrls.tsx @@ -21,7 +21,6 @@ import {HeartIcon, HeartIconSolid, CommentBottomArrow} from 'lib/icons' import {s, colors} from 'lib/styles' import {useTheme} from 'lib/ThemeContext' import {useStores} from 'state/index' -import {isNative} from 'platform/detection' import {RepostButton} from './RepostButton' import {Haptics} from 'lib/haptics' @@ -108,9 +107,7 @@ export function PostCtrls(opts: PostCtrlsOpts) { const onRepost = useCallback(() => { store.shell.closeModal() if (!opts.isReposted) { - if (isNative) { - Haptics.default() - } + Haptics.default() opts.onPressToggleRepost().catch(_e => undefined) // DISABLED see #135 // repostRef.current?.trigger( @@ -136,10 +133,7 @@ export function PostCtrls(opts: PostCtrlsOpts) { indexedAt: opts.indexedAt, }, }) - - if (isNative) { - Haptics.default() - } + Haptics.default() }, [ opts.author, opts.indexedAt, @@ -151,9 +145,7 @@ export function PostCtrls(opts: PostCtrlsOpts) { const onPressToggleLikeWrapper = async () => { if (!opts.isLiked) { - if (isNative) { - Haptics.default() - } + Haptics.default() await opts.onPressToggleLike().catch(_e => undefined) // DISABLED see #135 // likeRef.current?.trigger( @@ -200,7 +192,7 @@ export function PostCtrls(opts: PostCtrlsOpts) { accessibilityRole="button" accessibilityLabel={opts.isLiked ? 'Unlike' : 'Like'} accessibilityHint={ - opts.isReposted ? `Removes like from the post` : `Like the post` + opts.isReposted ? 'Removes like from the post' : 'Like the post' }> {opts.isLiked ? (