Skip to content

Commit

Permalink
FAB - delay followup haptic (#5974)
Browse files Browse the repository at this point in the history
  • Loading branch information
mozzius authored Oct 28, 2024
1 parent 2e3844c commit 5bce043
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
26 changes: 11 additions & 15 deletions src/view/com/post-thread/PostThreadComposePrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import {useLingui} from '@lingui/react'

import {PressableScale} from '#/lib/custom-animations/PressableScale'
import {useHaptics} from '#/lib/haptics'
import {useHapticsDisabled} from '#/state/preferences'
import {useProfileQuery} from '#/state/queries/profile'
import {useSession} from '#/state/session'
import {UserAvatar} from '#/view/com/util/UserAvatar'
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
import {atoms as a, native, useBreakpoints, useTheme} from '#/alf'
import {useInteractionState} from '#/components/hooks/useInteractionState'
import {Text} from '#/components/Typography'

Expand All @@ -23,24 +22,13 @@ export function PostThreadComposePrompt({
const {_} = useLingui()
const {gtMobile} = useBreakpoints()
const t = useTheme()
const playHaptics = useHaptics()
const isHapticsDisabled = useHapticsDisabled()
const playHaptic = useHaptics()
const {
state: hovered,
onIn: onHoverIn,
onOut: onHoverOut,
} = useInteractionState()

const onPress = () => {
playHaptics('Light')
setTimeout(
() => {
onPressCompose()
},
isHapticsDisabled ? 0 : 75,
)
}

return (
<PressableScale
accessibilityRole="button"
Expand All @@ -53,7 +41,15 @@ export function PostThreadComposePrompt({
t.atoms.border_contrast_low,
t.atoms.bg,
]}
onPress={onPress}
onPressIn={() => playHaptic('Light')}
onPress={() => {
onPressCompose()
setTimeout(() => playHaptic('Medium'), 200)
}}
onLongPress={native(() => {
onPressCompose()
setTimeout(() => playHaptic('Heavy'), 200)
})}
onHoverIn={onHoverIn}
onHoverOut={onHoverOut}>
<View
Expand Down
17 changes: 8 additions & 9 deletions src/view/com/util/fab/FABInner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
import {clamp} from '#/lib/numbers'
import {gradients} from '#/lib/styles'
import {isWeb} from '#/platform/detection'
import {useHapticsDisabled} from '#/state/preferences'
import {native} from '#/alf'

export interface FABProps
extends ComponentProps<typeof TouchableWithoutFeedback> {
Expand All @@ -23,7 +23,6 @@ export function FABInner({testID, icon, onPress, ...props}: FABProps) {
const insets = useSafeAreaInsets()
const {isMobile, isTablet} = useWebMediaQueries()
const playHaptic = useHaptics()
const isHapticsDisabled = useHapticsDisabled()
const fabMinimalShellTransform = useMinimalShellFabTransform()

const size = isTablet ? styles.sizeLarge : styles.sizeRegular
Expand All @@ -43,14 +42,14 @@ export function FABInner({testID, icon, onPress, ...props}: FABProps) {
<PressableScale
testID={testID}
onPressIn={() => playHaptic('Light')}
onPress={e => {
playHaptic('Light')
setTimeout(() => onPress?.(e), isHapticsDisabled ? 0 : 75)
}}
onLongPress={e => {
playHaptic('Medium')
setTimeout(() => onPress?.(e), isHapticsDisabled ? 0 : 75)
onPress={evt => {
onPress?.(evt)
setTimeout(() => playHaptic('Medium'), 200)
}}
onLongPress={native((evt: any) => {
onPress?.(evt)
setTimeout(() => playHaptic('Heavy'), 200)
})}
targetScale={0.9}
{...props}>
<LinearGradient
Expand Down

0 comments on commit 5bce043

Please sign in to comment.