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
7 changes: 7 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## 2025-03-05 - [Haptic Feedback for Gestures]
**Learning:** When adding haptics to continuous gestures (like `PanResponder`), it's critical to use a `ref` to ensure the haptic triggers exactly once when crossing a threshold. Otherwise, it triggers on every frame, creating an unpleasant "buzzing" effect.
**Action:** Always use a "hasTriggered" ref gated by the threshold logic in gesture handlers.

## 2025-03-05 - [Micro-UX: Tactile Tabs]
**Learning:** Light haptic impact on segmented control/tab switches makes the digital interface feel more mechanical and responsive, especially when visual transitions are subtle.
**Action:** Add `ImpactFeedbackStyle.Light` to tab-like navigation elements.
51 changes: 24 additions & 27 deletions package-lock.json

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

34 changes: 31 additions & 3 deletions src/screens/FlightScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} 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 @@ -70,14 +71,24 @@ function SwipeableFlightCard({
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;
Comment on lines +85 to +86
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasTriggeredHaptic is reset when the swipe moves back above the threshold (dx >= -SWIPE_THRESHOLD), so a single swipe gesture can trigger Haptics.selectionAsync() multiple times if the user jitters across the threshold. If the intent is β€œexactly once per gesture”, keep the ref true until onPanResponderRelease/Terminate and remove the mid-gesture reset (or update the gating logic accordingly).

Suggested change
} else if (g.dx >= -SWIPE_THRESHOLD && hasTriggeredHaptic.current) {
hasTriggeredHaptic.current = false;

Copilot uses AI. Check for mistakes.
}
}
},
onPanResponderRelease: (_, g) => {
hasTriggeredHaptic.current = false;
if (g.dx < -SWIPE_THRESHOLD) {
Animated.timing(translateX, { toValue: -SWIPE_THRESHOLD, duration: 100, useNativeDriver: true }).start(() => {
onToggleRef.current();
Expand All @@ -88,6 +99,7 @@ function SwipeableFlightCard({
}
},
onPanResponderTerminate: () => {
hasTriggeredHaptic.current = false;
Animated.spring(translateX, { toValue: 0, useNativeDriver: true }).start();
},
}), []);
Expand Down Expand Up @@ -493,6 +505,7 @@ export default function FlightScreen() {
const tab = activeTab;
await AsyncStorage.setItem(PINNED_FLIGHT_KEY, JSON.stringify({ ...item, _pinTab: tab, _pinnedAt: Date.now() }));
setPinnedFlightId(id);
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haptics.notificationAsync(...) returns a Promise, but it’s not awaited or handled. If it rejects (e.g., unsupported platform), it can create unhandled promise rejections. Consider calling it with void ...catch(() => {}) or awaiting it inside the surrounding try (and/or gating with Haptics.isAvailableAsync() / Platform.OS !== 'web').

Suggested change
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success).catch(() => {});

Copilot uses AI. Check for mistakes.
try { await schedulePinnedNotifications(item, tab, locale); } catch (e) { if (__DEV__) console.warn('[pinnedNotif]', e); }
// Send to watch
if (WearDataSender) {
Expand Down Expand Up @@ -522,6 +535,7 @@ export default function FlightScreen() {
await AsyncStorage.removeItem(PINNED_FLIGHT_KEY);
try { await cancelPinnedNotifications(); } catch (e) { if (__DEV__) console.warn('[cancelPinNotif]', e); }
setPinnedFlightId(null);
Haptics.selectionAsync();
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haptics.selectionAsync() is fire-and-forget here; if it rejects on unsupported platforms it can surface as an unhandled promise rejection. Consider using void Haptics.selectionAsync().catch(() => {}) (and/or gating with Haptics.isAvailableAsync() / Platform.OS !== 'web').

Suggested change
Haptics.selectionAsync();
void Haptics.selectionAsync().catch(() => {});

Copilot uses AI. Check for mistakes.
if (WearDataSender) WearDataSender.clearPinnedFlight();
} catch (e) { if (__DEV__) console.error('[unpin]', e); }
}, []);
Expand Down Expand Up @@ -773,15 +787,29 @@ export default function FlightScreen() {
{/* Arrivi / Partenze */}
<View style={s.segment}>
{(['arrivals', 'departures'] as const).map(tab => (
<TouchableOpacity key={tab} style={[s.segBtn, activeTab === tab && s.segBtnActive]} onPress={() => setActiveTab(tab)}>
<TouchableOpacity
key={tab}
style={[s.segBtn, activeTab === tab && s.segBtnActive]}
onPress={() => {
setActiveTab(tab);
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
}}
Comment on lines +793 to +796
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haptics.impactAsync(...) returns a Promise but isn’t awaited/handled; on unsupported platforms this can generate unhandled promise rejections. Consider wrapping haptics in a small helper that gates by platform/availability and uses void ...catch(() => {}).

Copilot uses AI. Check for mistakes.
>
<Text style={[s.segBtnText, activeTab === tab && s.segBtnTextActive]}>{tab === 'arrivals' ? t('flightArrivals') : t('flightDepartures')}</Text>
</TouchableOpacity>
))}
</View>
{/* Oggi / Domani */}
<View style={s.segment}>
{(['today', 'tomorrow'] as const).map(d => (
<TouchableOpacity key={d} style={[s.segBtn, activeDay === d && s.segBtnActive]} onPress={() => setActiveDay(d)}>
<TouchableOpacity
key={d}
style={[s.segBtn, activeDay === d && s.segBtnActive]}
onPress={() => {
setActiveDay(d);
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
}}
Comment on lines +808 to +811
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: Haptics.impactAsync(...) is not awaited/handled, which can lead to unhandled promise rejections on platforms where haptics are unavailable (notably web). Consider gating/handling via a shared helper.

Copilot uses AI. Check for mistakes.
>
<Text style={[s.segBtnText, activeDay === d && s.segBtnTextActive]}>{d === 'today' ? t('flightToday') : t('flightTomorrow')}</Text>
</TouchableOpacity>
))}
Expand Down
Loading