add isWeb check to disable haptics on web
parent
858ec6438d
commit
58a0489ce3
|
@ -1,17 +1,33 @@
|
||||||
import { isIOS } from 'platform/detection'
|
import {isIOS, isWeb} from 'platform/detection'
|
||||||
import ReactNativeHapticFeedback, {
|
import ReactNativeHapticFeedback, {
|
||||||
HapticFeedbackTypes,
|
HapticFeedbackTypes,
|
||||||
} from 'react-native-haptic-feedback'
|
} from 'react-native-haptic-feedback'
|
||||||
|
|
||||||
|
|
||||||
const hapticImpact: HapticFeedbackTypes = isIOS ? 'impactMedium' : 'impactLight' // Users said the medium impact was too strong on Android; see APP-537s
|
const hapticImpact: HapticFeedbackTypes = isIOS ? 'impactMedium' : 'impactLight' // Users said the medium impact was too strong on Android; see APP-537s
|
||||||
|
|
||||||
|
|
||||||
export class Haptics {
|
export class Haptics {
|
||||||
static default = () => ReactNativeHapticFeedback.trigger(hapticImpact)
|
static default() {
|
||||||
static impact = (type: HapticFeedbackTypes = hapticImpact) => ReactNativeHapticFeedback.trigger(type)
|
if (isWeb) {
|
||||||
static selection = () => ReactNativeHapticFeedback.trigger('selection')
|
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') => {
|
static notification = (type: 'success' | 'warning' | 'error') => {
|
||||||
|
if (isWeb) {
|
||||||
|
return
|
||||||
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'success':
|
case 'success':
|
||||||
return ReactNativeHapticFeedback.trigger('notificationSuccess')
|
return ReactNativeHapticFeedback.trigger('notificationSuccess')
|
||||||
|
|
|
@ -21,7 +21,6 @@ import {HeartIcon, HeartIconSolid, CommentBottomArrow} from 'lib/icons'
|
||||||
import {s, colors} from 'lib/styles'
|
import {s, colors} from 'lib/styles'
|
||||||
import {useTheme} from 'lib/ThemeContext'
|
import {useTheme} from 'lib/ThemeContext'
|
||||||
import {useStores} from 'state/index'
|
import {useStores} from 'state/index'
|
||||||
import {isNative} from 'platform/detection'
|
|
||||||
import {RepostButton} from './RepostButton'
|
import {RepostButton} from './RepostButton'
|
||||||
import {Haptics} from 'lib/haptics'
|
import {Haptics} from 'lib/haptics'
|
||||||
|
|
||||||
|
@ -108,9 +107,7 @@ export function PostCtrls(opts: PostCtrlsOpts) {
|
||||||
const onRepost = useCallback(() => {
|
const onRepost = useCallback(() => {
|
||||||
store.shell.closeModal()
|
store.shell.closeModal()
|
||||||
if (!opts.isReposted) {
|
if (!opts.isReposted) {
|
||||||
if (isNative) {
|
|
||||||
Haptics.default()
|
Haptics.default()
|
||||||
}
|
|
||||||
opts.onPressToggleRepost().catch(_e => undefined)
|
opts.onPressToggleRepost().catch(_e => undefined)
|
||||||
// DISABLED see #135
|
// DISABLED see #135
|
||||||
// repostRef.current?.trigger(
|
// repostRef.current?.trigger(
|
||||||
|
@ -136,10 +133,7 @@ export function PostCtrls(opts: PostCtrlsOpts) {
|
||||||
indexedAt: opts.indexedAt,
|
indexedAt: opts.indexedAt,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isNative) {
|
|
||||||
Haptics.default()
|
Haptics.default()
|
||||||
}
|
|
||||||
}, [
|
}, [
|
||||||
opts.author,
|
opts.author,
|
||||||
opts.indexedAt,
|
opts.indexedAt,
|
||||||
|
@ -151,9 +145,7 @@ export function PostCtrls(opts: PostCtrlsOpts) {
|
||||||
|
|
||||||
const onPressToggleLikeWrapper = async () => {
|
const onPressToggleLikeWrapper = async () => {
|
||||||
if (!opts.isLiked) {
|
if (!opts.isLiked) {
|
||||||
if (isNative) {
|
|
||||||
Haptics.default()
|
Haptics.default()
|
||||||
}
|
|
||||||
await opts.onPressToggleLike().catch(_e => undefined)
|
await opts.onPressToggleLike().catch(_e => undefined)
|
||||||
// DISABLED see #135
|
// DISABLED see #135
|
||||||
// likeRef.current?.trigger(
|
// likeRef.current?.trigger(
|
||||||
|
@ -200,7 +192,7 @@ export function PostCtrls(opts: PostCtrlsOpts) {
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={opts.isLiked ? 'Unlike' : 'Like'}
|
accessibilityLabel={opts.isLiked ? 'Unlike' : 'Like'}
|
||||||
accessibilityHint={
|
accessibilityHint={
|
||||||
opts.isReposted ? `Removes like from the post` : `Like the post`
|
opts.isReposted ? 'Removes like from the post' : 'Like the post'
|
||||||
}>
|
}>
|
||||||
{opts.isLiked ? (
|
{opts.isLiked ? (
|
||||||
<HeartIconSolid
|
<HeartIconSolid
|
||||||
|
|
Loading…
Reference in New Issue