Harvest valuable features from external/ reference repos, adapted to each product's stack and wired in; all products typecheck clean. - gitgram-web (5): clickable @mention/#hashtag linkify in rendered content (munia), + feed/notification/accessibility patterns; install @testing-library/dom - gitgram-backend (3): feed thread dedup + muted-thread removal (bluesky), GitHub star/follow write-back via OAuth (gh-social) - gitgram-mobile (4): double-tap-to-like + heart bounce (proximity), haptics layer (bluesky useHaptics), + gesture/feed UX - aitm-api (4): beads ready/dependency-DAG endpoints + atomic claim (beads) - aitm-mcp (6): beads_ready work-queue tool, context-efficient projections, transport arg aliasing (context7/pal-mcp/beads) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { useCallback } from 'react';
|
|
import { Platform } from 'react-native';
|
|
import * as Haptics from 'expo-haptics';
|
|
|
|
import { useSettingsStore } from '../store/settingsStore';
|
|
|
|
export type HapticStrength = 'Light' | 'Medium' | 'Heavy';
|
|
|
|
/**
|
|
* Returns a stable callback that fires a tactile impact, respecting the user's
|
|
* "disable haptics" preference. Ported from Bluesky's useHaptics hook.
|
|
*
|
|
* Android's medium/heavy impacts feel too strong, so non-iOS platforms always
|
|
* use the Light style regardless of the requested strength.
|
|
*/
|
|
export function useHaptics(): (strength?: HapticStrength) => void {
|
|
const hapticsDisabled = useSettingsStore((state) => state.hapticsDisabled);
|
|
|
|
return useCallback(
|
|
(strength: HapticStrength = 'Medium') => {
|
|
if (hapticsDisabled || Platform.OS === 'web') {
|
|
return;
|
|
}
|
|
|
|
const style =
|
|
Platform.OS === 'ios'
|
|
? Haptics.ImpactFeedbackStyle[strength]
|
|
: Haptics.ImpactFeedbackStyle.Light;
|
|
|
|
// impactAsync returns a promise; fire-and-forget is intentional and any
|
|
// failure (e.g. unsupported device) must not interrupt the interaction.
|
|
void Haptics.impactAsync(style).catch(() => {});
|
|
},
|
|
[hapticsDisabled],
|
|
);
|
|
}
|