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 Feedback in Continuous Gestures
**Learning:** In 'PanResponder' implementations within functional components, store dynamic callbacks (like 'onToggle') in a 'useRef' to provide the responder with access to the latest state/functions without re-instantiating the responder object. When implementing haptic feedback with 'expo-haptics' in continuous gestures (like 'PanResponder'), use a 'useRef' toggle (e.g., 'hasTriggeredHaptic') to ensure the feedback triggers only once when a threshold is crossed.
**Action:** Use 'useRef' for both callbacks and haptic triggers in gesture-based components to ensure performance and prevent multiple haptic triggers during a single gesture.
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.

8 changes: 8 additions & 0 deletions src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ 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: 'Pinna volo', flightAccessibilityUnpin: 'Rimuovi pin volo',
flightAccessibilityPinHint: 'Pinna il volo in alto e attiva le notifiche',
flightAccessibilityUnpinHint: 'Rimuove il volo dai pinnati',
flightFrom: 'da', flightTo: 'a',
flightNotifEnabled: 'Notifiche attivate',
flightNotifPermDenied: 'Permesso negato',
flightNotifPermMsg: 'Abilita le notifiche nelle impostazioni del telefono per usare questa funzione.',
Expand Down Expand Up @@ -256,6 +260,10 @@ 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',
flightAccessibilityPinHint: 'Pins the flight to the top and enables notifications',
flightAccessibilityUnpinHint: 'Removes the flight from pinned list',
flightFrom: 'from', flightTo: 'to',
flightNotifEnabled: 'Notifications enabled',
flightNotifPermDenied: 'Permission denied',
flightNotifPermMsg: 'Enable notifications in phone settings to use this feature.',
Expand Down
60 changes: 55 additions & 5 deletions src/screens/FlightScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ 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 Haptics from 'expo-haptics';
import * as Notifications from 'expo-notifications';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { MaterialIcons } from '@expo/vector-icons';
Expand Down Expand Up @@ -61,24 +63,37 @@ 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;
[key: string]: any;
}) {
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) => {
hasTriggeredHaptic.current = false;
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();
Expand All @@ -88,13 +103,18 @@ function SwipeableFlightCardComponent({
}
},
onPanResponderTerminate: () => {
hasTriggeredHaptic.current = false;
Animated.spring(translateX, { toValue: 0, useNativeDriver: true }).start();
},
}), []);

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 +625,40 @@ export default function FlightScreen() {
console.log(`[FlightScreen] No staffMonitor match for "${normFn}" (stripped: "${normFnStripped}") in ${activeTab}`);
}

const accessibilityLabel = [
isPinned ? t('flightPinnedLabel') : '',
flightNumber,
airline,
activeTab === 'arrivals' ? t('homeArrival') : t('homeDeparture'),
activeTab === 'arrivals' ? `${t('flightFrom')} ${originDest}` : `${t('flightTo')} ${originDest}`,
time,
activeTab === 'arrivals' ? (item.flight?.time?.real?.arrival ? t('flightLanded') : t('flightEstimated')) : statusText,
].filter(Boolean).join(', ');

const accessibilityActions = [
{ name: isPinned ? 'unpin' : 'pin', label: isPinned ? t('flightAccessibilityUnpin') : t('flightAccessibilityPin') },
];

const onAccessibilityAction = (event: AccessibilityActionEvent) => {
if (event.nativeEvent.actionName === 'pin' || event.nativeEvent.actionName === 'unpin') {
if (isPinned) unpinFlight();
else pinFlight(item);
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
}
};

return (
<SwipeableFlightCard
isPinned={isPinned}
onToggle={() => isPinned ? unpinFlight() : pinFlight(item)}
onToggle={() => {
if (isPinned) unpinFlight();
else pinFlight(item);
}}
accessible={true}
accessibilityLabel={accessibilityLabel}
accessibilityActions={accessibilityActions}
onAccessibilityAction={onAccessibilityAction}
accessibilityHint={isPinned ? t('flightAccessibilityUnpinHint') : t('flightAccessibilityPinHint')}
>
<View style={[s.card, isPinned && s.cardPinned, { marginBottom: 0 }]}>
{isPinned && <View style={s.pinBanner}><Text style={s.pinBannerText}>{t('flightPinned')}</Text></View>}
Expand Down Expand Up @@ -769,7 +819,7 @@ export default function FlightScreen() {
onPress={toggleNotifications}
activeOpacity={0.8}
accessible
accessibilityLabel={notifsEnabled ? 'Disattiva notifiche voli' : 'Attiva notifiche voli'}
accessibilityLabel={notifsEnabled ? t('flightNotifAccessDisable') : t('flightNotifAccessEnable')}
accessibilityRole="button"
>
<MaterialIcons
Expand Down
Loading
Loading