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-15 - Flight Card Haptics and Accessibility
**Learning:** Adding haptic feedback (selection for threshold crossing and success notification for action completion) significantly improves the feel of swipe gestures in React Native. For accessibility, non-pressable interactive cards should use `accessibilityActions` and `onAccessibilityAction` to provide screen reader users with the same functionality as swipe gestures.
**Action:** Use `useRef` to track haptic triggers in continuous gestures and always provide alternative accessibility actions for swipe-based features.
155 changes: 154 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
"expo-secure-store": "~15.0.5",
"expo-status-bar": "~3.0.9",
"react": "19.1.0",
"react-dom": "19.1.0",
"react-native": "0.81.5",
"react-native-android-widget": "^0.20.1",
"react-native-calendars": "^1.1314.0",
"react-native-web": "^0.21.0",
"react-native-webview": "13.16.1",
"tesseract.js": "^7.0.0"
},
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ const it = {
flightNotifMsg1: 'Programmate {count} notifiche: arrivi voli (15 min prima) + fine turno.',
flightNotifMsg0: 'Nessun volo futuro trovato, ma riceverai la notifica di fine turno.',
flightNotifAccessEnable: 'Attiva notifiche voli', flightNotifAccessDisable: 'Disattiva notifiche voli',
flightAccessibilityPinHint: 'Pinnare volo', flightAccessibilityUnpinHint: 'Rimuovere pin',
flightFrom: 'da', flightTo: 'a',
// Phonebook
phonebookTitle: 'Rubrica', contactAdd: 'Aggiungi',
contactSearch: 'Cerca nome o numero...', contactAll: 'Tutti',
Expand Down Expand Up @@ -264,6 +266,8 @@ const en: typeof it = {
flightNotifMsg1: '{count} notifications scheduled: flight arrivals (15 min before) + end of shift.',
flightNotifMsg0: 'No future flights found, but you will receive the end-of-shift notification.',
flightNotifAccessEnable: 'Enable flight notifications', flightNotifAccessDisable: 'Disable flight notifications',
flightAccessibilityPinHint: 'Pin flight', flightAccessibilityUnpinHint: 'Unpin flight',
flightFrom: 'from', flightTo: 'to',
// Phonebook
phonebookTitle: 'Phonebook', contactAdd: 'Add',
contactSearch: 'Search name or number...', contactAll: 'All',
Expand Down
44 changes: 40 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,
} 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,31 +63,43 @@ function LogoPill({ iataCode, airlineName, color }: { iataCode: string; airlineN
const SWIPE_THRESHOLD = 80;

function SwipeableFlightCardComponent({
children, isPinned, onToggle,
children, isPinned, onToggle, ...rest
}: {
children: React.ReactNode;
isPinned: boolean;
onToggle: () => void;
}) {
} & React.ComponentProps<typeof Animated.View>) {
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.selectionAsync();
hasTriggeredHaptic.current = true;
} else if (g.dx >= -SWIPE_THRESHOLD && hasTriggeredHaptic.current) {
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();
Expand All @@ -94,7 +108,11 @@ function SwipeableFlightCardComponent({

return (
<View style={{ marginBottom: 10 }}>
<Animated.View style={{ transform: [{ translateX }] }} {...panResponder.panHandlers}>
<Animated.View
style={{ transform: [{ translateX }] }}
{...panResponder.panHandlers}
{...rest}
>
{children}
</Animated.View>
</View>
Expand Down Expand Up @@ -594,6 +612,20 @@ export default function FlightScreen() {
const flightId = item.flight?.identification?.number?.default || null;
const isPinned = flightId !== null && flightId === pinnedFlightId;

// Accessibility strings
const pinActionLabel = isPinned ? t('flightAccessibilityUnpinHint') : t('flightAccessibilityPinHint');
const directionLabel = activeTab === 'arrivals' ? t('homeArrival') : t('homeDeparture');
const pinnedPrefix = isPinned ? `${t('homePinned')}, ` : '';
const connector = activeTab === 'arrivals' ? t('flightFrom') : t('flightTo');
const accessibilityLabel = `${pinnedPrefix}${flightNumber}, ${airline}, ${directionLabel} ${connector} ${originDest}, ${time}, ${statusText}`;

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

const normFn = normalizeFlightNumber(flightNumber);
const normalizeForMatching = (s: string) => s.replace(/[\s\-_]/g, '').toUpperCase();
const normFnStripped = normalizeForMatching(normFn);
Expand All @@ -609,6 +641,10 @@ export default function FlightScreen() {
<SwipeableFlightCard
isPinned={isPinned}
onToggle={() => isPinned ? unpinFlight() : pinFlight(item)}
accessible
accessibilityLabel={accessibilityLabel}
accessibilityActions={[{ name: 'togglePin', label: pinActionLabel }]}
onAccessibilityAction={handleAccessibilityAction}
>
<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
Loading