Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/store/achievementStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useReviewStore } from './reviewStore';
import apiService from '../services/api';
import { inAppReviewService, ReviewTrigger } from '../services/inAppReview';
import { appLogger } from '../utils/logger';
import { achievementHaptic } from '../utils/quizHaptics';

const triggerAchievementReview = () => {
const { incrementAchievementsUnlocked, getMetrics, recordReviewRequest } = useReviewStore.getState();
Expand Down Expand Up @@ -317,6 +318,8 @@ export const useAchievementStore = create<AchievementState>()(
achievementProgress: snapshotAchievementProgress(updatedAchievements),
unlockedCount: updatedAchievements.filter(a => !a.isLocked).length,
});
// #835: success haptic when an achievement unlocks.
void achievementHaptic();
setTimeout(triggerAchievementReview, 500);

try {
Expand Down
4 changes: 4 additions & 0 deletions src/store/quizStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { create } from 'zustand';
import { isRecord } from './persistence';
import { Quiz, QuizProgress } from '../types/course';
import logger from '../utils/logger';
import { quizAnswerHaptic } from '../utils/quizHaptics';

const QUIZ_SESSION_KEY = '@teachlink_quiz_session';
const QUIZ_PROGRESS_KEY = '@teachlink_quiz_progress';
Expand Down Expand Up @@ -177,6 +178,9 @@ export const useQuizStore = create<QuizState>((set, get) => ({
},

selectAnswer: (questionId: string, answer: string | number, isMultiSelect = false) => {
// #835: tactile confirmation on every answer selection.
void quizAnswerHaptic();

const { session } = get();
let updatedAnswer: string | number | (string | number)[];

Expand Down
39 changes: 39 additions & 0 deletions src/utils/quizHaptics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
ImpactFeedbackStyle,
NotificationFeedbackType,
impactAsync,
notificationAsync,
} from 'expo-haptics';
import { AccessibilityInfo } from 'react-native';

/**
* #835: haptic feedback for quiz answers and achievement unlocks.
*
* Both helpers respect the OS "Reduce Motion" accessibility setting — when it
* is enabled, no haptic is triggered. Failures are swallowed so haptics never
* interrupt the learning flow.
*/

async function reduceMotionEnabled(): Promise<boolean> {
try {
return await AccessibilityInfo.isReduceMotionEnabled();
} catch {
return false;
}
}

/** Medium impact when a quiz answer is selected. */
export async function quizAnswerHaptic(): Promise<void> {
if (await reduceMotionEnabled()) return;
impactAsync(ImpactFeedbackStyle.Medium).catch(() => {
// Ignore haptic failures silently.
});
}

/** Success notification when an achievement is unlocked. */
export async function achievementHaptic(): Promise<void> {
if (await reduceMotionEnabled()) return;
notificationAsync(NotificationFeedbackType.Success).catch(() => {
// Ignore haptic failures silently.
});
}
Loading