-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerScreen.tsx
More file actions
1539 lines (1485 loc) · 46.4 KB
/
TimerScreen.tsx
File metadata and controls
1539 lines (1485 loc) · 46.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type { Circumstances, EclipseRecord } from "@eclipse-timer/shared";
import { useMemo, useState } from "react";
import {
ActivityIndicator,
Animated,
FlatList,
Image,
Modal,
Pressable,
ScrollView,
StyleSheet,
Switch,
Text,
TextInput,
useWindowDimensions,
View,
} from "react-native";
import MapView, { Marker, Polygon, Polyline } from "react-native-maps";
import { SafeAreaView, useSafeAreaInsets } from "react-native-safe-area-context";
import { APP_LOGO } from "../assets/branding";
import BurgerButton from "../components/BurgerButton";
import type { TimerState } from "../hooks/useTimerState";
import type { FavoriteLocation } from "../state/appState";
import { colorForContactKey } from "../utils/contactTheme";
import { fmtLocalHuman, fmtUtcHuman } from "../utils/date";
import { formatTimerDuration } from "../utils/duration";
import { eclipseCenterForRecord, kindCodeForRecord } from "../utils/eclipse";
import {
calculatePreviewMoonGeometry,
determinePreviewTravelVector,
PREVIEW_STAGE_SIZE,
PREVIEW_SUN_RADIUS,
} from "../utils/previewGeometry";
const VISIBLE_PATH_COLOR = "rgba(79, 195, 247, 0.22)";
const TOTALITY_PATH_COLOR = "rgba(255, 82, 82, 0.28)";
const ANNULARITY_PATH_COLOR = "rgba(255, 167, 38, 0.30)";
const FAVORITE_COORD_EPSILON = 0.0001;
const DEG2RAD = Math.PI / 180;
const RAD2DEG = 180 / Math.PI;
const TIMER_HERO_PREVIEW_STAGE_SIZE = 84;
const TIMER_HERO_PREVIEW_SUN_RADIUS =
(TIMER_HERO_PREVIEW_STAGE_SIZE * PREVIEW_SUN_RADIUS) / PREVIEW_STAGE_SIZE;
const TIMER_HERO_PREVIEW_GLOW_SIZE = 118;
function localKindLabel(kind: "none" | "partial" | "total" | "annular") {
if (kind === "total") return "Total";
if (kind === "annular") return "Annular";
if (kind === "partial") return "Partial";
return "None";
}
function parseUtcTimestamp(iso?: string) {
if (!iso) return undefined;
const timestamp = Date.parse(iso);
if (!Number.isFinite(timestamp)) return undefined;
return timestamp;
}
function buildPreviewContactProgress(result: Circumstances) {
const c1 = parseUtcTimestamp(result.c1Utc);
const c2 = parseUtcTimestamp(result.c2Utc);
const max = parseUtcTimestamp(result.maxUtc);
const c3 = parseUtcTimestamp(result.c3Utc);
const c4 = parseUtcTimestamp(result.c4Utc);
const definedTimes = [c1, c2, max, c3, c4].filter((t): t is number => typeof t === "number");
if (!definedTimes.length) return {};
const firstDefined = definedTimes[0];
const lastDefined = definedTimes[definedTimes.length - 1];
if (typeof firstDefined !== "number" || typeof lastDefined !== "number") return {};
let startMs: number = c1 ?? firstDefined;
let endMs: number = c4 ?? lastDefined;
if (endMs <= startMs) {
if (typeof max === "number") {
startMs = max - 30 * 60 * 1000;
endMs = max + 30 * 60 * 1000;
} else {
endMs = startMs + 1;
}
}
const spanMs = Math.max(1, endMs - startMs);
const toProgress = (timestamp: number | undefined) =>
typeof timestamp === "number" ? clamp((timestamp - startMs) / spanMs, 0, 1) : undefined;
return {
c1: toProgress(c1),
c2: toProgress(c2),
max: toProgress(max),
c3: toProgress(c3),
c4: toProgress(c4),
};
}
function formatC1ToC4Duration(result: Circumstances) {
const c1 = parseUtcTimestamp(result.c1Utc);
const c4 = parseUtcTimestamp(result.c4Utc);
if (c1 === undefined || c4 === undefined || c4 <= c1) return "--";
return formatTimerDuration((c4 - c1) / 1000);
}
function formatCardinalCoord(
value: number,
positiveHemisphere: string,
negativeHemisphere: string,
) {
const hemisphere = value >= 0 ? positiveHemisphere : negativeHemisphere;
return `${Math.abs(value).toFixed(4)}${hemisphere}`;
}
function buildDefaultFavoriteName(lat: number, lon: number, favoriteLocations: FavoriteLocation[]) {
const base = `Pinned ${formatCardinalCoord(lat, "N", "S")} ${formatCardinalCoord(lon, "E", "W")}`;
const existingNames = new Set(
favoriteLocations.map((location) => location.name.trim().toLowerCase()).filter(Boolean),
);
if (!existingNames.has(base.toLowerCase())) return base;
let suffix = 2;
while (existingNames.has(`${base} ${suffix}`.toLowerCase())) {
suffix += 1;
}
return `${base} ${suffix}`;
}
function isSameFavoriteLocation(aLat: number, aLon: number, bLat: number, bLon: number) {
return (
Math.abs(aLat - bLat) <= FAVORITE_COORD_EPSILON &&
Math.abs(aLon - bLon) <= FAVORITE_COORD_EPSILON
);
}
function clamp(value: number, lo: number, hi: number) {
return Math.max(lo, Math.min(hi, value));
}
function normalizeLongitudeDeg(lonDeg: number) {
return (((lonDeg % 360) + 540) % 360) - 180;
}
function mapTypeLabel(mapType: TimerState["mapType"]) {
if (mapType === "satellite") return "Satellite";
if (mapType === "hybrid") return "Hybrid";
return "Standard";
}
function destinationPoint(
latDeg: number,
lonDeg: number,
bearingDeg: number,
distanceDeg: number,
): { latitude: number; longitude: number } {
const lat1 = latDeg * DEG2RAD;
const lon1 = lonDeg * DEG2RAD;
const brng = bearingDeg * DEG2RAD;
const angularDistance = distanceDeg * DEG2RAD;
const sinLat1 = Math.sin(lat1);
const cosLat1 = Math.cos(lat1);
const sinD = Math.sin(angularDistance);
const cosD = Math.cos(angularDistance);
const lat2 = Math.asin(sinLat1 * cosD + cosLat1 * sinD * Math.cos(brng));
const lon2 = lon1 + Math.atan2(Math.sin(brng) * sinD * cosLat1, cosD - sinLat1 * Math.sin(lat2));
return {
latitude: clamp(lat2 * RAD2DEG, -89.9, 89.9),
longitude: normalizeLongitudeDeg(lon2 * RAD2DEG),
};
}
type ContactDirectionOverlay = {
key: "c1" | "c2" | "c3" | "c4";
label: "C1" | "C2" | "C3" | "C4";
color: string;
bearingDeg: number;
endpoint: { latitude: number; longitude: number };
};
export type TimerEclipseOption = {
id: string;
dateYmd: string;
kindLabel: string;
isPast: boolean;
};
type TimerScreenProps = {
activeEclipse: EclipseRecord | null;
activeEclipseId: string | null;
isActiveEclipseLoading: boolean;
eclipseOptions: TimerEclipseOption[];
timer: TimerState;
isEclipseAlarmEnabled: boolean;
favoriteLocations: FavoriteLocation[];
onSetEclipseAlarmEnabled: (enabled: boolean) => void;
onAddFavoriteLocation: (location: Omit<FavoriteLocation, "id">) => void;
onSelectEclipse: (eclipseId: string) => void;
onUseFavoriteLocation: (location: FavoriteLocation) => void;
onOpenMenu: () => void;
onOpenPreview: (result: Circumstances) => void;
};
export default function TimerScreen({
activeEclipse,
activeEclipseId,
isActiveEclipseLoading,
eclipseOptions,
timer,
isEclipseAlarmEnabled,
favoriteLocations,
onSetEclipseAlarmEnabled,
onAddFavoriteLocation,
onSelectEclipse,
onUseFavoriteLocation,
onOpenMenu,
onOpenPreview,
}: TimerScreenProps) {
const insets = useSafeAreaInsets();
const { height: windowHeight } = useWindowDimensions();
const [isEclipsePickerOpen, setIsEclipsePickerOpen] = useState(false);
const [isAddFavoriteModalOpen, setIsAddFavoriteModalOpen] = useState(false);
const [favoriteModalName, setFavoriteModalName] = useState("");
const [favoriteModalDefaultName, setFavoriteModalDefaultName] = useState("");
const [favoriteModalPin, setFavoriteModalPin] = useState<{ lat: number; lon: number } | null>(
null,
);
const activeEclipseOption = useMemo(
() => eclipseOptions.find((option) => option.id === activeEclipseId) ?? null,
[activeEclipseId, eclipseOptions],
);
const mapHeight = useMemo(
() => clamp((windowHeight - insets.top - insets.bottom) * 0.4, 260, 420),
[insets.bottom, insets.top, windowHeight],
);
const activeEclipseCenter = useMemo(() => eclipseCenterForRecord(activeEclipse), [activeEclipse]);
const activeKindCode = useMemo(
() => (activeEclipse ? kindCodeForRecord(activeEclipse) : "P"),
[activeEclipse],
);
const centralOverlayColor = activeKindCode === "A" ? ANNULARITY_PATH_COLOR : TOTALITY_PATH_COLOR;
const centralLegendLabel =
activeKindCode === "A"
? "Annularity Path"
: activeKindCode === "H"
? "Central Path"
: "Totality Path";
const isPhotoMapMode = timer.mapType !== "standard";
const visibleOverlayColor = isPhotoMapMode ? "rgba(79, 195, 247, 0.12)" : VISIBLE_PATH_COLOR;
const activeCentralOverlayColor = isPhotoMapMode
? activeKindCode === "A"
? "rgba(255, 167, 38, 0.16)"
: "rgba(255, 82, 82, 0.16)"
: centralOverlayColor;
const favoriteAtCurrentPin = useMemo(
() =>
favoriteLocations.find((location) =>
isSameFavoriteLocation(location.lat, location.lon, timer.pin.lat, timer.pin.lon),
) ?? null,
[favoriteLocations, timer.pin.lat, timer.pin.lon],
);
const canAddCurrentPinToFavorites = !favoriteAtCurrentPin;
const contactDirectionOverlays = useMemo<ContactDirectionOverlay[]>(() => {
if (!timer.result || !timer.isResultCurrentForPin) return [];
const arrowDistanceDeg = clamp(timer.region.latitudeDelta * 0.28, 0.18, 2.2);
const entries = [
{
key: "c1",
label: "C1",
bearingDeg: timer.result.c1BearingDeg,
color: colorForContactKey("c1"),
},
{
key: "c2",
label: "C2",
bearingDeg: timer.result.c2BearingDeg,
color: colorForContactKey("c2"),
},
{
key: "c3",
label: "C3",
bearingDeg: timer.result.c3BearingDeg,
color: colorForContactKey("c3"),
},
{
key: "c4",
label: "C4",
bearingDeg: timer.result.c4BearingDeg,
color: colorForContactKey("c4"),
},
] as const;
const overlays: ContactDirectionOverlay[] = [];
for (const entry of entries) {
if (typeof entry.bearingDeg !== "number" || !Number.isFinite(entry.bearingDeg)) continue;
const bearingDeg = ((entry.bearingDeg % 360) + 360) % 360;
overlays.push({
key: entry.key,
label: entry.label,
color: entry.color,
bearingDeg,
endpoint: destinationPoint(timer.pin.lat, timer.pin.lon, bearingDeg, arrowDistanceDeg),
});
}
return overlays;
}, [
timer.isResultCurrentForPin,
timer.pin.lat,
timer.pin.lon,
timer.region.latitudeDelta,
timer.result,
]);
const hasDirectionsData = contactDirectionOverlays.length > 0;
const mapTypeText = mapTypeLabel(timer.mapType);
const maxEventMoonGeometry = useMemo(() => {
if (!timer.result) return null;
const result = timer.result;
const contactProgress = buildPreviewContactProgress(result);
const progressAtMax = typeof contactProgress.max === "number" ? contactProgress.max : 0.5;
return calculatePreviewMoonGeometry({
progress: progressAtMax,
kindAtLocation: result.kindAtLocation,
magnitude: result.magnitude,
contacts: contactProgress,
stageSize: TIMER_HERO_PREVIEW_STAGE_SIZE,
sunRadius: TIMER_HERO_PREVIEW_SUN_RADIUS,
travelVector: determinePreviewTravelVector({
c1BearingDeg: result.c1BearingDeg,
c2BearingDeg: result.c2BearingDeg,
c3BearingDeg: result.c3BearingDeg,
c4BearingDeg: result.c4BearingDeg,
}),
});
}, [timer.result]);
const closeAddFavoriteModal = () => {
setIsAddFavoriteModalOpen(false);
setFavoriteModalName("");
setFavoriteModalDefaultName("");
setFavoriteModalPin(null);
};
const closeEclipsePicker = () => {
setIsEclipsePickerOpen(false);
};
const openAddFavoriteModal = () => {
if (!canAddCurrentPinToFavorites) return;
const nextPin = { lat: timer.pin.lat, lon: timer.pin.lon };
const compiledDefaultName = buildDefaultFavoriteName(
nextPin.lat,
nextPin.lon,
favoriteLocations,
);
setFavoriteModalPin(nextPin);
setFavoriteModalDefaultName(compiledDefaultName);
setFavoriteModalName(compiledDefaultName);
setIsAddFavoriteModalOpen(true);
};
const submitAddFavorite = () => {
if (!favoriteModalPin) return;
const name = favoriteModalName.trim() || favoriteModalDefaultName;
onAddFavoriteLocation({
name,
lat: favoriteModalPin.lat,
lon: favoriteModalPin.lon,
});
timer.setStatusMessage(`Saved ${name} to favorites`);
closeAddFavoriteModal();
};
const openEclipsePicker = () => {
if (!eclipseOptions.length) return;
setIsEclipsePickerOpen(true);
};
const selectEclipseFromPicker = (eclipseId: string) => {
const normalizedId = eclipseId.trim();
if (!normalizedId) return;
closeEclipsePicker();
onSelectEclipse(normalizedId);
};
return (
<SafeAreaView style={styles.safe} edges={["top", "left", "right", "bottom"]}>
<View style={styles.header}>
<BurgerButton onPress={onOpenMenu} />
<View style={styles.headerMeta}>
<View style={styles.headerBrandRow}>
<Image source={APP_LOGO} style={styles.headerLogo} resizeMode="contain" />
<Text style={styles.title}>Eclipse Timer (MVP)</Text>
</View>
<Text style={styles.subtitle}>
{isActiveEclipseLoading
? "Loading eclipse data..."
: activeEclipse
? `${activeEclipse.id} - ${activeEclipse.dateYmd}`
: "No eclipse loaded"}
</Text>
</View>
</View>
<View style={styles.eclipseSwitcherWrap}>
<Pressable
style={[
styles.eclipseSwitcherBtn,
isActiveEclipseLoading ? styles.eclipseSwitcherBtnDisabled : null,
]}
onPress={openEclipsePicker}
disabled={!eclipseOptions.length || isActiveEclipseLoading}
accessibilityRole="button"
accessibilityLabel="Switch active eclipse"
accessibilityState={{ disabled: !eclipseOptions.length || isActiveEclipseLoading }}
>
<View style={styles.eclipseSwitcherRow}>
<Text style={styles.eclipseSwitcherLabel}>Active Eclipse</Text>
<Text style={styles.eclipseSwitcherValue}>
{activeEclipseOption
? `${activeEclipseOption.dateYmd} - ${activeEclipseOption.kindLabel}`
: "No eclipse selected"}
</Text>
<Text style={styles.eclipseSwitcherHint}>Switch</Text>
</View>
</Pressable>
</View>
<View style={[styles.mapWrap, { height: mapHeight }]}>
<MapView
key={`map-${timer.mapType}`}
ref={timer.mapRef}
style={styles.map}
region={timer.region}
onRegionChangeComplete={timer.onRegionChangeComplete}
onPress={timer.onMapPress}
mapType={timer.mapType}
showsBuildings
showsCompass
showsIndoors
showsPointsOfInterest
>
{timer.showVisibleOverlay
? timer.overlayVisiblePolygons.map((coordinates, idx) => (
<Polygon
key={`visible-${idx}`}
coordinates={coordinates}
fillColor={visibleOverlayColor}
strokeColor="rgba(79, 195, 247, 0.05)"
strokeWidth={0.5}
/>
))
: null}
{timer.showCentralOverlay
? timer.overlayCentralPolygons.map((coordinates, idx) => (
<Polygon
key={`central-${idx}`}
coordinates={coordinates}
fillColor={activeCentralOverlayColor}
strokeColor="rgba(255,255,255,0.08)"
strokeWidth={0.5}
/>
))
: null}
<Marker
coordinate={{ latitude: timer.pin.lat, longitude: timer.pin.lon }}
draggable
onDragEnd={timer.onDragEnd}
title="Observer"
description={`${timer.pin.lat.toFixed(4)}, ${timer.pin.lon.toFixed(4)}`}
/>
{timer.showDirectionsOverlay
? contactDirectionOverlays.map((direction) => (
<Polyline
key={`direction-line-${direction.key}`}
coordinates={[
{ latitude: timer.pin.lat, longitude: timer.pin.lon },
direction.endpoint,
]}
strokeColor={direction.color}
strokeWidth={2}
lineDashPattern={[5, 4]}
/>
))
: null}
{timer.showDirectionsOverlay
? contactDirectionOverlays.map((direction) => (
<Marker
key={`direction-marker-${direction.key}`}
coordinate={direction.endpoint}
anchor={{ x: 0.5, y: 0.5 }}
tracksViewChanges={false}
title={`${direction.label} direction`}
description={`${Math.round(direction.bearingDeg)}° from pin`}
>
<View style={styles.contactDirectionBadge}>
<Text
style={[
styles.contactDirectionArrow,
{
color: direction.color,
transform: [{ rotate: `${direction.bearingDeg}deg` }],
},
]}
>
▲
</Text>
<Text style={[styles.contactDirectionLabel, { color: direction.color }]}>
{direction.label}
</Text>
</View>
</Marker>
))
: null}
</MapView>
<Pressable
style={styles.mapGpsBtn}
onPress={timer.useGps}
accessibilityRole="button"
accessibilityLabel="Use current GPS location"
>
<View style={styles.mapGpsIcon}>
<View style={styles.mapGpsIconCrossVertical} />
<View style={styles.mapGpsIconCrossHorizontal} />
<View style={styles.mapGpsIconRing}>
<View style={styles.mapGpsIconDot} />
</View>
</View>
</Pressable>
<Pressable style={styles.mapOverlayBtn} onPress={timer.cycleMapType}>
<Text style={styles.mapOverlayBtnText}>{mapTypeText}</Text>
</Pressable>
<View style={styles.mapLegendStack}>
{timer.result && timer.isResultCurrentForPin ? (
<Pressable
style={[
styles.mapDirectionLegend,
!timer.showDirectionsOverlay ? styles.mapLegendMuted : null,
!hasDirectionsData ? styles.mapLegendDisabled : null,
]}
onPress={timer.toggleDirectionsOverlay}
disabled={!hasDirectionsData}
accessibilityRole="button"
accessibilityLabel={
timer.showDirectionsOverlay ? "Hide direction overlays" : "Show direction overlays"
}
>
{contactDirectionOverlays.map((direction) => (
<View
key={`direction-legend-${direction.key}`}
style={styles.mapDirectionLegendRow}
>
<View
style={[styles.mapDirectionLegendLine, { borderTopColor: direction.color }]}
/>
<Text style={[styles.mapDirectionLegendText, { color: direction.color }]}>
{direction.label}
</Text>
</View>
))}
</Pressable>
) : null}
<View style={styles.mapLegend}>
<Pressable
style={[
styles.mapLegendItem,
!timer.showVisibleOverlay ? styles.mapLegendMuted : null,
!timer.hasVisibleOverlayData ? styles.mapLegendDisabled : null,
]}
onPress={timer.toggleVisibleOverlay}
disabled={!timer.hasVisibleOverlayData}
accessibilityRole="button"
accessibilityLabel={
timer.showVisibleOverlay
? "Hide eclipse visible overlay"
: "Show eclipse visible overlay"
}
>
<View style={styles.mapLegendRow}>
<View style={[styles.mapLegendSwatch, { backgroundColor: visibleOverlayColor }]} />
<Text style={styles.mapLegendText}>Eclipse Visible</Text>
</View>
</Pressable>
<Pressable
style={[
styles.mapLegendItem,
!timer.showCentralOverlay ? styles.mapLegendMuted : null,
!timer.hasCentralOverlayData ? styles.mapLegendDisabled : null,
]}
onPress={timer.toggleCentralOverlay}
disabled={!timer.hasCentralOverlayData}
accessibilityRole="button"
accessibilityLabel={
timer.showCentralOverlay ? "Hide central path overlay" : "Show central path overlay"
}
>
<View style={styles.mapLegendRow}>
<View
style={[styles.mapLegendSwatch, { backgroundColor: activeCentralOverlayColor }]}
/>
<Text style={styles.mapLegendText}>{centralLegendLabel}</Text>
</View>
</Pressable>
</View>
</View>
</View>
<View style={styles.controls}>
<View style={styles.btnRowCompact}>
<Pressable
style={[styles.btnCompact, isActiveEclipseLoading ? styles.btnDisabled : null]}
onPress={() => {
if (!activeEclipseCenter) {
timer.setStatusMessage("No center coordinates available for this eclipse");
return;
}
timer.jumpTo(activeEclipseCenter.lat, activeEclipseCenter.lon, 3);
}}
disabled={isActiveEclipseLoading}
>
<Text style={styles.btnCompactText}>Greatest Eclipse</Text>
</Pressable>
<Pressable
style={[styles.btnCompact, !canAddCurrentPinToFavorites ? styles.btnDisabled : null]}
onPress={openAddFavoriteModal}
disabled={!canAddCurrentPinToFavorites}
>
<Text style={styles.btnCompactText}>
{canAddCurrentPinToFavorites ? "Add Favorite" : "Saved"}
</Text>
</Pressable>
</View>
</View>
<Modal
visible={isEclipsePickerOpen}
transparent
animationType="fade"
onRequestClose={closeEclipsePicker}
>
<View style={styles.eclipsePickerBackdrop}>
<View style={styles.eclipsePickerCard}>
<Text style={styles.eclipsePickerTitle}>Select Eclipse</Text>
<Text style={styles.eclipsePickerSubtitle}>
Switch eclipses without leaving the timer screen.
</Text>
<FlatList
data={eclipseOptions}
keyExtractor={(item) => item.id}
style={styles.eclipsePickerList}
contentContainerStyle={styles.eclipsePickerListContent}
renderItem={({ item }) => {
const isSelected = item.id === activeEclipseId;
return (
<Pressable
style={[
styles.eclipsePickerItem,
isSelected ? styles.eclipsePickerItemSelected : null,
]}
onPress={() => selectEclipseFromPicker(item.id)}
accessibilityRole="button"
accessibilityLabel={`${item.dateYmd} ${item.kindLabel}, ${item.isPast ? "past" : "upcoming"}`}
accessibilityState={{ selected: isSelected }}
>
<Text
style={[
styles.eclipsePickerItemTitle,
isSelected ? styles.eclipsePickerItemTitleSelected : null,
]}
>
{item.dateYmd} {item.kindLabel}
</Text>
<Text
style={[
styles.eclipsePickerItemMeta,
isSelected ? styles.eclipsePickerItemMetaSelected : null,
]}
>
{item.id} - {item.isPast ? "Past" : "Upcoming"}
</Text>
</Pressable>
);
}}
/>
<Pressable style={styles.eclipsePickerCloseBtn} onPress={closeEclipsePicker}>
<Text style={styles.eclipsePickerCloseText}>Close</Text>
</Pressable>
</View>
</View>
</Modal>
<Modal
visible={isAddFavoriteModalOpen}
transparent
animationType="fade"
onRequestClose={closeAddFavoriteModal}
>
<View style={styles.favoriteModalBackdrop}>
<View style={styles.favoriteModalCard}>
<Text style={styles.favoriteModalTitle}>Add to Favorites</Text>
<Text style={styles.favoriteModalSubtitle}>Name this location (optional)</Text>
<TextInput
value={favoriteModalName}
onChangeText={setFavoriteModalName}
placeholder={favoriteModalDefaultName}
placeholderTextColor="#707070"
style={styles.favoriteModalInput}
autoCapitalize="words"
autoCorrect={false}
autoFocus
/>
{favoriteModalPin ? (
<Text style={styles.favoriteModalCoords}>
{favoriteModalPin.lat.toFixed(4)}, {favoriteModalPin.lon.toFixed(4)}
</Text>
) : null}
<View style={styles.favoriteModalActions}>
<Pressable style={styles.favoriteModalCancelBtn} onPress={closeAddFavoriteModal}>
<Text style={styles.favoriteModalCancelText}>Cancel</Text>
</Pressable>
<Pressable style={styles.favoriteModalSaveBtn} onPress={submitAddFavorite}>
<Text style={styles.favoriteModalSaveText}>Save</Text>
</Pressable>
</View>
</View>
</View>
</Modal>
<View style={styles.favoriteWrap}>
{favoriteLocations.length ? (
<ScrollView
horizontal
showsHorizontalScrollIndicator={false}
contentContainerStyle={styles.favoriteList}
>
{favoriteLocations.map((location) => (
<Pressable
key={location.id}
style={styles.favoriteChip}
onPress={() => onUseFavoriteLocation(location)}
>
<Text style={styles.favoriteChipText}>{location.name}</Text>
</Pressable>
))}
</ScrollView>
) : (
<Text style={styles.favoriteEmpty}>
No saved favorites yet. Add one from Menu {" > "} Location Settings.
</Text>
)}
</View>
<View style={styles.statusBar}>
<Text style={styles.statusText}>{timer.status}</Text>
</View>
<ScrollView
style={styles.results}
contentContainerStyle={[
styles.resultsContent,
{ paddingBottom: Math.max(28, insets.bottom + 18) },
]}
>
<Animated.View
style={[
styles.card,
{
transform: [
{
scale: timer.resultFlash.interpolate({
inputRange: [0, 1],
outputRange: [1, 1.02],
}),
},
],
opacity: timer.resultFlash.interpolate({
inputRange: [0, 1],
outputRange: [1, 0.92],
}),
},
]}
>
{isActiveEclipseLoading && !timer.result ? (
<View style={styles.loadingCardState}>
<ActivityIndicator />
<Text style={styles.muted}>Loading overlays and eclipse metadata...</Text>
</View>
) : !timer.result ? (
<Text style={styles.muted}>
{timer.isComputing
? "Computing eclipse circumstances..."
: "Eclipse circumstances will auto-compute for the current pin."}
</Text>
) : (
<>
<View style={styles.timerHero}>
<View style={styles.timerHeroSplit}>
<View style={styles.timerHeroMain}>
<Text style={styles.timerHeroLabel}>Next Event Timer</Text>
<Text style={styles.timerHeroText}>{timer.nextEventCountdownText}</Text>
</View>
<View style={styles.timerHeroPreviewWrap}>
<Text style={styles.timerHeroPreviewLabel}>MAX View</Text>
<View style={styles.timerHeroPreviewStage}>
<View style={styles.timerHeroPreviewSunGlow} />
<View style={styles.timerHeroPreviewSunDisk} />
{maxEventMoonGeometry ? (
<View
style={[
styles.timerHeroPreviewMoon,
{
width: maxEventMoonGeometry.moonRadius * 2,
height: maxEventMoonGeometry.moonRadius * 2,
borderRadius: maxEventMoonGeometry.moonRadius,
left:
maxEventMoonGeometry.moonCenterX - maxEventMoonGeometry.moonRadius,
top:
maxEventMoonGeometry.moonCenterY - maxEventMoonGeometry.moonRadius,
},
]}
/>
) : null}
</View>
</View>
</View>
</View>
<View style={styles.metricRow}>
<View style={styles.metricTile}>
<Text style={styles.metricLabel}>Type</Text>
<Text style={styles.metricValue}>
{localKindLabel(timer.result.kindAtLocation)}
</Text>
</View>
<View style={styles.metricTile}>
<Text style={styles.metricLabel}>C1-C4 Duration</Text>
<Text style={styles.metricValue}>{formatC1ToC4Duration(timer.result)}</Text>
</View>
<View style={styles.metricTile}>
<Text style={styles.metricLabel}>Totality Duration</Text>
<Text style={styles.metricValue}>
{formatTimerDuration(timer.result.durationSeconds)}
</Text>
</View>
</View>
<View style={styles.eclipseAlarmCard}>
<View style={styles.eclipseAlarmCardMain}>
<Text style={styles.eclipseAlarmCardTitle}>
Enable alarms and reminders for this eclipse
</Text>
<Text style={styles.eclipseAlarmCardDescription}>
Enables fixed T-1h/T-10m reminders and per-event in-app `a1/a2` alarms.
</Text>
</View>
<Switch
value={isEclipseAlarmEnabled}
onValueChange={onSetEclipseAlarmEnabled}
disabled={!activeEclipse}
accessibilityRole="switch"
accessibilityLabel="Enable alarms and reminders for this eclipse"
/>
</View>
{!timer.notificationsEnabled ? (
<Text style={styles.notificationsDisabledHint}>
Eclipse alarms/reminders are off for this eclipse. Enable them above.
</Text>
) : null}
<View style={styles.sep} />
{timer.contactItems.map((item) => (
<View
style={[
styles.contactRow,
!isEclipseAlarmEnabled ? styles.contactRowDisabled : null,
]}
key={item.key}
>
<View style={styles.contactMain}>
<View style={styles.contactLabelRow}>
<View
style={[
styles.contactKeyBadge,
{
borderColor: colorForContactKey(item.key),
backgroundColor: "rgba(255,255,255,0.04)",
},
]}
>
<Text
style={[
styles.contactKeyBadgeText,
{ color: colorForContactKey(item.key) },
]}
>
{item.key === "max" ? "MAX" : item.key.toUpperCase()}
</Text>
</View>
<Text style={styles.contactLabel}>{item.label}</Text>
</View>
<Text style={styles.contactTime}>UTC: {fmtUtcHuman(item.iso)}</Text>
<Text
style={[styles.contactTimeLocal, { color: colorForContactKey(item.key) }]}
>
Local: {fmtLocalHuman(item.iso)}
</Text>
</View>
<View style={styles.contactAlarm}>
<Text style={styles.alarmLabel}>Alarm</Text>
<Switch
value={timer.alarmState[item.key]}
onValueChange={(enabled) => timer.toggleAlarm(item.key, enabled)}
disabled={!item.iso || !isEclipseAlarmEnabled}
/>
</View>
</View>
))}
<Pressable
style={styles.previewBtn}
onPress={() => {
if (!timer.result) return;
onOpenPreview(timer.result);
}}
>
<Text style={styles.previewBtnText}>Preview</Text>
</Pressable>
</>
)}
</Animated.View>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
safe: { flex: 1, backgroundColor: "#0b0b0b" },
header: {
paddingHorizontal: 12,
paddingTop: 8,
paddingBottom: 6,
flexDirection: "row",
alignItems: "center",
gap: 10,
},
headerMeta: {
flex: 1,
gap: 2,
},
headerBrandRow: {
flexDirection: "row",
alignItems: "center",
gap: 8,
},
headerLogo: {
width: 20,
height: 20,
},
title: { color: "white", fontSize: 18, fontWeight: "700" },
subtitle: { color: "#bdbdbd", fontSize: 12 },
eclipseSwitcherWrap: {
paddingHorizontal: 12,
paddingBottom: 6,
},
eclipseSwitcherBtn: {
borderRadius: 12,
borderWidth: 1,
borderColor: "#2e3566",
backgroundColor: "#151a43",
paddingVertical: 8,
paddingHorizontal: 10,
},
eclipseSwitcherBtnDisabled: {
opacity: 0.68,
},
eclipseSwitcherRow: {
flexDirection: "row",
alignItems: "center",
gap: 8,
},
eclipseSwitcherLabel: {
color: "#b7beff",
fontSize: 10,
fontWeight: "700",
textTransform: "uppercase",
letterSpacing: 0.4,
},
eclipseSwitcherHint: {
color: "#d9dcff",
fontSize: 10,
fontWeight: "700",
},