Skip to content
Open
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 .jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2025-05-14 - Haptic & Accessibility for Swipe Gestures
**Learning:** Swipe gestures are delightfull but inherently inaccessible to screen reader users. Adding haptic feedback (Medium impact on threshold, Success on completion) provides tactile confirmation for sighted users.
**Action:** Always pair swipe-to-action gestures with `accessibilityActions` and `onAccessibilityAction` to ensure screen reader users can trigger the same functionality via the accessibility menu. Use `ViewProps` to safely pass accessibility attributes to underlying views.
4 changes: 4 additions & 0 deletions src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ const it = {
flightCheckin: 'Check-in', flightGate: 'Gate', flightStand: 'Stand', flightBelt: 'Nastro', flightDeparted: 'Partito',
flightLanded: 'Atterrato', flightEstimated: 'Stimato', flightOnTime: 'In orario',
flightPinned: 'PINNATO', flightPinnedLabel: 'Pinnato',
flightAccessibilityPin: 'Fissa volo', flightAccessibilityUnpin: 'Rimuovi fissaggio volo',
flightFrom: 'da', flightTo: 'per',
flightNotifEnabled: 'Notifiche attivate',
flightNotifPermDenied: 'Permesso negato',
flightNotifPermMsg: 'Abilita le notifiche nelle impostazioni del telefono per usare questa funzione.',
Expand Down Expand Up @@ -256,6 +258,8 @@ const en: typeof it = {
flightCheckin: 'Check-in', flightGate: 'Gate', flightStand: 'Stand', flightBelt: 'Belt', flightDeparted: 'Departed',
flightLanded: 'Landed', flightEstimated: 'Estimated', flightOnTime: 'On time',
flightPinned: 'PINNED', flightPinnedLabel: 'Pinned',
flightAccessibilityPin: 'Pin flight', flightAccessibilityUnpin: 'Unpin flight',
flightFrom: 'from', flightTo: 'to',
flightNotifEnabled: 'Notifications enabled',
flightNotifPermDenied: 'Permission denied',
flightNotifPermMsg: 'Enable notifications in phone settings to use this feature.',
Expand Down
46 changes: 42 additions & 4 deletions src/screens/FlightScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {
View, Text, StyleSheet, ActivityIndicator, Modal,
FlatList, TouchableOpacity, RefreshControl, Image, Alert,
Animated, PanResponder, NativeModules, Platform,
AccessibilityActionEvent, ViewProps,
} from 'react-native';
import * as Calendar from 'expo-calendar';
import * as Notifications from 'expo-notifications';
import * as Haptics from 'expo-haptics';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { MaterialIcons } from '@expo/vector-icons';
import { useAppTheme, type ThemeColors } from '../context/ThemeContext';
Expand Down Expand Up @@ -61,40 +63,56 @@ function LogoPill({ iataCode, airlineName, color }: { iataCode: string; airlineN
const SWIPE_THRESHOLD = 80;

function SwipeableFlightCardComponent({
children, isPinned, onToggle,
children, isPinned, onToggle, ...props
}: {
children: React.ReactNode;
isPinned: boolean;
onToggle: () => void;
}) {
} & ViewProps) {
const translateX = useRef(new Animated.Value(0)).current;
const onToggleRef = useRef(onToggle);
onToggleRef.current = onToggle;
const hasTriggeredHaptic = useRef(false);

const panResponder = useMemo(() => PanResponder.create({
onMoveShouldSetPanResponder: (_, g) =>
Math.abs(g.dx) > 15 && Math.abs(g.dx) > Math.abs(g.dy) * 1.5,
onPanResponderMove: (_, g) => {
if (g.dx < 0) translateX.setValue(g.dx);
if (g.dx < 0) {
translateX.setValue(g.dx);
if (g.dx < -SWIPE_THRESHOLD && !hasTriggeredHaptic.current) {
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
hasTriggeredHaptic.current = true;
} else if (g.dx >= -SWIPE_THRESHOLD) {
hasTriggeredHaptic.current = false;
}
}
},
onPanResponderRelease: (_, g) => {
if (g.dx < -SWIPE_THRESHOLD) {
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
Animated.timing(translateX, { toValue: -SWIPE_THRESHOLD, duration: 100, useNativeDriver: true }).start(() => {
onToggleRef.current();
Animated.spring(translateX, { toValue: 0, useNativeDriver: true, tension: 120, friction: 10 }).start();
});
} else {
Animated.spring(translateX, { toValue: 0, useNativeDriver: true, tension: 120, friction: 10 }).start();
}
hasTriggeredHaptic.current = false;
},
onPanResponderTerminate: () => {
Animated.spring(translateX, { toValue: 0, useNativeDriver: true }).start();
hasTriggeredHaptic.current = false;
},
}), []);

return (
<View style={{ marginBottom: 10 }}>
<Animated.View style={{ transform: [{ translateX }] }} {...panResponder.panHandlers}>
<Animated.View
style={{ transform: [{ translateX }] }}
{...panResponder.panHandlers}
{...props}
>
{children}
</Animated.View>
</View>
Expand Down Expand Up @@ -605,10 +623,30 @@ export default function FlightScreen() {
console.log(`[FlightScreen] No staffMonitor match for "${normFn}" (stripped: "${normFnStripped}") in ${activeTab}`);
}

const accessibilityLabel = [
isPinned ? t('flightPinned') : '',
flightNumber,
airline,
activeTab === 'arrivals' ? t('flightFrom') : t('flightTo'),
originDest,
time,
statusText,
].filter(Boolean).join(', ');

const onAccessibilityAction = (event: AccessibilityActionEvent) => {
if (event.nativeEvent.actionName === 'togglePin') {
isPinned ? unpinFlight() : pinFlight(item);
}
};

return (
<SwipeableFlightCard
isPinned={isPinned}
onToggle={() => isPinned ? unpinFlight() : pinFlight(item)}
accessible={true}
accessibilityLabel={accessibilityLabel}
accessibilityActions={[{ name: 'togglePin', label: isPinned ? t('flightAccessibilityUnpin') : t('flightAccessibilityPin') }]}
onAccessibilityAction={onAccessibilityAction}
>
<View style={[s.card, isPinned && s.cardPinned, { marginBottom: 0 }]}>
{isPinned && <View style={s.pinBanner}><Text style={s.pinBannerText}>{t('flightPinned')}</Text></View>}
Expand Down
Loading