@super-calendar/native 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
1
  import {
2
- LegendList,
3
2
  type LegendListRef,
4
3
  type LegendListRenderItemProps,
5
4
  type OnViewableItemsChangedInfo,
6
5
  } from "@legendapp/list/react-native";
6
+ import { AnimatedLegendList } from "@legendapp/list/reanimated";
7
7
  import {
8
8
  addDays,
9
9
  differenceInCalendarDays,
@@ -31,6 +31,9 @@ import {
31
31
  import {
32
32
  type AccessibilityActionEvent,
33
33
  type GestureResponderEvent,
34
+ type LayoutChangeEvent,
35
+ type NativeScrollEvent,
36
+ type NativeSyntheticEvent,
34
37
  Platform,
35
38
  Pressable,
36
39
  StyleSheet,
@@ -40,11 +43,11 @@ import {
40
43
  useWindowDimensions,
41
44
  View,
42
45
  type ViewStyle,
46
+ type ScrollViewProps,
43
47
  } from "react-native";
44
48
  import { Gesture, GestureDetector } from "react-native-gesture-handler";
45
49
  import Animated, {
46
50
  runOnJS,
47
- scrollTo,
48
51
  type SharedValue,
49
52
  useAnimatedReaction,
50
53
  useAnimatedRef,
@@ -155,28 +158,31 @@ const DEFAULT_DRAG_STEP_MINUTES = 15;
155
158
  // moved over a later event would fall behind it).
156
159
  const DRAG_EVENT_Z = 100;
157
160
  // How long to hold the dragged event past the visible columns before the view
158
- // pages one period toward that edge.
159
- const EDGE_DWELL_MS = 500;
161
+ // pages one period toward that edge, and the interval between further pages
162
+ // while the finger stays there.
163
+ const EDGE_DWELL_MS = 600;
164
+ const EDGE_REPEAT_MS = 700;
160
165
  // How close (px) the dragging finger must get to the pager's left/right edge to
161
166
  // count as "past the columns". Detecting by finger position, not by how many
162
167
  // columns the drag has crossed, so an event in any column can reach either edge
163
- // (a column-delta test can't reach the far edge from a near-side column).
164
- const EDGE_ZONE_PX = 36;
168
+ // (a column-delta test can't reach the far edge from a near-side column). Kept
169
+ // narrow: on a phone the last column is only a few times this wide.
170
+ const EDGE_ZONE_PX = 24;
165
171
 
166
172
  /**
167
173
  * Lets a per-event drag worklet, deep inside the pager, drive a cross-week drag:
168
- * locate the pager's edges, freeze the swipe scroll while paging (a native
169
- * programmatic scroll is otherwise deferred until the touch ends, so the view
170
- * would only advance once the finger lifts), and hand the event off to a floating
171
- * ghost that survives the source page paging away, then commit on release.
174
+ * locate the pager's edges, page the view under the held finger, and hand the
175
+ * event off to a floating ghost that survives the source page paging away, then
176
+ * commit on release.
172
177
  */
173
178
  type EdgePaging = {
174
179
  // Pager frame in window space, so the worklet can find the edges and place the
175
180
  // ghost (its top-left is the window origin the finger coords are relative to).
181
+ // The pager scrolls with the grid, so its top is derived live from the scroll
182
+ // viewport's top and the current offset.
176
183
  pagerLeft: SharedValue<number>;
177
- pagerTop: SharedValue<number>;
184
+ pagerTop: ReturnType<typeof useDerivedValue<number>>;
178
185
  pagerWidth: SharedValue<number>;
179
- lockScroll: (locked: boolean) => void;
180
186
  // The floating "held" copy of the dragged event: pager-local top-left, size, and
181
187
  // visibility, driven on the UI thread so it tracks the finger across the page.
182
188
  ghostX: SharedValue<number>;
@@ -184,8 +190,8 @@ type EdgePaging = {
184
190
  ghostW: SharedValue<number>;
185
191
  ghostH: SharedValue<number>;
186
192
  ghostVisible: SharedValue<number>;
187
- // Show the ghost for `event`, then drop it at pager-local `ghostLocalX` shifted
188
- // in time by `minuteDelta` (clearing the ghost either way).
193
+ // Show the ghost for `event`, then drop it at its pager-local top-left
194
+ // (clearing the ghost either way).
189
195
  beginLift: (event: CalendarEvent<unknown>) => void;
190
196
  commitLiftedDrop: (ghostLocalX: number, minuteDelta: number) => void;
191
197
  };
@@ -318,7 +324,14 @@ export type { EventDragHandler, EventDragStartHandler } from "../types";
318
324
  // Hour labels are nudged up so the number sits centred on its grid line. Pad the
319
325
  // scroll content by the same amount so the top-most label is never clipped.
320
326
  const HOUR_LABEL_TOP_INSET = 12;
327
+ // Least height the all-day band keeps, so the lane inside stays measurable (see
328
+ // the band's height style).
329
+ const LANE_BAND_FLOOR = 1;
321
330
  const HOUR_LABEL_NUDGE = 6;
331
+ // Fixed height of the day-header row. The header pages with the columns (it
332
+ // lives inside each page), so the hour column's corner, the all-day band, and
333
+ // the hours all offset by this without measuring the header per page.
334
+ const DAY_HEADER_HEIGHT = 56;
322
335
 
323
336
  type AnimatedEventBoxProps<T> = {
324
337
  positioned: PositionedEvent<T>;
@@ -368,7 +381,7 @@ type AnimatedEventBoxProps<T> = {
368
381
  onEdgeAdvance?: (dir: number) => void;
369
382
  };
370
383
 
371
- function AnimatedEventBox<T>({
384
+ function AnimatedEventBoxInner<T>({
372
385
  positioned,
373
386
  eventIndex,
374
387
  movingEvent,
@@ -402,8 +415,8 @@ function AnimatedEventBox<T>({
402
415
  const RenderEventComponent = renderEvent;
403
416
  const theme = useCalendarTheme();
404
417
  const slot = useSlots<TimeGridSlot>();
405
- // Pager geometry + scroll lock, so a cross-week edge drag can find the edges
406
- // and page the view live under the finger (see EdgePaging). The two edge
418
+ // Pager geometry, so a cross-week edge drag can find the edges and page the
419
+ // view live under the finger (see EdgePaging). The two edge
407
420
  // shared values are pulled out so the move worklet closes over them directly
408
421
  // rather than over the whole context object (which also holds a JS callback).
409
422
  const edgePaging = useContext(EdgePagingContext);
@@ -515,13 +528,16 @@ function AnimatedEventBox<T>({
515
528
  // already renders. Purely geometric, so a resting box (already clipped to the
516
529
  // day by `layoutDayEvents`) is untouched and the height doesn't jump when a
517
530
  // drag commits.
531
+ // Hidden while lifted: the floating ghost stands in for the box until the
532
+ // drop commits (and, for a multi-day move, while the preview draws it).
518
533
  return {
519
534
  top,
520
535
  height: visibleBoxHeight.value,
521
536
  transform: [{ translateX: moveOffsetX.value }],
522
537
  zIndex: dragZ.value,
538
+ opacity: hiddenForMove || lifted.value ? 0 : 1,
523
539
  };
524
- }, [startHours, minHour]);
540
+ }, [startHours, minHour, hiddenForMove]);
525
541
 
526
542
  // Pixel height of the part of a move that runs past midnight, or 0 when nothing
527
543
  // spills. Measured against the end of the day, not `maxHour`: a narrowed window
@@ -592,8 +608,22 @@ function AnimatedEventBox<T>({
592
608
 
593
609
  // Keep the latest event/handler in a ref so the gestures stay memoized but
594
610
  // never call into a stale closure.
595
- const latest = useRef({ event: positioned.event, eventIndex, onDragEvent, onDragStart });
596
- latest.current = { event: positioned.event, eventIndex, onDragEvent, onDragStart };
611
+ const latest = useRef({
612
+ event: positioned.event,
613
+ eventIndex,
614
+ onDragEvent,
615
+ onDragStart,
616
+ onPress,
617
+ onLongPress,
618
+ });
619
+ latest.current = {
620
+ event: positioned.event,
621
+ eventIndex,
622
+ onDragEvent,
623
+ onDragStart,
624
+ onPress,
625
+ onLongPress,
626
+ };
597
627
 
598
628
  // Snap the box back to where it started (drop rejected or degenerate).
599
629
  const snapBack = useCallback(() => {
@@ -658,9 +688,9 @@ function AnimatedEventBox<T>({
658
688
 
659
689
  // Edge auto-advance dwell. Dragging the event past the visible columns and
660
690
  // holding there pages the view one period and carries the event onto it: same
661
- // weekday, keeping whatever time the vertical drag has reached. It fires once
662
- // per drag (the box unmounts as the page changes), matching "hold at the edge
663
- // to move to the next/previous week"; the tested commit path does the move.
691
+ // weekday, keeping whatever time the vertical drag has reached. It keeps paging
692
+ // while the finger stays at the edge, matching "hold at the edge to move to the
693
+ // next/previous week"; the tested commit path does the move.
664
694
  const dwellTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
665
695
  const disarmEdge = useCallback(() => {
666
696
  if (dwellTimer.current) {
@@ -668,22 +698,14 @@ function AnimatedEventBox<T>({
668
698
  dwellTimer.current = null;
669
699
  }
670
700
  }, []);
671
- // Cancel a pending dwell and hand the pager's swipe scroll back. Runs on every
672
- // gesture end so a lock taken by an edge-page is always released.
673
- const releaseEdge = useCallback(() => {
674
- disarmEdge();
675
- edgePaging?.lockScroll(false);
676
- }, [disarmEdge, edgePaging]);
701
+ // Cancel a pending dwell. Runs on every gesture end.
702
+ const releaseEdge = disarmEdge;
677
703
  const armEdge = useCallback(
678
704
  (dir: number) => {
679
705
  disarmEdge();
680
- dwellTimer.current = setTimeout(() => {
706
+ const fire = () => {
681
707
  dwellTimer.current = null;
682
708
  if (!edgePaging) return;
683
- // Freeze the pager's own swipe before paging: on native a programmatic
684
- // scroll is deferred while the touch is tracked, so without this the view
685
- // wouldn't advance until the finger lifts.
686
- edgePaging.lockScroll(true);
687
709
  // First edge fire: lift the event into the floating ghost. It must NOT
688
710
  // commit here — committing relocates the event off this page, which
689
711
  // unmounts the dragging box and kills the gesture. Instead the ghost
@@ -700,7 +722,9 @@ function AnimatedEventBox<T>({
700
722
  edgePaging.beginLift(latest.current.event as CalendarEvent<unknown>);
701
723
  }
702
724
  onEdgeAdvance?.(dir);
703
- }, EDGE_DWELL_MS);
725
+ dwellTimer.current = setTimeout(fire, EDGE_REPEAT_MS);
726
+ };
727
+ dwellTimer.current = setTimeout(fire, EDGE_DWELL_MS);
704
728
  },
705
729
  [
706
730
  disarmEdge,
@@ -875,69 +899,120 @@ function AnimatedEventBox<T>({
875
899
  releaseEdge,
876
900
  ]);
877
901
 
878
- const resizeGesture = useMemo(
879
- () =>
880
- Gesture.Pan()
881
- .enabled(resizable)
882
- .onStart(() => {
883
- dragZ.value = DRAG_EVENT_Z;
884
- runOnJS(notifyDragStart)();
885
- })
886
- .onUpdate((event) => {
887
- resizeDelta.value = event.translationY;
888
- })
889
- .onEnd((event) => {
890
- const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
891
- if (delta === 0) {
892
- resizeDelta.value = 0;
893
- return;
894
- }
895
- resizeDelta.value = (delta / MINUTES_PER_HOUR) * cellHeight.value;
896
- runOnJS(commitDrag)(0, delta);
897
- })
898
- .onFinalize(() => {
899
- dragZ.value = 0;
900
- }),
901
- [resizable, snapMinutes, cellHeight, resizeDelta, dragZ, commitDrag, notifyDragStart],
902
- );
902
+ // Stable callbacks that read the event and handlers from the ref, so the
903
+ // resize gestures below keep their identity across renders.
904
+ const handlePress = useCallback(() => {
905
+ const { event, onPress: press } = latest.current;
906
+ press(event);
907
+ }, []);
908
+ // A handle also takes the consumer's long press, unless a long press already
909
+ // grabs the event to move it.
910
+ const canLongPress = !canMove && onLongPress != null;
911
+ const handleLongPressFromHandle = useCallback(() => {
912
+ const { event, onLongPress: press } = latest.current;
913
+ press?.(event);
914
+ }, []);
915
+
916
+ // A plain tap on a resize handle is a press on the event. The two handles cover
917
+ // almost all of a box at the minimum height, so without this a 5- to 30-minute
918
+ // event has next to no tappable surface. A drag from a handle still resizes:
919
+ // the pan wins the race as soon as the finger moves.
920
+ const resizeGesture = useMemo(() => {
921
+ const pan = Gesture.Pan()
922
+ .enabled(resizable)
923
+ .onStart(() => {
924
+ dragZ.value = DRAG_EVENT_Z;
925
+ runOnJS(notifyDragStart)();
926
+ })
927
+ .onUpdate((event) => {
928
+ resizeDelta.value = event.translationY;
929
+ })
930
+ .onEnd((event) => {
931
+ const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
932
+ if (delta === 0) {
933
+ resizeDelta.value = 0;
934
+ return;
935
+ }
936
+ resizeDelta.value = (delta / MINUTES_PER_HOUR) * cellHeight.value;
937
+ runOnJS(commitDrag)(0, delta);
938
+ })
939
+ .onFinalize(() => {
940
+ dragZ.value = 0;
941
+ });
942
+ const tap = Gesture.Tap()
943
+ .runOnJS(true)
944
+ .onEnd((_event, success) => {
945
+ if (success) handlePress();
946
+ });
947
+ const longPress = Gesture.LongPress()
948
+ .enabled(canLongPress)
949
+ .runOnJS(true)
950
+ .onStart(() => {
951
+ handleLongPressFromHandle();
952
+ });
953
+ return Gesture.Race(pan, tap, longPress);
954
+ }, [
955
+ resizable,
956
+ snapMinutes,
957
+ cellHeight,
958
+ resizeDelta,
959
+ dragZ,
960
+ commitDrag,
961
+ notifyDragStart,
962
+ handlePress,
963
+ canLongPress,
964
+ handleLongPressFromHandle,
965
+ ]);
903
966
 
904
967
  // Top-edge resize: dragging the top changes the start (end fixed). Mirrors the
905
968
  // bottom resize but commits a start-delta and previews via resizeStartDelta.
906
- const resizeStartGesture = useMemo(
907
- () =>
908
- Gesture.Pan()
909
- .enabled(resizableFromStart)
910
- .onStart(() => {
911
- dragZ.value = DRAG_EVENT_Z;
912
- runOnJS(notifyDragStart)();
913
- })
914
- .onUpdate((event) => {
915
- resizeStartDelta.value = event.translationY;
916
- })
917
- .onEnd((event) => {
918
- const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
919
- if (delta === 0) {
920
- resizeStartDelta.value = 0;
921
- return;
922
- }
923
- resizeStartDelta.value = (delta / MINUTES_PER_HOUR) * cellHeight.value;
924
- runOnJS(commitDrag)(delta, 0);
925
- })
926
- .onFinalize(() => {
927
- dragZ.value = 0;
928
- }),
929
- [
930
- resizableFromStart,
931
- snapMinutes,
932
- cellHeight,
933
- resizeStartDelta,
934
- dragZ,
935
- commitDrag,
936
- notifyDragStart,
937
- ],
938
- );
969
+ const resizeStartGesture = useMemo(() => {
970
+ const pan = Gesture.Pan()
971
+ .enabled(resizableFromStart)
972
+ .onStart(() => {
973
+ dragZ.value = DRAG_EVENT_Z;
974
+ runOnJS(notifyDragStart)();
975
+ })
976
+ .onUpdate((event) => {
977
+ resizeStartDelta.value = event.translationY;
978
+ })
979
+ .onEnd((event) => {
980
+ const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
981
+ if (delta === 0) {
982
+ resizeStartDelta.value = 0;
983
+ return;
984
+ }
985
+ resizeStartDelta.value = (delta / MINUTES_PER_HOUR) * cellHeight.value;
986
+ runOnJS(commitDrag)(delta, 0);
987
+ })
988
+ .onFinalize(() => {
989
+ dragZ.value = 0;
990
+ });
991
+ const tap = Gesture.Tap()
992
+ .runOnJS(true)
993
+ .onEnd((_event, success) => {
994
+ if (success) handlePress();
995
+ });
996
+ const longPress = Gesture.LongPress()
997
+ .enabled(canLongPress)
998
+ .runOnJS(true)
999
+ .onStart(() => {
1000
+ handleLongPressFromHandle();
1001
+ });
1002
+ return Gesture.Race(pan, tap, longPress);
1003
+ }, [
1004
+ resizableFromStart,
1005
+ snapMinutes,
1006
+ cellHeight,
1007
+ resizeStartDelta,
1008
+ dragZ,
1009
+ commitDrag,
1010
+ notifyDragStart,
1011
+ handlePress,
1012
+ canLongPress,
1013
+ handleLongPressFromHandle,
1014
+ ]);
939
1015
 
940
- const handlePress = () => onPress(positioned.event);
941
1016
  // When movable, a long press grabs the event to move it, so don't also fire
942
1017
  // the consumer's long-press handler.
943
1018
  const handleLongPress = !canMove && onLongPress ? () => onLongPress(positioned.event) : undefined;
@@ -1004,10 +1079,7 @@ function AnimatedEventBox<T>({
1004
1079
  themed: theme.containers.timeGridEvent,
1005
1080
  });
1006
1081
  const box = (
1007
- <Animated.View
1008
- {...eventSlot}
1009
- style={[eventSlot.style, boxStyle, hiddenForMove ? { opacity: 0 } : null]}
1010
- >
1082
+ <Animated.View {...eventSlot} style={[eventSlot.style, boxStyle]}>
1011
1083
  <RenderEventComponent
1012
1084
  event={positioned.event}
1013
1085
  mode={mode}
@@ -1021,7 +1093,7 @@ function AnimatedEventBox<T>({
1021
1093
  />
1022
1094
  {resizableFromStart ? (
1023
1095
  <GestureDetector gesture={resizeStartGesture}>
1024
- <Animated.View style={styles.resizeHandleTop}>
1096
+ <Animated.View testID="resize-handle-top" style={styles.resizeHandleTop}>
1025
1097
  {showDragHandle ? (
1026
1098
  <View style={[styles.resizeGrip, { backgroundColor: theme.colors.eventText }]} />
1027
1099
  ) : null}
@@ -1030,7 +1102,7 @@ function AnimatedEventBox<T>({
1030
1102
  ) : null}
1031
1103
  {resizable ? (
1032
1104
  <GestureDetector gesture={resizeGesture}>
1033
- <Animated.View style={styles.resizeHandle}>
1105
+ <Animated.View testID="resize-handle" style={styles.resizeHandle}>
1034
1106
  {/* The grip is the only visible drag affordance; hiding it keeps the
1035
1107
  resize gesture working but removes the indicator. */}
1036
1108
  {showDragHandle ? (
@@ -1070,92 +1142,205 @@ function AnimatedEventBox<T>({
1070
1142
  );
1071
1143
  }
1072
1144
 
1145
+ // A page re-renders on every drag preview and page change; the boxes only need
1146
+ // to when their own event, geometry, or zoom source changes.
1147
+ const AnimatedEventBox = memo(AnimatedEventBoxInner) as typeof AnimatedEventBoxInner;
1148
+
1073
1149
  /** Replace the hour-axis label. Receives the hour (0–23) and the `ampm` flag. */
1074
1150
  export type HourRenderer = (hour: number, ampm: boolean) => React.ReactNode;
1075
1151
 
1076
- type HourRowProps = {
1152
+ // The hours (rows/labels) visible in the window [minHour, maxHour).
1153
+ const hourRange = (minHour: number, maxHour: number) =>
1154
+ Array.from({ length: maxHour - minHour }, (_, index) => minHour + index);
1155
+
1156
+ type HourLabelProps = {
1077
1157
  hour: number;
1078
- minHour: number;
1079
- cellHeight: SharedValue<number>;
1080
- hourColumnWidth: number;
1158
+ width: number;
1081
1159
  label: string;
1082
1160
  ampm: boolean;
1083
1161
  hourComponent?: HourRenderer;
1084
1162
  };
1085
1163
 
1086
- const HourRow = ({
1087
- hour,
1088
- minHour,
1089
- cellHeight,
1090
- hourColumnWidth,
1091
- label,
1092
- ampm,
1093
- hourComponent,
1094
- }: HourRowProps) => {
1164
+ // The hour-axis label: the consumer's `hourComponent`, or the themed text.
1165
+ const HourLabel = ({ hour, width, label, ampm, hourComponent }: HourLabelProps) => {
1095
1166
  const theme = useCalendarTheme();
1096
1167
  const slot = useSlots<TimeGridSlot>();
1097
- // Position via `top` (a layout prop), not a transform. The per-row layout pass
1098
- // as cellHeight animates keeps the ScrollView's content size in sync while
1099
- // zooming; a transform is composited and leaves the scroll range stale.
1100
- const animatedStyle = useAnimatedStyle(
1101
- () => ({ top: (hour - minHour) * cellHeight.value }),
1102
- [hour, minHour],
1168
+ return hourComponent ? (
1169
+ <View style={{ width }}>{hourComponent(hour, ampm)}</View>
1170
+ ) : (
1171
+ <Text
1172
+ {...slot<TextStyle>("hourLabel", {
1173
+ base: [styles.hourLabel, { width }],
1174
+ themed: [theme.text.hourLabel, { color: theme.colors.textMuted }],
1175
+ })}
1176
+ allowFontScaling={false}
1177
+ >
1178
+ {label}
1179
+ </Text>
1103
1180
  );
1181
+ };
1182
+
1183
+ type HourLinesProps = {
1184
+ hours: number[];
1185
+ timeslots: number;
1186
+ };
1104
1187
 
1188
+ // The grid lines of one page: a column of equal hour cells filling the hour
1189
+ // window, each holding its line at the top and its sub-hour dividers inside.
1190
+ // Layout spreads the cells as the window's height animates, so no line needs a
1191
+ // worklet of its own.
1192
+ const HourLines = memo(function HourLines({ hours, timeslots }: HourLinesProps) {
1193
+ const theme = useCalendarTheme();
1194
+ const slot = useSlots<TimeGridSlot>();
1195
+ const hourLineSlot = slot("gridLines", {
1196
+ base: [styles.hourLine, styles.nonInteractive],
1197
+ themed: { backgroundColor: theme.colors.gridLine },
1198
+ });
1199
+ const timeslotLineSlot = slot("gridLines", {
1200
+ base: [styles.timeslotLine, styles.nonInteractive],
1201
+ themed: { backgroundColor: theme.colors.gridLine },
1202
+ });
1105
1203
  return (
1106
- <Animated.View style={[styles.hourRow, styles.nonInteractive, animatedStyle]}>
1107
- {hourComponent ? (
1108
- <View style={{ width: hourColumnWidth }}>{hourComponent(hour, ampm)}</View>
1109
- ) : (
1110
- <Text
1111
- {...slot<TextStyle>("hourLabel", {
1112
- base: [styles.hourLabel, { width: hourColumnWidth }],
1113
- themed: [theme.text.hourLabel, { color: theme.colors.textMuted }],
1114
- })}
1115
- allowFontScaling={false}
1116
- >
1117
- {label}
1118
- </Text>
1119
- )}
1120
- <View
1121
- {...slot("gridLines", {
1122
- base: styles.hourLine,
1123
- themed: { backgroundColor: theme.colors.gridLine },
1124
- })}
1125
- />
1126
- </Animated.View>
1204
+ <View style={[styles.fill, styles.nonInteractive]}>
1205
+ {hours.map((hour) => (
1206
+ <View key={hour} style={styles.hourCell}>
1207
+ {Array.from({ length: Math.max(1, timeslots) }, (_, slotIndex) => (
1208
+ <View key={slotIndex} style={styles.hourCell}>
1209
+ <View {...(slotIndex === 0 ? hourLineSlot : timeslotLineSlot)} />
1210
+ </View>
1211
+ ))}
1212
+ </View>
1213
+ ))}
1214
+ </View>
1127
1215
  );
1128
- };
1216
+ });
1129
1217
 
1130
- type TimeslotLineProps = {
1131
- hour: number;
1218
+ type HourGutterProps = {
1219
+ width: number;
1132
1220
  minHour: number;
1133
- fraction: number;
1221
+ maxHour: number;
1134
1222
  cellHeight: SharedValue<number>;
1135
- hourColumnWidth: number;
1223
+ /** Height of the all-day band shared with the pages (live, follows the swipe). */
1224
+ laneHeight: SharedValue<number>;
1225
+ /** The grid's vertical offset, so the "all-day" cell can hold still at the top. */
1226
+ scrollY: SharedValue<number>;
1227
+ showLane: boolean;
1228
+ /** Draw the "all-day" text in the lane cell. Default off, so an empty lane reads
1229
+ * as neutral space rather than a labelled-but-empty row. */
1230
+ showAllDayLabel: boolean;
1231
+ /** Height of the day-header corner above the "all-day" cell (0 when the header
1232
+ * isn't paged, i.e. a custom `renderHeader` draws its own fixed header). */
1233
+ headerHeight: number;
1234
+ /** ISO week label for the corner, or null to leave it empty. */
1235
+ weekNumber: string | null;
1236
+ ampm: boolean;
1237
+ hourComponent?: HourRenderer;
1136
1238
  };
1137
1239
 
1138
- // A faint divider inside an hour row, marking a sub-hour slot (e.g. half hours).
1139
- const TimeslotLine = ({
1140
- hour,
1240
+ // The hour-axis column beside the pager. It is part of the grid's one vertical
1241
+ // scroll content, so it scrolls and zooms with the pages and holds still while
1242
+ // they swipe. Its "all-day" cell rides the scroll offset to stay pinned at the
1243
+ // top beside the pages' all-day bands, and its label rows are spread by layout
1244
+ // over the hour window, like the pages' lines.
1245
+ const HourGutterInner = ({
1246
+ width,
1141
1247
  minHour,
1142
- fraction,
1248
+ maxHour,
1143
1249
  cellHeight,
1144
- hourColumnWidth,
1145
- }: TimeslotLineProps) => {
1250
+ laneHeight,
1251
+ scrollY,
1252
+ showLane,
1253
+ showAllDayLabel,
1254
+ headerHeight,
1255
+ weekNumber,
1256
+ ampm,
1257
+ hourComponent,
1258
+ }: HourGutterProps) => {
1146
1259
  const theme = useCalendarTheme();
1147
1260
  const slot = useSlots<TimeGridSlot>();
1148
- const animatedStyle = useAnimatedStyle(
1149
- () => ({ top: (hour - minHour + fraction) * cellHeight.value }),
1150
- [hour, minHour, fraction],
1261
+ const hours = useMemo(() => hourRange(minHour, maxHour), [minHour, maxHour]);
1262
+ // Height and offset are separate styles: a style that returns a transform is
1263
+ // re-applied every time it runs, so keeping the offset apart means a swipe
1264
+ // (which only moves the band's height) sends nothing to the view.
1265
+ const laneCellHeightStyle = useAnimatedStyle(() => ({ height: laneHeight.value }));
1266
+ const pinStyle = useAnimatedStyle(() => ({ transform: [{ translateY: scrollY.value }] }));
1267
+ const rowsStyle = useAnimatedStyle(
1268
+ () => ({
1269
+ top: headerHeight + laneHeight.value + HOUR_LABEL_TOP_INSET,
1270
+ height: (maxHour - minHour) * cellHeight.value,
1271
+ }),
1272
+ [minHour, maxHour, headerHeight],
1273
+ );
1274
+ return (
1275
+ <View testID="hour-gutter" {...slot("hourGutter", { base: [styles.hourGutter, { width }] })}>
1276
+ {headerHeight > 0 ? (
1277
+ <Animated.View
1278
+ style={[
1279
+ styles.gutterCorner,
1280
+ {
1281
+ height: headerHeight,
1282
+ backgroundColor: theme.colors.surface,
1283
+ borderBottomColor: theme.colors.gridLine,
1284
+ },
1285
+ pinStyle,
1286
+ ]}
1287
+ >
1288
+ {weekNumber ? (
1289
+ <Text
1290
+ {...slot<TextStyle>("weekNumber", {
1291
+ themed: [theme.text.hourLabel, { color: theme.colors.textMuted }],
1292
+ })}
1293
+ allowFontScaling={false}
1294
+ >
1295
+ {weekNumber}
1296
+ </Text>
1297
+ ) : null}
1298
+ </Animated.View>
1299
+ ) : null}
1300
+ {showLane ? (
1301
+ <Animated.View
1302
+ style={[
1303
+ styles.laneCell,
1304
+ { top: headerHeight },
1305
+ { backgroundColor: theme.colors.surface, borderBottomColor: theme.colors.gridLine },
1306
+ laneCellHeightStyle,
1307
+ pinStyle,
1308
+ ]}
1309
+ >
1310
+ {showAllDayLabel ? (
1311
+ <Text
1312
+ {...slot<TextStyle>("allDayLabel", {
1313
+ base: styles.allDayLabel,
1314
+ themed: { color: theme.colors.textMuted },
1315
+ })}
1316
+ allowFontScaling={false}
1317
+ >
1318
+ all-day
1319
+ </Text>
1320
+ ) : null}
1321
+ </Animated.View>
1322
+ ) : null}
1323
+ <Animated.View style={[styles.gutterRows, rowsStyle]}>
1324
+ {hours.map((hour) => (
1325
+ <View key={hour} style={styles.hourCell}>
1326
+ <View style={[styles.hourRow, styles.nonInteractive]}>
1327
+ <HourLabel
1328
+ hour={hour}
1329
+ width={width}
1330
+ label={formatHour(hour, { ampm })}
1331
+ ampm={ampm}
1332
+ hourComponent={hourComponent}
1333
+ />
1334
+ </View>
1335
+ </View>
1336
+ ))}
1337
+ </Animated.View>
1338
+ </View>
1151
1339
  );
1152
- const lineSlot = slot("gridLines", {
1153
- base: [styles.timeslotLine, styles.nonInteractive, { left: hourColumnWidth }],
1154
- themed: { backgroundColor: theme.colors.gridLine },
1155
- });
1156
- return <Animated.View {...lineSlot} style={[lineSlot.style, animatedStyle]} />;
1157
1340
  };
1158
1341
 
1342
+ const HourGutter = memo(HourGutterInner);
1343
+
1159
1344
  type NowIndicatorProps = {
1160
1345
  cellHeight: SharedValue<number>;
1161
1346
  nowHours: number;
@@ -1192,6 +1377,8 @@ type ShadeBandProps = {
1192
1377
  /** Which slot/testID the band belongs to (closed hours vs background events). */
1193
1378
  slotName?: "businessHours" | "backgroundEvent";
1194
1379
  testID?: string;
1380
+ /** Let touches reach the band's content; the band itself stays transparent to them. */
1381
+ interactive?: boolean;
1195
1382
  children?: React.ReactNode;
1196
1383
  };
1197
1384
 
@@ -1207,6 +1394,7 @@ const ShadeBand = ({
1207
1394
  color,
1208
1395
  slotName = "businessHours",
1209
1396
  testID = "business-hours-shade",
1397
+ interactive = false,
1210
1398
  children,
1211
1399
  }: ShadeBandProps) => {
1212
1400
  const slot = useSlots<TimeGridSlot>();
@@ -1218,15 +1406,20 @@ const ShadeBand = ({
1218
1406
  [startHour, endHour, minHour],
1219
1407
  );
1220
1408
  const bandSlot = slot(slotName, {
1221
- base: [styles.shadeBand, styles.nonInteractive, { left, width }],
1409
+ base: [
1410
+ styles.shadeBand,
1411
+ interactive ? styles.passThrough : styles.nonInteractive,
1412
+ { left, width },
1413
+ ],
1222
1414
  themed: color === undefined ? undefined : { backgroundColor: color },
1223
1415
  });
1224
1416
  return (
1225
1417
  <Animated.View
1226
1418
  testID={testID}
1227
- // Decorative, like the dom bands' aria-hidden: never announced or focused.
1228
- accessibilityElementsHidden
1229
- importantForAccessibility="no-hide-descendants"
1419
+ // Decorative unless interactive, like the dom bands' aria-hidden: never
1420
+ // announced or focused. An interactive band exposes its content instead.
1421
+ accessibilityElementsHidden={!interactive}
1422
+ importantForAccessibility={interactive ? "auto" : "no-hide-descendants"}
1230
1423
  {...bandSlot}
1231
1424
  style={[bandSlot.style, animatedStyle]}
1232
1425
  >
@@ -1235,6 +1428,73 @@ const ShadeBand = ({
1235
1428
  );
1236
1429
  };
1237
1430
 
1431
+ type BackgroundEventBandProps<T> = {
1432
+ event: CalendarEvent<T>;
1433
+ cellHeight: SharedValue<number>;
1434
+ startHour: number;
1435
+ endHour: number;
1436
+ minHour: number;
1437
+ left: number;
1438
+ width: number;
1439
+ mode: TimeGridMode;
1440
+ continuesBefore: boolean;
1441
+ continuesAfter: boolean;
1442
+ render: RenderEvent<T>;
1443
+ onPress: (event: CalendarEvent<T>) => void;
1444
+ onLongPress?: (event: CalendarEvent<T>) => void;
1445
+ };
1446
+
1447
+ // A background event's band drawn by the consumer's component instead of the
1448
+ // themed shade. The band lets touches reach that content, and the component is
1449
+ // rendered as an element (like `renderEvent`, so it may use hooks) with the
1450
+ // event, the mode, a live boxHeight, the multi-day continuation flags and the
1451
+ // press handlers.
1452
+ function BackgroundEventBand<T>({
1453
+ event,
1454
+ cellHeight,
1455
+ startHour,
1456
+ endHour,
1457
+ minHour,
1458
+ left,
1459
+ width,
1460
+ mode,
1461
+ continuesBefore,
1462
+ continuesAfter,
1463
+ render: Render,
1464
+ onPress,
1465
+ onLongPress,
1466
+ }: BackgroundEventBandProps<T>) {
1467
+ const boxHeight = useDerivedValue(
1468
+ () => (endHour - startHour) * cellHeight.value,
1469
+ [startHour, endHour, cellHeight],
1470
+ );
1471
+ const handlePress = useCallback(() => onPress(event), [onPress, event]);
1472
+ const handleLongPress = useCallback(() => onLongPress?.(event), [onLongPress, event]);
1473
+ return (
1474
+ <ShadeBand
1475
+ cellHeight={cellHeight}
1476
+ startHour={startHour}
1477
+ endHour={endHour}
1478
+ minHour={minHour}
1479
+ left={left}
1480
+ width={width}
1481
+ slotName="backgroundEvent"
1482
+ testID="background-event-shade"
1483
+ interactive
1484
+ >
1485
+ <Render
1486
+ event={event}
1487
+ mode={mode}
1488
+ boxHeight={boxHeight}
1489
+ continuesBefore={continuesBefore}
1490
+ continuesAfter={continuesAfter}
1491
+ onPress={handlePress}
1492
+ onLongPress={onLongPress ? handleLongPress : undefined}
1493
+ />
1494
+ </ShadeBand>
1495
+ );
1496
+ }
1497
+
1238
1498
  type TimetablePageProps<T> = {
1239
1499
  mode: TimeGridMode;
1240
1500
  numberOfDays: number;
@@ -1244,38 +1504,25 @@ type TimetablePageProps<T> = {
1244
1504
  date: Date;
1245
1505
  events: CalendarEvent<T>[];
1246
1506
  cellHeight: SharedValue<number>;
1247
- hourHeight: number;
1248
1507
  // The zoom committed at the end of the last pinch. Off-screen pages animate off
1249
1508
  // this (it changes once per gesture) instead of the live cellHeight (which
1250
1509
  // changes every frame), so a pinch only re-runs the visible page's worklets.
1251
1510
  committedCellHeight: SharedValue<number>;
1252
- scrollY: SharedValue<number>;
1253
1511
  isActive: boolean;
1254
- /** Initial vertical scroll position (px): the live shared offset, so a page that
1255
- * mounts after a scroll appears there rather than snapping from the default. */
1256
- initialScrollY: number;
1257
- /** Record the rested vertical offset (px) so later-mounted pages seed from it. */
1258
- onSettleOffset: (y: number) => void;
1259
1512
  weekStartsOn: WeekStartsOn;
1260
1513
  weekEndsOn?: WeekStartsOn;
1261
- /** Full grid width (hour gutter + day columns). Comes from the container, not the window. */
1514
+ /** Width of the day columns: the pager's width (the hour column sits beside it). */
1262
1515
  width: number;
1263
- hourColumnWidth: number;
1264
1516
  minHour: number;
1265
1517
  maxHour: number;
1266
- ampm: boolean;
1267
1518
  timeslots: number;
1268
1519
  isRTL: boolean;
1269
- showAllDayEventCell: boolean;
1270
1520
  highlightWeekends: boolean;
1271
- showVerticalScrollIndicator: boolean;
1272
- verticalScrollEnabled: boolean;
1273
- hourComponent?: HourRenderer;
1274
1521
  calendarCellStyle?: (date: Date) => StyleProp<ViewStyle>;
1275
1522
  businessHours?: BusinessHours;
1276
1523
  renderBusinessHours?: (band: BusinessHoursBand) => React.ReactNode;
1277
- minHourHeight: number;
1278
- maxHourHeight: number;
1524
+ /** A component that draws a background event's band; see `Calendar`. */
1525
+ renderBackgroundEvent?: RenderEvent<T>;
1279
1526
  showNowIndicator: boolean;
1280
1527
  renderEvent: RenderEvent<T>;
1281
1528
  keyExtractor: EventKeyExtractor<T>;
@@ -1293,14 +1540,33 @@ type TimetablePageProps<T> = {
1293
1540
  onLongPressCell?: (date: Date) => void;
1294
1541
  onCreateEvent?: (start: Date, end: Date) => void;
1295
1542
  onEdgeAdvance?: (dir: number) => void;
1296
- /** Report this page's hour-grid top (below the all-day lane), while it is the
1297
- * active page, so a cross-week drop can map a ghost's Y to the right time. */
1298
- onGridTop?: (y: number) => void;
1543
+ /** This page's index in the pager: the key its all-day lane height is reported under. */
1544
+ pageIndex: number;
1545
+ /** Height of the all-day band shared by every page (live, follows the swipe). */
1546
+ laneHeight: SharedValue<number>;
1547
+ /** The grid's vertical offset, so the band can hold still at the top while the hours scroll. */
1548
+ scrollY: SharedValue<number>;
1549
+ showAllDayEventCell: boolean;
1550
+ onLaneLayout: (index: number, height: number) => void;
1551
+ /**
1552
+ * Fixed height of the page (and the pager): tall enough for the fully zoomed
1553
+ * hour window and the tallest lane seen, so neither the pager nor its item
1554
+ * containers re-lay out while the band or the zoom animate inside.
1555
+ */
1556
+ height: number;
1557
+ /** Draw this page's day-header row (pages with the columns). False when a custom
1558
+ * `renderHeader` owns a fixed header above the pager. */
1559
+ pagedHeader: boolean;
1560
+ weekdayFormat?: WeekdayFormat;
1561
+ locale?: Locale;
1562
+ activeDate?: Date;
1563
+ onPressDateHeader?: (date: Date) => void;
1299
1564
  };
1300
1565
 
1301
- // A single date's grid: the pinch-zoomable, vertically-scrolling time column.
1302
- // Three of these are mounted side by side inside the pager so the previous and
1303
- // next dates are ready to drag into view.
1566
+ // One page of day columns: the tall, non-scrolling content for a single date
1567
+ // range. Pages sit side by side in the horizontal pager, which itself lives in
1568
+ // the grid's one vertical scroll view, so every page and the hour column share
1569
+ // that scroll position and zoom.
1304
1570
  function TimetablePageInner<T>({
1305
1571
  mode,
1306
1572
  numberOfDays,
@@ -1310,32 +1576,21 @@ function TimetablePageInner<T>({
1310
1576
  date,
1311
1577
  events,
1312
1578
  cellHeight,
1313
- hourHeight,
1314
1579
  committedCellHeight,
1315
- scrollY,
1316
1580
  isActive,
1317
- initialScrollY,
1318
- onSettleOffset,
1319
1581
  weekStartsOn,
1320
1582
  weekEndsOn,
1321
1583
  width,
1322
- hourColumnWidth,
1323
1584
  minHour,
1324
1585
  maxHour,
1325
- ampm,
1326
1586
  timeslots,
1327
1587
  isRTL,
1328
- showAllDayEventCell,
1329
1588
  highlightWeekends,
1330
- showVerticalScrollIndicator,
1331
- verticalScrollEnabled,
1332
- hourComponent,
1333
1589
  calendarCellStyle,
1334
- minHourHeight,
1335
- maxHourHeight,
1336
1590
  showNowIndicator,
1337
1591
  businessHours,
1338
1592
  renderBusinessHours,
1593
+ renderBackgroundEvent,
1339
1594
  renderEvent,
1340
1595
  keyExtractor,
1341
1596
  snapMinutes,
@@ -1352,102 +1607,25 @@ function TimetablePageInner<T>({
1352
1607
  onLongPressCell,
1353
1608
  onCreateEvent,
1354
1609
  onEdgeAdvance,
1355
- onGridTop,
1610
+ pageIndex,
1611
+ laneHeight,
1612
+ scrollY,
1613
+ showAllDayEventCell,
1614
+ onLaneLayout,
1615
+ height,
1616
+ pagedHeader,
1617
+ weekdayFormat,
1618
+ locale,
1619
+ activeDate,
1620
+ onPressDateHeader,
1356
1621
  }: TimetablePageProps<T>) {
1357
1622
  const theme = useCalendarTheme();
1358
1623
  const slot = useSlots<TimeGridSlot>();
1359
- const scrollRef = useAnimatedRef<Animated.ScrollView>();
1360
- // The hour grid sits below the all-day lane; capture its top on layout and
1361
- // report it up while this page is active (the lane height differs per week).
1362
- const gridTopRef = useRef(0);
1363
- useEffect(() => {
1364
- if (isActive) onGridTop?.(gridTopRef.current);
1365
- }, [isActive, onGridTop]);
1366
1624
 
1367
1625
  // The visible page tracks the live cellHeight (animates every pinch frame);
1368
1626
  // off-screen pages track committedCellHeight (settles once per gesture).
1369
1627
  const heightSource = isActive ? cellHeight : committedCellHeight;
1370
1628
 
1371
- // Keep every page locked to the same vertical scroll position so the prev/next
1372
- // pages are already aligned before they drag into view — no post-swipe jump.
1373
- // Only a genuine user drag (and its momentum) updates the shared offset. The
1374
- // contentOffset seed and the programmatic scrolls that fire during paging also
1375
- // emit onScroll events; letting those write `scrollY` could broadcast a transient
1376
- // 0 to every page (the random "snaps to midnight" behaviour), so they're ignored.
1377
- const isDragging = useSharedValue(false);
1378
- // Mirror `isActive` to a shared value so the scroll worklet reads the *current*
1379
- // active state. A plain `isActive` captured in the worklet goes stale, so only the
1380
- // page active when the handler was first created would record its scrolls — which
1381
- // is why a position set on a later page was lost and an earlier one came back.
1382
- const isActiveShared = useSharedValue(isActive);
1383
- useEffect(() => {
1384
- isActiveShared.value = isActive;
1385
- }, [isActive, isActiveShared]);
1386
- const scrollHandler = useAnimatedScrollHandler({
1387
- onScroll: (event) => {
1388
- // Native captures the active page's scroll on a real drag. (Web is handled by
1389
- // the container-level scroll listener in TimeGridInner, because LegendList
1390
- // recycles the page containers there and per-page `isActive` can't reliably
1391
- // tell which DOM node the user is actually scrolling.)
1392
- if (isActiveShared.value && isDragging.value) {
1393
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1394
- scrollY.value = event.contentOffset.y;
1395
- }
1396
- },
1397
- onBeginDrag: () => {
1398
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1399
- isDragging.value = true;
1400
- },
1401
- onEndDrag: (event) => {
1402
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1403
- isDragging.value = false;
1404
- // Capture the rested position. The mid-drag onScroll above stops at the
1405
- // finger-lift point; without this, the momentum tail after it is lost and the
1406
- // saved offset falls short of where the page actually settles.
1407
- if (!isWeb && isActiveShared.value) {
1408
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1409
- scrollY.value = event.contentOffset.y;
1410
- runOnJS(onSettleOffset)(event.contentOffset.y);
1411
- }
1412
- },
1413
- onMomentumEnd: (event) => {
1414
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1415
- isDragging.value = false;
1416
- if (!isWeb && isActiveShared.value) {
1417
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1418
- scrollY.value = event.contentOffset.y;
1419
- runOnJS(onSettleOffset)(event.contentOffset.y);
1420
- }
1421
- },
1422
- });
1423
-
1424
- // Keep *inactive* pages aligned to the shared offset as it changes, so they're
1425
- // already in position before they drag into view. Reads `isActiveShared` (not the
1426
- // captured `isActive`) so the worklet sees the current state.
1427
- useAnimatedReaction(
1428
- () => scrollY.value,
1429
- (current, previous) => {
1430
- if (!isActiveShared.value && current !== previous) {
1431
- scrollTo(scrollRef, 0, current, false);
1432
- }
1433
- },
1434
- );
1435
-
1436
- // When a page becomes the active one (paged or jumped to), align it to the shared
1437
- // offset. The reaction above only syncs *inactive* pages, and only when `scrollY`
1438
- // changes, so a page that paged in after the last change (the third page on from a
1439
- // drag, say) would keep its seeded default. Uses reanimated's `scrollTo` worklet:
1440
- // the imperative `scrollRef.current.scrollTo()` does not take effect on a
1441
- // useAnimatedRef, which is why that page stayed at the default. Native only; web is
1442
- // handled by the container-level effect in TimeGridInner.
1443
- useAnimatedReaction(
1444
- () => isActiveShared.value,
1445
- (active, previous) => {
1446
- if (isWeb || !active || active === previous) return;
1447
- scrollTo(scrollRef, 0, scrollY.value, false);
1448
- },
1449
- );
1450
-
1451
1629
  const days = useMemo(
1452
1630
  () => getViewDays(mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays),
1453
1631
  [mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays],
@@ -1460,8 +1638,8 @@ function TimetablePageInner<T>({
1460
1638
  // gesture worklet would capture the whole `days` array (of `Date`s), which
1461
1639
  // react-native-worklets >=0.10 refuses to copy to the UI thread.
1462
1640
  const dayCount = days.length;
1463
- const dayWidth = (width - hourColumnWidth) / dayCount;
1464
- const dayLeft = (dayIndex: number) => hourColumnWidth + dayIndex * dayWidth;
1641
+ const dayWidth = width / dayCount;
1642
+ const dayLeft = (dayIndex: number) => dayIndex * dayWidth;
1465
1643
 
1466
1644
  // Calendar-day offset of each column from the first, as plain numbers a drag
1467
1645
  // worklet can close over. Identity (0,1,2,…) for contiguous days; with
@@ -1513,11 +1691,7 @@ function TimetablePageInner<T>({
1513
1691
  if (date) onLongPressCell?.(date);
1514
1692
  };
1515
1693
 
1516
- // The hours (rows/labels) visible in the window [minHour, maxHour).
1517
- const hoursRange = useMemo(
1518
- () => Array.from({ length: maxHour - minHour }, (_, index) => minHour + index),
1519
- [minHour, maxHour],
1520
- );
1694
+ const hoursRange = useMemo(() => hourRange(minHour, maxHour), [minHour, maxHour]);
1521
1695
 
1522
1696
  const now = useNow(showNowIndicator && isActive, { now: nowProp, timeZone: nowTimeZone });
1523
1697
  // "Today" follows the (possibly zone-shifted or overridden) now, so the line
@@ -1530,33 +1704,35 @@ function TimetablePageInner<T>({
1530
1704
  () => ({ height: (maxHour - minHour) * heightSource.value }),
1531
1705
  [minHour, maxHour, heightSource],
1532
1706
  );
1533
-
1534
- // Capture the row height when the pinch starts and apply `event.scale`
1535
- // (relative to that start) rather than multiplying per-frame deltas — deltas
1536
- // compound float error and the zoom never settles on a clean level.
1537
- const pinchStartCellHeight = useSharedValue(hourHeight);
1538
- const zoomGesture = useMemo(() => {
1539
- const pinch = Gesture.Pinch()
1540
- .onStart(() => {
1541
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1542
- pinchStartCellHeight.value = cellHeight.value;
1543
- })
1544
- .onUpdate((event) => {
1545
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1546
- cellHeight.value = Math.min(
1547
- maxHourHeight,
1548
- Math.max(minHourHeight, pinchStartCellHeight.value * event.scale),
1549
- );
1550
- })
1551
- .onEnd(() => {
1552
- // Publish the final zoom to the off-screen pages in one update.
1553
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1554
- committedCellHeight.value = cellHeight.value;
1555
- });
1556
- // Recognise the pinch and the ScrollView's native scroll together so the
1557
- // scroll never cancels an in-progress zoom.
1558
- return Gesture.Simultaneous(pinch, Gesture.Native());
1559
- }, [cellHeight, committedCellHeight, pinchStartCellHeight, minHourHeight, maxHourHeight]);
1707
+ // The page stacks its all-day band, the label inset, then the hours. The band
1708
+ // rides the scroll offset so it holds still at the top of the viewport while
1709
+ // the hours pass beneath it, and it slides with the page during a swipe.
1710
+ const headerOffset = pagedHeader ? DAY_HEADER_HEIGHT : 0;
1711
+ const gridStyle = useAnimatedStyle(
1712
+ () => ({
1713
+ top: headerOffset + laneHeight.value + HOUR_LABEL_TOP_INSET,
1714
+ height: (maxHour - minHour) * heightSource.value,
1715
+ }),
1716
+ [minHour, maxHour, heightSource, headerOffset],
1717
+ );
1718
+ // Split like the hour column's cell: the offset style only runs on a scroll,
1719
+ // the height style only when the band resizes. Both the header and the band
1720
+ // ride the scroll offset, so they hold still at the top while the hours pass.
1721
+ // The band keeps a 1px floor when the lane measures nothing, so the lane inside
1722
+ // is never clipped to nothing: Android stops reporting the layout of a view
1723
+ // clipped away entirely, which would leave all-day events that arrive later
1724
+ // unmeasured. The bottom rule only draws once the band has real height.
1725
+ const laneHeightStyle = useAnimatedStyle(() => ({
1726
+ height: Math.max(LANE_BAND_FLOOR, laneHeight.value),
1727
+ borderBottomWidth: laneHeight.value >= LANE_BAND_FLOOR ? StyleSheet.hairlineWidth : 0,
1728
+ }));
1729
+ const pinStyle = useAnimatedStyle(() => ({ transform: [{ translateY: scrollY.value }] }));
1730
+ const reportLaneLayout = useCallback(
1731
+ (event: LayoutChangeEvent) => {
1732
+ onLaneLayout(pageIndex, event.nativeEvent.layout.height);
1733
+ },
1734
+ [onLaneLayout, pageIndex],
1735
+ );
1560
1736
 
1561
1737
  // Drag-to-create: sweep out a new event on empty grid. Native long-presses
1562
1738
  // first (so a tap/scroll isn't hijacked); web uses a drag threshold like move,
@@ -1609,7 +1785,7 @@ function TimetablePageInner<T>({
1609
1785
  const idx = dayCount === 1 ? 0 : Math.floor(event.x / dayWidth);
1610
1786
  createDayIndex.value = idx;
1611
1787
  createStartY.value = event.y;
1612
- createLeft.value = hourColumnWidth + idx * dayWidth;
1788
+ createLeft.value = idx * dayWidth;
1613
1789
  createWidth.value = dayWidth;
1614
1790
  createTop.value = event.y;
1615
1791
  createHeight.value = 0;
@@ -1644,7 +1820,6 @@ function TimetablePageInner<T>({
1644
1820
  createEnabled,
1645
1821
  dayCount,
1646
1822
  dayWidth,
1647
- hourColumnWidth,
1648
1823
  heightSource,
1649
1824
  snapMinutes,
1650
1825
  commitCreate,
@@ -1711,7 +1886,7 @@ function TimetablePageInner<T>({
1711
1886
  const cellLayer =
1712
1887
  onPressCell || onLongPressCell || createEnabled ? (
1713
1888
  <Pressable
1714
- style={[styles.cellPressLayer, { left: hourColumnWidth }]}
1889
+ style={styles.cellPressLayer}
1715
1890
  onPress={onPressCell ? handleBackgroundPress : undefined}
1716
1891
  // When create is on, a long-press starts the create-drag, so don't also
1717
1892
  // fire the consumer's long-press handler.
@@ -1726,247 +1901,265 @@ function TimetablePageInner<T>({
1726
1901
  ) : null;
1727
1902
 
1728
1903
  return (
1729
- <View style={styles.container}>
1730
- {showAllDayEventCell ? (
1731
- <AllDayLane
1732
- days={days}
1733
- events={events}
1734
- mode={mode}
1735
- hourColumnWidth={hourColumnWidth}
1736
- dayWidth={dayWidth}
1737
- renderEvent={renderEvent}
1738
- keyExtractor={keyExtractor}
1739
- onPressEvent={onPressEvent}
1740
- onLongPressEvent={onLongPressEvent}
1741
- />
1904
+ <View
1905
+ testID="time-grid-page"
1906
+ style={[styles.page, { width, height }]}
1907
+ // Only the active page is on screen; keep the pre-mounted neighbours out of
1908
+ // the screen-reader traversal so their events and headers aren't announced.
1909
+ accessibilityElementsHidden={!isActive}
1910
+ importantForAccessibility={isActive ? "auto" : "no-hide-descendants"}
1911
+ >
1912
+ {pagedHeader ? (
1913
+ <Animated.View
1914
+ testID="paged-header"
1915
+ style={[
1916
+ styles.pagedHeader,
1917
+ { backgroundColor: theme.colors.surface, borderBottomColor: theme.colors.gridLine },
1918
+ pinStyle,
1919
+ ]}
1920
+ >
1921
+ <DayHeaderRow
1922
+ days={days}
1923
+ mode={mode}
1924
+ dayWidth={dayWidth}
1925
+ weekdayFormat={weekdayFormat}
1926
+ locale={locale}
1927
+ activeDate={activeDate}
1928
+ onPressDateHeader={onPressDateHeader}
1929
+ />
1930
+ </Animated.View>
1742
1931
  ) : null}
1743
- <GestureDetector gesture={zoomGesture}>
1744
- <Animated.ScrollView
1745
- ref={scrollRef}
1746
- showsVerticalScrollIndicator={showVerticalScrollIndicator}
1747
- scrollEnabled={verticalScrollEnabled}
1748
- onScroll={scrollHandler}
1749
- scrollEventThrottle={16}
1750
- onLayout={(event) => {
1751
- // The scroll view's offset within the page equals the all-day lane
1752
- // height above it: the hour grid's top. Report it while active.
1753
- gridTopRef.current = event.nativeEvent.layout.y;
1754
- if (isActive) onGridTop?.(gridTopRef.current);
1755
- }}
1756
- contentContainerStyle={{ paddingTop: HOUR_LABEL_TOP_INSET }}
1757
- contentOffset={{ x: 0, y: initialScrollY }}
1932
+ {showAllDayEventCell ? (
1933
+ <Animated.View
1934
+ testID="all-day-band"
1935
+ style={[
1936
+ styles.laneBand,
1937
+ {
1938
+ top: headerOffset,
1939
+ backgroundColor: theme.colors.surface,
1940
+ borderBottomColor: theme.colors.gridLine,
1941
+ },
1942
+ laneHeightStyle,
1943
+ pinStyle,
1944
+ ]}
1758
1945
  >
1759
- <Animated.View style={[styles.content, fullHeightStyle]}>
1760
- {/* Behind the events, so empty-space taps/drags create while event
1946
+ <AllDayLane
1947
+ days={days}
1948
+ events={events}
1949
+ mode={mode}
1950
+ dayWidth={dayWidth}
1951
+ renderEvent={renderEvent}
1952
+ keyExtractor={keyExtractor}
1953
+ onPressEvent={onPressEvent}
1954
+ onLongPressEvent={onLongPressEvent}
1955
+ onLayout={reportLaneLayout}
1956
+ />
1957
+ </Animated.View>
1958
+ ) : null}
1959
+ <Animated.View style={[styles.grid, gridStyle]}>
1960
+ {/* Behind the events, so empty-space taps/drags create while event
1761
1961
  taps still hit their box. */}
1762
- {cellLayer && backgroundGesture ? (
1763
- <GestureDetector gesture={backgroundGesture}>{cellLayer}</GestureDetector>
1764
- ) : (
1765
- cellLayer
1766
- )}
1767
-
1768
- {days.map((day, dayIndex) => {
1769
- if (!highlightWeekends || !isWeekend(day)) return null;
1770
- const shadeSlot = slot("weekendShade", {
1771
- base: [
1772
- styles.weekendColumn,
1773
- styles.nonInteractive,
1774
- { left: dayLeft(dayIndex), width: dayWidth },
1775
- ],
1776
- themed: { backgroundColor: theme.colors.weekendBackground },
1777
- });
1778
- return (
1962
+ {cellLayer && backgroundGesture ? (
1963
+ <GestureDetector gesture={backgroundGesture}>{cellLayer}</GestureDetector>
1964
+ ) : (
1965
+ cellLayer
1966
+ )}
1967
+
1968
+ {days.map((day, dayIndex) => {
1969
+ if (!highlightWeekends || !isWeekend(day)) return null;
1970
+ const shadeSlot = slot("weekendShade", {
1971
+ base: [
1972
+ styles.weekendColumn,
1973
+ styles.nonInteractive,
1974
+ { left: dayLeft(dayIndex), width: dayWidth },
1975
+ ],
1976
+ themed: { backgroundColor: theme.colors.weekendBackground },
1977
+ });
1978
+ return (
1979
+ <Animated.View
1980
+ key={`weekend-${day.toISOString()}`}
1981
+ testID="weekend-shade"
1982
+ {...shadeSlot}
1983
+ style={[shadeSlot.style, fullHeightStyle]}
1984
+ />
1985
+ );
1986
+ })}
1987
+
1988
+ {calendarCellStyle
1989
+ ? days.map((day, dayIndex) => {
1990
+ const cellStyle = calendarCellStyle(day);
1991
+ return cellStyle ? (
1779
1992
  <Animated.View
1780
- key={`weekend-${day.toISOString()}`}
1781
- testID="weekend-shade"
1782
- {...shadeSlot}
1783
- style={[shadeSlot.style, fullHeightStyle]}
1993
+ key={`cell-${day.toISOString()}`}
1994
+ style={[
1995
+ styles.weekendColumn,
1996
+ styles.nonInteractive,
1997
+ { left: dayLeft(dayIndex), width: dayWidth },
1998
+ cellStyle,
1999
+ fullHeightStyle,
2000
+ ]}
2001
+ />
2002
+ ) : null;
2003
+ })
2004
+ : null}
2005
+
2006
+ {businessHours
2007
+ ? days.flatMap((day, dayIndex) =>
2008
+ closedHourBands(day, businessHours, minHour, maxHour).map((band, bandIndex) => (
2009
+ <ShadeBand
2010
+ key={`closed-${day.toISOString()}-${bandIndex}`}
2011
+ cellHeight={heightSource}
2012
+ startHour={band.start}
2013
+ endHour={band.end}
2014
+ minHour={minHour}
2015
+ left={dayLeft(dayIndex)}
2016
+ width={dayWidth}
2017
+ color={renderBusinessHours ? undefined : theme.colors.outsideHoursBackground}
2018
+ >
2019
+ {renderBusinessHours?.({ date: day, start: band.start, end: band.end })}
2020
+ </ShadeBand>
2021
+ )),
2022
+ )
2023
+ : null}
2024
+
2025
+ {/* Background events: shaded time ranges, or the consumer's own band. */}
2026
+ {days.flatMap((day, dayIndex) => {
2027
+ const dayStart = startOfDay(day);
2028
+ const nextDayStart = addDays(dayStart, 1);
2029
+ return backgroundBandsForDay(events, day)
2030
+ .map((b) => ({
2031
+ ...b,
2032
+ startHours: Math.max(b.startHours, minHour),
2033
+ endHours: Math.min(b.endHours, maxHour),
2034
+ }))
2035
+ .filter((b) => b.endHours > b.startHours)
2036
+ .map((b, bandIndex) => {
2037
+ const key = `bg-${day.toISOString()}-${keyExtractor(b.event, bandIndex)}`;
2038
+ return renderBackgroundEvent ? (
2039
+ <BackgroundEventBand
2040
+ key={key}
2041
+ event={b.event}
2042
+ cellHeight={heightSource}
2043
+ startHour={b.startHours}
2044
+ endHour={b.endHours}
2045
+ minHour={minHour}
2046
+ left={dayLeft(dayIndex)}
2047
+ width={dayWidth}
2048
+ mode={mode}
2049
+ continuesBefore={b.event.start < dayStart}
2050
+ continuesAfter={b.event.end > nextDayStart}
2051
+ render={renderBackgroundEvent}
2052
+ onPress={onPressEvent}
2053
+ onLongPress={onLongPressEvent}
2054
+ />
2055
+ ) : (
2056
+ <ShadeBand
2057
+ key={key}
2058
+ cellHeight={heightSource}
2059
+ startHour={b.startHours}
2060
+ endHour={b.endHours}
2061
+ minHour={minHour}
2062
+ left={dayLeft(dayIndex)}
2063
+ width={dayWidth}
2064
+ color={theme.colors.backgroundEvent}
2065
+ slotName="backgroundEvent"
2066
+ testID="background-event-shade"
1784
2067
  />
1785
2068
  );
1786
- })}
1787
-
1788
- {calendarCellStyle
1789
- ? days.map((day, dayIndex) => {
1790
- const cellStyle = calendarCellStyle(day);
1791
- return cellStyle ? (
1792
- <Animated.View
1793
- key={`cell-${day.toISOString()}`}
1794
- style={[
1795
- styles.weekendColumn,
1796
- styles.nonInteractive,
1797
- { left: dayLeft(dayIndex), width: dayWidth },
1798
- cellStyle,
1799
- fullHeightStyle,
1800
- ]}
1801
- />
1802
- ) : null;
1803
- })
1804
- : null}
1805
-
1806
- {businessHours
1807
- ? days.flatMap((day, dayIndex) =>
1808
- closedHourBands(day, businessHours, minHour, maxHour).map((band, bandIndex) => (
1809
- <ShadeBand
1810
- key={`closed-${day.toISOString()}-${bandIndex}`}
1811
- cellHeight={heightSource}
1812
- startHour={band.start}
1813
- endHour={band.end}
1814
- minHour={minHour}
1815
- left={dayLeft(dayIndex)}
1816
- width={dayWidth}
1817
- color={renderBusinessHours ? undefined : theme.colors.outsideHoursBackground}
1818
- >
1819
- {renderBusinessHours?.({ date: day, start: band.start, end: band.end })}
1820
- </ShadeBand>
1821
- )),
1822
- )
1823
- : null}
1824
-
1825
- {/* Background events: shaded, non-interactive time ranges. */}
1826
- {days.flatMap((day, dayIndex) =>
1827
- backgroundBandsForDay(events, day)
1828
- .map((b) => ({
1829
- ...b,
1830
- startHours: Math.max(b.startHours, minHour),
1831
- endHours: Math.min(b.endHours, maxHour),
1832
- }))
1833
- .filter((b) => b.endHours > b.startHours)
1834
- .map((b, bandIndex) => (
1835
- <ShadeBand
1836
- key={`bg-${day.toISOString()}-${bandIndex}`}
1837
- cellHeight={heightSource}
1838
- startHour={b.startHours}
1839
- endHour={b.endHours}
1840
- minHour={minHour}
1841
- left={dayLeft(dayIndex)}
1842
- width={dayWidth}
1843
- color={theme.colors.backgroundEvent}
1844
- slotName="backgroundEvent"
1845
- testID="background-event-shade"
1846
- />
1847
- )),
1848
- )}
1849
-
1850
- {days.map((day, dayIndex) => {
1851
- const separatorSlot = slot("daySeparator", {
1852
- base: [styles.daySeparator, styles.nonInteractive, { left: dayLeft(dayIndex) }],
1853
- themed: { backgroundColor: theme.colors.gridLine },
1854
- });
2069
+ });
2070
+ })}
2071
+
2072
+ {days.map((day, dayIndex) => {
2073
+ const separatorSlot = slot("daySeparator", {
2074
+ base: [styles.daySeparator, styles.nonInteractive, { left: dayLeft(dayIndex) }],
2075
+ themed: { backgroundColor: theme.colors.gridLine },
2076
+ });
2077
+ return (
2078
+ <Animated.View
2079
+ key={`separator-${day.toISOString()}`}
2080
+ {...separatorSlot}
2081
+ style={[separatorSlot.style, fullHeightStyle]}
2082
+ />
2083
+ );
2084
+ })}
2085
+
2086
+ <HourLines hours={hoursRange} timeslots={timeslots} />
2087
+
2088
+ {dayLayouts.flatMap((layout, dayIndex) =>
2089
+ layout
2090
+ // Skip events that fall entirely outside the [minHour, maxHour) window.
2091
+ .filter((p) => p.startHours < maxHour && p.startHours + p.durationHours > minHour)
2092
+ .map((positioned, eventIndex) => {
2093
+ const columnWidth = dayWidth / positioned.columns;
1855
2094
  return (
1856
- <Animated.View
1857
- key={`separator-${day.toISOString()}`}
1858
- {...separatorSlot}
1859
- style={[separatorSlot.style, fullHeightStyle]}
2095
+ <AnimatedEventBox
2096
+ // Prefix with the day so a multi-day event's per-day segments
2097
+ // (which share the same event key) stay unique across the
2098
+ // flattened list of all days' boxes.
2099
+ key={`${dayIndex}:${keyExtractor(positioned.event, eventIndex)}`}
2100
+ positioned={positioned}
2101
+ eventIndex={events.indexOf(positioned.event)}
2102
+ movingEvent={movingEvent}
2103
+ onMovePreview={setMultiDayMove}
2104
+ cellHeight={heightSource}
2105
+ minHour={minHour}
2106
+ maxHour={maxHour}
2107
+ left={dayLeft(dayIndex) + positioned.column * columnWidth}
2108
+ width={columnWidth}
2109
+ dayLeftPx={dayLeft(dayIndex)}
2110
+ nextDayDirection={isRTL ? -1 : 1}
2111
+ dayWidth={dayWidth}
2112
+ dayIndex={dayIndex}
2113
+ dayCount={days.length}
2114
+ dayOrdinals={dayOrdinals}
2115
+ mode={mode}
2116
+ daysPerPage={daysPerPage}
2117
+ renderEvent={renderEvent}
2118
+ snapMinutes={snapMinutes}
2119
+ minEventHeight={minEventHeight}
2120
+ eventGap={eventGap}
2121
+ showDragHandle={showDragHandle}
2122
+ eventStartEditable={eventStartEditable}
2123
+ eventDurationEditable={eventDurationEditable}
2124
+ onPress={onPressEvent}
2125
+ onLongPress={onLongPressEvent}
2126
+ onDragEvent={onDragEvent}
2127
+ onDragStart={onDragStart}
2128
+ onEdgeAdvance={onEdgeAdvance}
1860
2129
  />
1861
2130
  );
1862
- })}
1863
-
1864
- {hoursRange.map((hour) => (
1865
- <HourRow
1866
- key={hour}
1867
- hour={hour}
1868
- minHour={minHour}
1869
- cellHeight={heightSource}
1870
- hourColumnWidth={hourColumnWidth}
1871
- label={formatHour(hour, { ampm })}
1872
- ampm={ampm}
1873
- hourComponent={hourComponent}
1874
- />
1875
- ))}
1876
-
1877
- {timeslots > 1
1878
- ? hoursRange.flatMap((hour) =>
1879
- Array.from({ length: timeslots - 1 }, (_, i) => (
1880
- <TimeslotLine
1881
- key={`slot-${hour}-${i}`}
1882
- hour={hour}
1883
- minHour={minHour}
1884
- fraction={(i + 1) / timeslots}
1885
- cellHeight={heightSource}
1886
- hourColumnWidth={hourColumnWidth}
1887
- />
1888
- )),
1889
- )
1890
- : null}
1891
-
1892
- {dayLayouts.flatMap((layout, dayIndex) =>
1893
- layout
1894
- // Skip events that fall entirely outside the [minHour, maxHour) window.
1895
- .filter((p) => p.startHours < maxHour && p.startHours + p.durationHours > minHour)
1896
- .map((positioned, eventIndex) => {
1897
- const columnWidth = dayWidth / positioned.columns;
1898
- return (
1899
- <AnimatedEventBox
1900
- // Prefix with the day so a multi-day event's per-day segments
1901
- // (which share the same event key) stay unique across the
1902
- // flattened list of all days' boxes.
1903
- key={`${dayIndex}:${keyExtractor(positioned.event, eventIndex)}`}
1904
- positioned={positioned}
1905
- eventIndex={events.indexOf(positioned.event)}
1906
- movingEvent={movingEvent}
1907
- onMovePreview={setMultiDayMove}
1908
- cellHeight={heightSource}
1909
- minHour={minHour}
1910
- maxHour={maxHour}
1911
- left={dayLeft(dayIndex) + positioned.column * columnWidth}
1912
- width={columnWidth}
1913
- dayLeftPx={dayLeft(dayIndex)}
1914
- nextDayDirection={isRTL ? -1 : 1}
1915
- dayWidth={dayWidth}
1916
- dayIndex={dayIndex}
1917
- dayCount={days.length}
1918
- dayOrdinals={dayOrdinals}
1919
- mode={mode}
1920
- daysPerPage={daysPerPage}
1921
- renderEvent={renderEvent}
1922
- snapMinutes={snapMinutes}
1923
- minEventHeight={minEventHeight}
1924
- eventGap={eventGap}
1925
- showDragHandle={showDragHandle}
1926
- eventStartEditable={eventStartEditable}
1927
- eventDurationEditable={eventDurationEditable}
1928
- onPress={onPressEvent}
1929
- onLongPress={onLongPressEvent}
1930
- onDragEvent={onDragEvent}
1931
- onDragStart={onDragStart}
1932
- onEdgeAdvance={onEdgeAdvance}
1933
- />
1934
- );
1935
- }),
1936
- )}
1937
-
1938
- {multiDayMove ? (
1939
- <MultiDayMovePreview
1940
- move={multiDayMove}
1941
- days={days}
1942
- cellHeight={heightSource}
1943
- dayWidth={dayWidth}
1944
- hourColumnWidth={hourColumnWidth}
1945
- minHour={minHour}
1946
- mode={mode}
1947
- renderEvent={renderEvent}
1948
- minEventHeight={minEventHeight}
1949
- eventGap={eventGap}
1950
- />
1951
- ) : null}
2131
+ }),
2132
+ )}
2133
+
2134
+ {multiDayMove ? (
2135
+ <MultiDayMovePreview
2136
+ move={multiDayMove}
2137
+ days={days}
2138
+ cellHeight={heightSource}
2139
+ dayWidth={dayWidth}
2140
+ minHour={minHour}
2141
+ mode={mode}
2142
+ renderEvent={renderEvent}
2143
+ minEventHeight={minEventHeight}
2144
+ eventGap={eventGap}
2145
+ />
2146
+ ) : null}
1952
2147
 
1953
- {showNowIndicator && nowDayIndex >= 0 && nowInWindow ? (
1954
- <NowIndicator
1955
- cellHeight={heightSource}
1956
- nowHours={nowHours}
1957
- minHour={minHour}
1958
- left={dayLeft(nowDayIndex)}
1959
- width={dayWidth}
1960
- color={theme.colors.nowIndicator}
1961
- />
1962
- ) : null}
2148
+ {showNowIndicator && nowDayIndex >= 0 && nowInWindow ? (
2149
+ <NowIndicator
2150
+ cellHeight={heightSource}
2151
+ nowHours={nowHours}
2152
+ minHour={minHour}
2153
+ left={dayLeft(nowDayIndex)}
2154
+ width={dayWidth}
2155
+ color={theme.colors.nowIndicator}
2156
+ />
2157
+ ) : null}
1963
2158
 
1964
- {createEnabled ? (
1965
- <Animated.View {...ghostSlot} style={[ghostSlot.style, createGhostStyle]} />
1966
- ) : null}
1967
- </Animated.View>
1968
- </Animated.ScrollView>
1969
- </GestureDetector>
2159
+ {createEnabled ? (
2160
+ <Animated.View {...ghostSlot} style={[ghostSlot.style, createGhostStyle]} />
2161
+ ) : null}
2162
+ </Animated.View>
1970
2163
  </View>
1971
2164
  );
1972
2165
  }
@@ -1978,10 +2171,10 @@ const TimetablePage = memo(TimetablePageInner) as typeof TimetablePageInner;
1978
2171
  * where the structure matches; `columnHeaderDateText`, `weekendShade` and
1979
2172
  * `daySeparator` are native-only (the dom grid styles those through its
1980
2173
  * `dayColumn`/`columnHeaderDate` elements). Slots rendered as Reanimated views
1981
- * (`gridLines` sub-hour dividers, `businessHours`, `weekendShade`,
1982
- * `daySeparator`, `event`, `nowIndicator`, `createGhost`) always honour the
1983
- * `styles` map; their `className` reaches the element but needs a Tailwind
1984
- * runtime that styles Animated components.
2174
+ * (`businessHours`, `weekendShade`, `daySeparator`, `event`,
2175
+ * `nowIndicator`, `createGhost`) always honour the `styles` map; their
2176
+ * `className` reaches the element but needs a Tailwind runtime that styles
2177
+ * Animated components.
1985
2178
  */
1986
2179
  export type TimeGridSlot =
1987
2180
  | "header"
@@ -1994,6 +2187,7 @@ export type TimeGridSlot =
1994
2187
  | "allDayLabel"
1995
2188
  | "allDayColumn"
1996
2189
  | "allDayEvent"
2190
+ | "hourGutter"
1997
2191
  | "hourLabel"
1998
2192
  | "gridLines"
1999
2193
  | "businessHours"
@@ -2045,6 +2239,11 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
2045
2239
  timeslots?: number;
2046
2240
  /** Show the all-day lane above the grid. Default true. */
2047
2241
  showAllDayEventCell?: boolean;
2242
+ /** Pull-to-refresh control, mounted on the grid's vertical scroll view. */
2243
+ refreshControl?: ScrollViewProps["refreshControl"];
2244
+ /** Show the "all-day" text label in the hour column. Default false; the lane
2245
+ * still reserves its row, it just isn't labelled. */
2246
+ showAllDayLabel?: boolean;
2048
2247
  /** Tint Saturday/Sunday columns with the weekend background. Default true. Set
2049
2248
  * false to treat weekends like any other day. */
2050
2249
  highlightWeekends?: boolean;
@@ -2058,6 +2257,8 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
2058
2257
  * band stays non-interactive and hidden from assistive tech.
2059
2258
  */
2060
2259
  renderBusinessHours?: (band: BusinessHoursBand) => React.ReactNode;
2260
+ /** A component that draws a background event's band; see `Calendar`. */
2261
+ renderBackgroundEvent?: RenderEvent<T>;
2061
2262
  /** Show the ISO week number in the header gutter. Default false. */
2062
2263
  showWeekNumber?: boolean;
2063
2264
  /** Element rendered between the day header and the grid. */
@@ -2152,10 +2353,13 @@ function TimeGridInner<T>({
2152
2353
  hideHours = false,
2153
2354
  timeslots = 1,
2154
2355
  showAllDayEventCell = true,
2356
+ showAllDayLabel = false,
2357
+ refreshControl,
2155
2358
  highlightWeekends = true,
2156
2359
  calendarCellStyle,
2157
2360
  businessHours,
2158
2361
  renderBusinessHours,
2362
+ renderBackgroundEvent,
2159
2363
  showWeekNumber = false,
2160
2364
  headerComponent,
2161
2365
  minHour = 0,
@@ -2202,6 +2406,11 @@ function TimeGridInner<T>({
2202
2406
  const clampedMaxHour = Math.max(clampedMinHour + 1, Math.min(maxHour, HOURS_PER_DAY));
2203
2407
  // Collapse the hour gutter to zero when hours are hidden.
2204
2408
  const hourColumnWidth = hideHours ? 0 : hourColumnWidthProp;
2409
+ // The built-in day header pages with the columns (rendered inside each page). A
2410
+ // custom `renderHeader` keeps a single fixed header above the pager instead, so
2411
+ // the pages carry no header and nothing offsets by its height.
2412
+ const pagedHeader = renderHeader == null;
2413
+ const headerOffset = pagedHeader ? DAY_HEADER_HEIGHT : 0;
2205
2414
 
2206
2415
  // Inject a consumer's `eventAccessibilityLabel` override into every event once,
2207
2416
  // so the timed columns and the all-day lane share it without threading a prop
@@ -2220,7 +2429,7 @@ function TimeGridInner<T>({
2220
2429
  overlapsOtherEvents(events, event, start, end) ? false : onDragEventProp(event, start, end);
2221
2430
  }, [onDragEventProp, eventOverlap, events]);
2222
2431
 
2223
- const { width, height } = useWindowDimensions();
2432
+ const { width } = useWindowDimensions();
2224
2433
  const listRef = useRef<LegendListRef>(null);
2225
2434
  // The pager's own view; measured in the window so an event drag can locate the
2226
2435
  // horizontal edges (its screen-space left and width) for cross-week paging.
@@ -2228,40 +2437,113 @@ function TimeGridInner<T>({
2228
2437
  // The grid's outer view; on web its ref resolves to the DOM node we attach the
2229
2438
  // Ctrl/Cmd + scroll zoom listener to.
2230
2439
  const containerRef = useRef<View>(null);
2231
- // Web: ignore scroll events until this time (ms). Set around a page change so the
2232
- // recycle-reset and the offset-restore aren't mistaken for a user scroll.
2233
- const suppressCaptureUntilRef = useRef(0);
2234
- // Horizontal list items need an explicit cross-axis height; seed it with the
2235
- // window height (so it renders immediately and in tests) and refine on layout.
2236
- const [pageHeight, setPageHeight] = useState(height);
2440
+ // The scroll viewport; measured in the window so a lifted drag can map the
2441
+ // finger into the scrolling content.
2442
+ const viewportRef = useRef<View>(null);
2443
+ // Width the pager last laid out at, so the zoom (which changes its height every
2444
+ // frame) doesn't re-measure it.
2445
+ const pagerLayoutWidthRef = useRef(-1);
2446
+ const scrollRef = useAnimatedRef<Animated.ScrollView>();
2237
2447
  // The grid sizes to its container width, not the window, so it fits a
2238
2448
  // constrained layout on the web (e.g. a max-width card). On native the grid
2239
2449
  // fills the window, so this equals the window width and behaviour is unchanged.
2240
- // Seeded with the window width for the first paint, refined on layout.
2450
+ // Seeded with the window width so width-derived values exist before the first
2451
+ // layout, then refined on layout.
2241
2452
  const [containerWidth, setContainerWidth] = useState(width);
2242
- // The list must remount exactly once — when the real height replaces the
2243
- // window-height seed — or it keeps the oversized seed and clips. It must NOT
2244
- // remount on later height changes (e.g. a taller day header vs a shorter week
2245
- // header on a mode switch): a remount blanks the visible page for a frame.
2246
- const [measured, setMeasured] = useState(false);
2453
+ // Width of the day columns: the pager's own, once it has laid out (on the web
2454
+ // a classic scrollbar takes width inside the scroll view), else what the hour
2455
+ // column leaves of the container.
2456
+ const [pagerLayoutWidth, setPagerLayoutWidth] = useState<number | null>(null);
2457
+ const columnsWidth = pagerLayoutWidth ?? containerWidth - hourColumnWidth;
2458
+ // The pager mounts only once its container has laid out, so the list's fixed
2459
+ // item size is the measured width rather than the window-based estimate.
2460
+ const pagerReady = pagerLayoutWidth != null && pagerLayoutWidth > 0;
2461
+ // The tallest all-day lane reported so far, so the fixed pager height below
2462
+ // always has room for the band.
2463
+ const [tallestLane, setTallestLane] = useState(0);
2247
2464
  // Week-anchored modes page by a full week and align pages to the week start:
2248
2465
  // `week`, and `custom` when a `weekEndsOn` defines a partial-week span.
2249
2466
  const weekAnchored = mode === "week" || (mode === "custom" && weekEndsOn != null);
2250
2467
  // Days advanced per page: a full week when week-anchored, else the column count.
2251
2468
  const step = weekAnchored ? 7 : viewDayCount(mode, numberOfDays);
2252
- // Shared vertical scroll offset so every mounted page stays aligned. Seeded
2253
- // from the numeric hourHeight rather than reading cellHeight.value (which
2254
- // would warn about reading a shared value during render).
2469
+ // Initial vertical offset (`scrollOffsetMinutes`), from the numeric hourHeight
2470
+ // rather than cellHeight.value (which would warn about reading a shared value
2471
+ // during render).
2255
2472
  const seedDefaultY =
2256
2473
  Math.max(0, scrollOffsetMinutes / MINUTES_PER_HOUR - clampedMinHour) * hourHeight;
2474
+ // The live offset of the one scroll view, for the drag worklets: the pager
2475
+ // scrolls with the content, so a finger's window position maps into the grid
2476
+ // through it.
2257
2477
  const scrollY = useSharedValue(seedDefaultY);
2258
- // Pager frame in window space (refined on layout) and a swipe-scroll freeze,
2259
- // shared with the event drag worklets through EdgePagingContext so a cross-week
2260
- // edge drag can detect the edges and page the view live under a held finger.
2478
+ const scrollHandler = useAnimatedScrollHandler({
2479
+ onScroll: (event) => {
2480
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2481
+ scrollY.value = event.contentOffset.y;
2482
+ },
2483
+ });
2484
+ // react-native-web ignores `contentOffset`; apply the initial offset once the
2485
+ // viewport and the content have laid out instead.
2486
+ const webSeededRef = useRef(!isWeb);
2487
+ const seedWebScroll = useCallback(() => {
2488
+ if (webSeededRef.current) return;
2489
+ const node = scrollRef.current;
2490
+ if (!node) return;
2491
+ node.scrollTo({ y: seedDefaultY, animated: false });
2492
+ // Latch only once the view can hold the offset: until both the viewport and
2493
+ // the content have a size, the scroll clamps to 0 and would drop the seed.
2494
+ const dom = node.getScrollableNode() as { scrollHeight: number; clientHeight: number } | null;
2495
+ if (dom && dom.scrollHeight > dom.clientHeight) webSeededRef.current = true;
2496
+ }, [scrollRef, seedDefaultY]);
2497
+ // Height of the all-day band, shared by the hour column and every page. Each
2498
+ // page reports its lane's natural height under its index, and the band follows
2499
+ // the pager's live offset (kept on the UI thread by the list), interpolating
2500
+ // between the outgoing and incoming pages' heights so it resizes on the fly
2501
+ // during a swipe. The list opens on the anchor page. A guard below clamps the
2502
+ // interpolation to the committed page when the offset is more than 1.5 pages
2503
+ // away (a stale mount seed), so a multi-page `freeSwipe` fling holds the band
2504
+ // at the committed height and it snaps to the destination on settle rather than
2505
+ // animating the whole way; single-page paging (the default) interpolates fully.
2506
+ const laneHeights = useSharedValue<Record<number, number>>({});
2507
+ // Mirrored on the JS side: several pages report in one tick, and a read of the
2508
+ // shared value inside that tick still sees the previous batch, so building the
2509
+ // next map from `.value` would keep only the last report.
2510
+ const laneHeightsRef = useRef<Record<number, number>>({});
2511
+ const pagerOffset = useSharedValue(PAGE_WINDOW * columnsWidth);
2512
+ const pagerSharedValues = useMemo(() => ({ scrollOffset: pagerOffset }), [pagerOffset]);
2513
+ // The committed page, for the worklet below: the list only reports its offset
2514
+ // as it scrolls, and seeds it from its own scroll state at mount, which can
2515
+ // still be zero. An offset more than a page and a half from the committed
2516
+ // page is that stale seed, so the band reads as resting on the page.
2517
+ const activeIndexShared = useSharedValue(PAGE_WINDOW);
2518
+ const laneHeight = useDerivedValue(() => {
2519
+ if (!showAllDayEventCell || columnsWidth <= 0) return 0;
2520
+ const heights = laneHeights.value;
2521
+ let progress = pagerOffset.value / columnsWidth;
2522
+ if (Math.abs(progress - activeIndexShared.value) > 1.5) progress = activeIndexShared.value;
2523
+ const from = Math.floor(progress);
2524
+ const fraction = progress - from;
2525
+ const start = heights[from] ?? 0;
2526
+ const end = heights[from + 1] ?? start;
2527
+ return start + (end - start) * fraction;
2528
+ }, [showAllDayEventCell, columnsWidth]);
2529
+ const reportLaneHeight = useCallback(
2530
+ (index: number, height: number) => {
2531
+ setTallestLane((tallest) => (height > tallest ? height : tallest));
2532
+ if (laneHeightsRef.current[index] === height) return;
2533
+ laneHeightsRef.current = { ...laneHeightsRef.current, [index]: height };
2534
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2535
+ laneHeights.value = laneHeightsRef.current;
2536
+ },
2537
+ [laneHeights],
2538
+ );
2539
+ // Window-space frames (refined on layout), shared with the event drag worklets
2540
+ // through EdgePagingContext so a cross-week edge drag can detect the edges and
2541
+ // page the view live under a held finger. The pager's top follows the scroll:
2542
+ // the viewport's top, less the offset.
2543
+ const viewportTop = useSharedValue(0);
2261
2544
  const pagerLeft = useSharedValue(0);
2262
- const pagerTop = useSharedValue(0);
2263
2545
  const pagerWidth = useSharedValue(width);
2264
- const [edgePagingLock, setEdgePagingLock] = useState(false);
2546
+ const pagerTop = useDerivedValue(() => viewportTop.value - scrollY.value);
2265
2547
  // Floating "held" ghost that carries a dragged event across a page change (see
2266
2548
  // EdgePaging): pager-local top-left, size, visibility, and the event to draw.
2267
2549
  const ghostX = useSharedValue(0);
@@ -2269,10 +2551,6 @@ function TimeGridInner<T>({
2269
2551
  const ghostW = useSharedValue(0);
2270
2552
  const ghostH = useSharedValue(0);
2271
2553
  const ghostVisible = useSharedValue(0);
2272
- // Pager-local top of the active page's hour grid (the all-day lane above it
2273
- // varies in height per week), so a cross-week drop maps the ghost's screen
2274
- // position to the right time on the page it lands on.
2275
- const gridTop = useSharedValue(0);
2276
2554
  const [liftedEvent, setLiftedEvent] = useState<CalendarEvent<T> | null>(null);
2277
2555
  const liftedEventRef = useRef<CalendarEvent<T> | null>(null);
2278
2556
  // The drop commit needs the live page's columns and handler; keep them in a ref
@@ -2281,8 +2559,8 @@ function TimeGridInner<T>({
2281
2559
  // drag (the gesture must outlive the page change to finish a cross-week drop).
2282
2560
  const dropRef = useRef({
2283
2561
  headerDays: [] as Date[],
2284
- containerWidth,
2285
- hourColumnWidth,
2562
+ columnsWidth,
2563
+ headerOffset,
2286
2564
  minHour: clampedMinHour,
2287
2565
  maxHour: clampedMaxHour,
2288
2566
  snapMinutes: Math.max(1, dragStepMinutes),
@@ -2298,14 +2576,13 @@ function TimeGridInner<T>({
2298
2576
  ghostVisible.value = 0;
2299
2577
  liftedEventRef.current = null;
2300
2578
  setLiftedEvent(null);
2301
- setEdgePagingLock(false);
2302
2579
  }, [ghostVisible]);
2303
2580
  const commitLiftedDrop = useCallback(
2304
2581
  (ghostLocalX: number, ghostLocalY: number) => {
2305
2582
  const {
2306
2583
  headerDays: days,
2307
- containerWidth: cw,
2308
- hourColumnWidth: hcw,
2584
+ columnsWidth: cw,
2585
+ headerOffset: headerH,
2309
2586
  minHour: min,
2310
2587
  maxHour: max,
2311
2588
  snapMinutes: snap,
@@ -2317,16 +2594,14 @@ function TimeGridInner<T>({
2317
2594
  clearLift();
2318
2595
  if (!ev || !onDrag || days.length === 0) return;
2319
2596
  // Map the ghost's drawn position on the page it landed on back to a cell:
2320
- // its left edge picks the day column, its top edge picks the time. Reading
2321
- // the live grid geometry (the all-day lane pushes the grid down, the grid
2322
- // scrolls, pinch changes the row height) keeps the drop under the ghost.
2323
- const dayWidth = (cw - hcw) / days.length;
2324
- const col = Math.min(
2325
- Math.max(Math.floor((ghostLocalX - hcw) / dayWidth), 0),
2326
- days.length - 1,
2327
- );
2597
+ // its left edge picks the day column, its top edge picks the time. Both are
2598
+ // pager-local, and the pager is the scrolling content itself, so the top
2599
+ // edge only needs the page's all-day band and label inset taken off before
2600
+ // the live row height (pinch) converts it to hours.
2601
+ const dayWidth = cw / days.length;
2602
+ const col = Math.min(Math.max(Math.floor(ghostLocalX / dayWidth), 0), days.length - 1);
2328
2603
  const hoursFromMin =
2329
- (ghostLocalY - gridTop.value - HOUR_LABEL_TOP_INSET + scrollY.value) / cellHeight.value;
2604
+ (ghostLocalY - headerH - laneHeight.value - HOUR_LABEL_TOP_INSET) / cellHeight.value;
2330
2605
  const rawMinutes = (min + hoursFromMin) * MINUTES_PER_HOUR;
2331
2606
  // Same rule as an in-page move: the start stays in the day it landed on,
2332
2607
  // while the duration is free to carry the end past midnight.
@@ -2340,21 +2615,13 @@ function TimeGridInner<T>({
2340
2615
  // reads as a visible snap-back instead of the event seeming to vanish.
2341
2616
  if (onDrag(ev, start, end) === false) onDate(ev.start);
2342
2617
  },
2343
- [clearLift, gridTop, scrollY, cellHeight],
2344
- );
2345
- const handleGridTop = useCallback(
2346
- (y: number) => {
2347
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2348
- gridTop.value = y;
2349
- },
2350
- [gridTop],
2618
+ [clearLift, cellHeight, laneHeight],
2351
2619
  );
2352
2620
  const edgePaging = useMemo<EdgePaging>(
2353
2621
  () => ({
2354
2622
  pagerLeft,
2355
2623
  pagerTop,
2356
2624
  pagerWidth,
2357
- lockScroll: setEdgePagingLock,
2358
2625
  ghostX,
2359
2626
  ghostY,
2360
2627
  ghostW,
@@ -2376,18 +2643,81 @@ function TimeGridInner<T>({
2376
2643
  commitLiftedDrop,
2377
2644
  ],
2378
2645
  );
2379
- // Plain mirror of the last settled vertical offset. A page that mounts after a
2380
- // scroll seeds its contentOffset here instead of the default, so it appears at the
2381
- // saved time straight away rather than rendering at the default and snapping (the
2382
- // one-frame flash). Null until the first scroll, when `seedDefaultY` is used.
2383
- const offsetSeedRef = useRef<number | null>(null);
2384
- const captureOffsetSeed = useCallback((y: number) => {
2385
- offsetSeedRef.current = y;
2386
- }, []);
2387
2646
  // Zoom committed at the end of the last pinch; off-screen pages animate off
2388
2647
  // this so they don't re-run their worklets every frame while the visible page
2389
2648
  // zooms.
2390
2649
  const committedCellHeight = useSharedValue(hourHeight);
2650
+ // Outside a pinch, any other writer of `cellHeight` (a consumer-owned shared
2651
+ // value, the web wheel zoom) commits at once, so the hour column and the
2652
+ // off-screen pages never disagree with the visible page.
2653
+ const pinching = useSharedValue(false);
2654
+ useAnimatedReaction(
2655
+ () => cellHeight.value,
2656
+ (value) => {
2657
+ if (!pinching.value) committedCellHeight.value = value;
2658
+ },
2659
+ );
2660
+
2661
+ // Capture the row height when the pinch starts and apply `event.scale`
2662
+ // (relative to that start) rather than multiplying per-frame deltas — deltas
2663
+ // compound float error and the zoom never settles on a clean level.
2664
+ const pinchStartCellHeight = useSharedValue(hourHeight);
2665
+ const zoomGesture = useMemo(() => {
2666
+ const pinch = Gesture.Pinch()
2667
+ .onStart(() => {
2668
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2669
+ pinching.value = true;
2670
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2671
+ pinchStartCellHeight.value = cellHeight.value;
2672
+ })
2673
+ .onUpdate((event) => {
2674
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2675
+ cellHeight.value = Math.min(
2676
+ maxHourHeight,
2677
+ Math.max(minHourHeight, pinchStartCellHeight.value * event.scale),
2678
+ );
2679
+ })
2680
+ // Finalize (not end) so a cancelled pinch still commits and reopens the
2681
+ // reaction above.
2682
+ .onFinalize(() => {
2683
+ // Publish the final zoom to the off-screen pages in one update.
2684
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2685
+ pinching.value = false;
2686
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2687
+ committedCellHeight.value = cellHeight.value;
2688
+ });
2689
+ // Recognise the pinch and the scroll view's native scroll together so the
2690
+ // scroll never cancels an in-progress zoom.
2691
+ return Gesture.Simultaneous(pinch, Gesture.Native());
2692
+ }, [
2693
+ cellHeight,
2694
+ committedCellHeight,
2695
+ pinching,
2696
+ pinchStartCellHeight,
2697
+ minHourHeight,
2698
+ maxHourHeight,
2699
+ ]);
2700
+ // The pager and its pages keep one fixed height, big enough for the fully
2701
+ // zoomed hour window plus the tallest lane, so the list and its item
2702
+ // containers (which report every layout to JS) never re-lay out while the
2703
+ // band or the zoom animate. Only the scroll content's own height is live.
2704
+ const pagerHeight =
2705
+ headerOffset +
2706
+ HOUR_LABEL_TOP_INSET +
2707
+ (clampedMaxHour - clampedMinHour) * maxHourHeight +
2708
+ tallestLane;
2709
+ // Height of the scroll content (the hour column and every page): the all-day
2710
+ // band, the label inset, then the hours, live with the pinch and the swipe.
2711
+ const gridHeightStyle = useAnimatedStyle(
2712
+ () => ({
2713
+ height:
2714
+ headerOffset +
2715
+ laneHeight.value +
2716
+ HOUR_LABEL_TOP_INSET +
2717
+ (clampedMaxHour - clampedMinHour) * cellHeight.value,
2718
+ }),
2719
+ [clampedMinHour, clampedMaxHour, headerOffset],
2720
+ );
2391
2721
 
2392
2722
  // Web stand-in for pinch: Ctrl/Cmd + scroll zooms the grid via the same shared
2393
2723
  // values the pinch gesture drives.
@@ -2427,6 +2757,10 @@ function TimeGridInner<T>({
2427
2757
  // The committed date's page is the centred/active one. `viewedIndexRef` tracks
2428
2758
  // where the list actually sits, telling swipe-driven changes from external ones.
2429
2759
  const activeIndex = indexOfDate(date);
2760
+ useEffect(() => {
2761
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2762
+ activeIndexShared.value = activeIndex;
2763
+ }, [activeIndex, activeIndexShared]);
2430
2764
  const viewedIndexRef = useRef(activeIndex);
2431
2765
  // While a programmatic scroll (a "today" button, prev/next, or any date set from
2432
2766
  // outside) is settling, this holds its target index. Viewability ticks for the
@@ -2434,6 +2768,37 @@ function TimeGridInner<T>({
2434
2768
  // a page in between back as the new date — which made jumps land one page short.
2435
2769
  const pendingScrollIndexRef = useRef<number | null>(null);
2436
2770
 
2771
+ // ISO week label for the hour column's corner (the visible page's Thursday
2772
+ // defines the week). Null unless the header is paged and week numbers are on.
2773
+ const weekNumber = useMemo(() => {
2774
+ if (!pagedHeader || !showWeekNumber || hourColumnWidth === 0) return null;
2775
+ const days = getViewDays(
2776
+ mode,
2777
+ pageDates[activeIndex] ?? date,
2778
+ weekStartsOn,
2779
+ numberOfDays,
2780
+ isRTL,
2781
+ weekEndsOn,
2782
+ hiddenDays,
2783
+ );
2784
+ const thursday = days.find((d) => d.getDay() === 4) ?? days[0];
2785
+ return thursday ? `${weekNumberPrefix}${getISOWeek(thursday)}` : null;
2786
+ }, [
2787
+ pagedHeader,
2788
+ showWeekNumber,
2789
+ hourColumnWidth,
2790
+ mode,
2791
+ pageDates,
2792
+ activeIndex,
2793
+ date,
2794
+ weekStartsOn,
2795
+ numberOfDays,
2796
+ isRTL,
2797
+ weekEndsOn,
2798
+ hiddenDays,
2799
+ weekNumberPrefix,
2800
+ ]);
2801
+
2437
2802
  // Header days track the active page (page-aligned), so they always match the
2438
2803
  // columns below and a swipe never flashes another day's label.
2439
2804
  const headerDays = useMemo(
@@ -2454,8 +2819,8 @@ function TimeGridInner<T>({
2454
2819
  // identity-stable EdgePaging callbacks (see dropRef).
2455
2820
  dropRef.current = {
2456
2821
  headerDays,
2457
- containerWidth,
2458
- hourColumnWidth,
2822
+ columnsWidth,
2823
+ headerOffset,
2459
2824
  minHour: clampedMinHour,
2460
2825
  maxHour: clampedMaxHour,
2461
2826
  snapMinutes: Math.max(1, dragStepMinutes),
@@ -2494,73 +2859,35 @@ function TimeGridInner<T>({
2494
2859
  if (activeIndex === viewedIndexRef.current) return;
2495
2860
  viewedIndexRef.current = activeIndex;
2496
2861
  pendingScrollIndexRef.current = activeIndex;
2862
+ // Keep the all-day band's interpolation source in step with the jump; the
2863
+ // list reports its offset only as it scrolls, not on a programmatic one.
2864
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2865
+ pagerOffset.value = activeIndex * columnsWidth;
2497
2866
  void listRef.current?.scrollToIndex({ index: activeIndex, animated: false });
2867
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- columnsWidth/pagerOffset are stable per width
2498
2868
  }, [activeIndex]);
2499
2869
 
2500
- // react-native-web only: paging recycles the page containers and resets their
2501
- // vertical scroll, so the on-screen page randomly lands at the top. After the
2502
- // page settles, restore the shared offset directly on the visible page's scroll
2503
- // node — the one lever that reliably works on the web. Deferred a frame (twice,
2504
- // for safety) so the paged-in grid has laid out before we scroll it.
2870
+ // The list reports its offset only as it scrolls; seed it whenever the list is
2871
+ // (re)laid out at a new width, where it opens on the active page.
2505
2872
  useEffect(() => {
2506
- if (!isWeb) return;
2507
- const root = containerRef.current as unknown as HTMLElement | null;
2508
- if (!root) return;
2509
- const restoreVisiblePage = () => {
2510
- const vw = (root.ownerDocument?.defaultView ?? globalThis).innerWidth;
2511
- for (const el of root.querySelectorAll<HTMLElement>("*")) {
2512
- const style = getComputedStyle(el);
2513
- const scrollable =
2514
- (style.overflowY === "scroll" || style.overflowY === "auto") &&
2515
- el.scrollHeight > el.clientHeight + 20 &&
2516
- el.clientHeight > 100;
2517
- if (!scrollable) continue;
2518
- const rect = el.getBoundingClientRect();
2519
- if (rect.left > -50 && rect.right <= vw + 50) {
2520
- el.scrollTop = scrollY.value;
2521
- break;
2522
- }
2523
- }
2524
- };
2525
- // Don't capture the scroll events this transition emits (recycle-reset, restore).
2526
- suppressCaptureUntilRef.current = Date.now() + 400;
2527
- let raf2 = 0;
2528
- const raf1 = requestAnimationFrame(() => {
2529
- restoreVisiblePage();
2530
- raf2 = requestAnimationFrame(restoreVisiblePage);
2531
- });
2532
- return () => {
2533
- cancelAnimationFrame(raf1);
2534
- cancelAnimationFrame(raf2);
2535
- };
2536
- // `pageHeight` is included so this also runs once the pager measures its real
2537
- // height on first open (the mount pass runs before the pages have laid out).
2538
- // eslint-disable-next-line react-hooks/exhaustive-deps -- containerRef/scrollY are stable
2539
- }, [activeIndex, pageHeight]);
2540
-
2541
- // Web: record the on-screen page's scroll into the shared offset on genuine user
2542
- // scrolls, so switching pages preserves the position. Programmatic scrolls (the
2543
- // recycle-reset and the restore above) are skipped via the suppression window, so
2544
- // they can't clobber it. Scoped to the visible page so off-screen sync is ignored.
2873
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2874
+ pagerOffset.value = activeIndex * columnsWidth;
2875
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- reseed on width only; scroll events track index changes
2876
+ }, [columnsWidth, pagerOffset]);
2877
+
2878
+ // react-native-web ignores `contentOffset`: retry the seed each frame until the
2879
+ // scroll view can hold it (the viewport's `onLayout` also tries).
2545
2880
  useEffect(() => {
2546
2881
  if (!isWeb) return;
2547
- const root = containerRef.current as unknown as HTMLElement | null;
2548
- if (!root) return;
2549
- const onScrollCapture = (event: Event) => {
2550
- if (Date.now() < suppressCaptureUntilRef.current) return;
2551
- const el = event.target as HTMLElement | null;
2552
- if (!el || typeof el.scrollTop !== "number" || el.clientHeight <= 100) return;
2553
- const rect = el.getBoundingClientRect();
2554
- const vw = (root.ownerDocument?.defaultView ?? globalThis).innerWidth;
2555
- if (rect.left <= -50 || rect.right > vw + 50) return;
2556
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2557
- scrollY.value = el.scrollTop;
2558
- offsetSeedRef.current = el.scrollTop;
2882
+ let attempts = 0;
2883
+ let frame = 0;
2884
+ const attempt = () => {
2885
+ seedWebScroll();
2886
+ if (!webSeededRef.current && attempts++ < 120) frame = requestAnimationFrame(attempt);
2559
2887
  };
2560
- root.addEventListener("scroll", onScrollCapture, true);
2561
- return () => root.removeEventListener("scroll", onScrollCapture, true);
2562
- // eslint-disable-next-line react-hooks/exhaustive-deps -- containerRef/scrollY are stable
2563
- }, []);
2888
+ frame = requestAnimationFrame(attempt);
2889
+ return () => cancelAnimationFrame(frame);
2890
+ }, [seedWebScroll]);
2564
2891
 
2565
2892
  // Web: LegendList's horizontal scroll container is `overflow-x: auto`, so a
2566
2893
  // trackpad swipe or horizontal wheel would scroll between pages. Paging should be
@@ -2583,23 +2910,65 @@ function TimeGridInner<T>({
2583
2910
  };
2584
2911
  const raf = requestAnimationFrame(lockHorizontal);
2585
2912
  return () => cancelAnimationFrame(raf);
2913
+ // Re-run once the list exists at its real size (it remounts per width).
2586
2914
  // eslint-disable-next-line react-hooks/exhaustive-deps -- containerRef is stable
2587
- }, [pageHeight]);
2915
+ }, [columnsWidth]);
2588
2916
 
2589
- // Web arrow-key paging (swipe is disabled there); the effect above scrolls to
2590
- // the new page once `onChangeDate` updates `date`.
2917
+ // Honour the OS "reduce motion" setting: the pager's animated transitions
2918
+ // (paging from an edge drag, the snap-back after a cell press) become instant
2919
+ // jumps when it's on.
2920
+ const reduceMotion = useReducedMotion();
2921
+
2922
+ // Page by `delta` (edge drags, web arrow keys): move the list at once and
2923
+ // report the date, rather than waiting for the reported date to come back
2924
+ // through props. The realign effect then finds the list already there.
2591
2925
  const goToPage = useCallback(
2592
2926
  (delta: number) => {
2593
- const target = pageDates[activeIndex + delta];
2594
- if (target) onChangeDate(target);
2927
+ const index = viewedIndexRef.current + delta;
2928
+ const target = pageDates[index];
2929
+ if (!target) return;
2930
+ viewedIndexRef.current = index;
2931
+ pendingScrollIndexRef.current = index;
2932
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2933
+ pagerOffset.value = index * columnsWidth;
2934
+ void listRef.current?.scrollToIndex({ index, animated: !isWeb && !reduceMotion });
2935
+ onChangeDate(target);
2595
2936
  },
2596
- [pageDates, activeIndex, onChangeDate],
2937
+ [pageDates, reduceMotion, onChangeDate, columnsWidth, pagerOffset],
2597
2938
  );
2598
2939
  useWebPagerKeys(swipeEnabled, goToPage);
2599
2940
 
2600
- // Honour the OS "reduce motion" setting: the pager's one animated transition
2601
- // (the snap-back below) becomes an instant jump when it's on.
2602
- const reduceMotion = useReducedMotion();
2941
+ // A fast fling can outrun the list's on-demand mounting and leave the pager
2942
+ // blank until something nudges it. When momentum ends, re-anchor the list on
2943
+ // the page the offset landed on: `scrollToIndex` forces it to recompute its
2944
+ // container positions and repaint, which a plain React re-render (from the
2945
+ // date change) does not. The index comes from the settled offset, not the
2946
+ // viewability ref, so it is right regardless of which fires first.
2947
+ const handlePagerSettled = useCallback(
2948
+ (event: NativeSyntheticEvent<NativeScrollEvent>) => {
2949
+ if (columnsWidth <= 0) return;
2950
+ // Only a user fling can leave the pager blank; a programmatic scroll
2951
+ // (goToPage, realign) sets `pendingScrollIndexRef` and repaints itself, so
2952
+ // skip those to avoid a redundant re-anchor during held edge paging.
2953
+ if (pendingScrollIndexRef.current != null) return;
2954
+ const raw = Math.round(event.nativeEvent.contentOffset.x / columnsWidth);
2955
+ const index = Math.min(Math.max(raw, 0), pageDates.length - 1);
2956
+ // Commit the page the pager snaps to. Viewability only reports a page that
2957
+ // is nearly all on screen, so a fling that rests between pages would
2958
+ // otherwise move the grid without moving the date behind the header.
2959
+ if (index !== viewedIndexRef.current) {
2960
+ viewedIndexRef.current = index;
2961
+ const target = pageDates[index];
2962
+ if (target) onChangeDate(target);
2963
+ }
2964
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2965
+ pagerOffset.value = index * columnsWidth;
2966
+ requestAnimationFrame(() => {
2967
+ void listRef.current?.scrollToIndex({ index, animated: false });
2968
+ });
2969
+ },
2970
+ [columnsWidth, pageDates, onChangeDate, pagerOffset],
2971
+ );
2603
2972
 
2604
2973
  // Optionally snap the pager back to the active page after an empty-cell press
2605
2974
  // (so tapping a far-swiped page returns to the committed date).
@@ -2614,96 +2983,91 @@ function TimeGridInner<T>({
2614
2983
 
2615
2984
  const snapToIndices = useMemo(() => pageDates.map((_, index) => index), [pageDates]);
2616
2985
  const keyExtractorList = useCallback((item: Date) => item.toISOString(), []);
2617
- const getFixedItemSize = useCallback(() => containerWidth, [containerWidth]);
2986
+ const getFixedItemSize = useCallback(() => columnsWidth, [columnsWidth]);
2618
2987
  const renderItem = useCallback(
2619
2988
  ({ item, index }: LegendListRenderItemProps<Date>) => (
2620
- <View style={{ width: containerWidth, height: pageHeight }}>
2621
- <TimetablePage
2622
- mode={mode}
2623
- numberOfDays={numberOfDays}
2624
- hiddenDays={hiddenDays}
2625
- now={now}
2626
- nowTimeZone={timeZone}
2627
- date={item}
2628
- width={containerWidth}
2629
- events={events}
2630
- cellHeight={cellHeight}
2631
- hourHeight={hourHeight}
2632
- committedCellHeight={committedCellHeight}
2633
- scrollY={scrollY}
2634
- isActive={index === activeIndex}
2635
- initialScrollY={offsetSeedRef.current ?? seedDefaultY}
2636
- onSettleOffset={captureOffsetSeed}
2637
- weekStartsOn={weekStartsOn}
2638
- weekEndsOn={weekEndsOn}
2639
- hourColumnWidth={hourColumnWidth}
2640
- minHour={clampedMinHour}
2641
- maxHour={clampedMaxHour}
2642
- ampm={ampm}
2643
- timeslots={timeslots}
2644
- isRTL={isRTL}
2645
- showAllDayEventCell={showAllDayEventCell}
2646
- highlightWeekends={highlightWeekends}
2647
- showVerticalScrollIndicator={showVerticalScrollIndicator}
2648
- verticalScrollEnabled={verticalScrollEnabled}
2649
- hourComponent={hourComponent}
2650
- calendarCellStyle={calendarCellStyle}
2651
- businessHours={businessHours}
2652
- renderBusinessHours={renderBusinessHours}
2653
- minHourHeight={minHourHeight}
2654
- maxHourHeight={maxHourHeight}
2655
- showNowIndicator={showNowIndicator}
2656
- renderEvent={labeledRenderEvent}
2657
- keyExtractor={keyExtractor}
2658
- snapMinutes={Math.max(1, dragStepMinutes)}
2659
- minEventHeight={minEventHeight}
2660
- eventGap={eventGap}
2661
- showDragHandle={showDragHandle}
2662
- eventStartEditable={eventStartEditable}
2663
- eventDurationEditable={eventDurationEditable}
2664
- onPressEvent={onPressEvent}
2665
- onLongPressEvent={onLongPressEvent}
2666
- onDragEvent={onDragEvent}
2667
- onDragStart={onDragStart}
2668
- onPressCell={handlePressCell}
2669
- onLongPressCell={onLongPressCell}
2670
- onCreateEvent={onCreateEvent}
2671
- onEdgeAdvance={goToPage}
2672
- onGridTop={handleGridTop}
2673
- />
2674
- </View>
2989
+ <TimetablePage
2990
+ mode={mode}
2991
+ numberOfDays={numberOfDays}
2992
+ hiddenDays={hiddenDays}
2993
+ now={now}
2994
+ nowTimeZone={timeZone}
2995
+ date={item}
2996
+ width={columnsWidth}
2997
+ events={events}
2998
+ cellHeight={cellHeight}
2999
+ committedCellHeight={committedCellHeight}
3000
+ isActive={index === activeIndex}
3001
+ weekStartsOn={weekStartsOn}
3002
+ weekEndsOn={weekEndsOn}
3003
+ minHour={clampedMinHour}
3004
+ maxHour={clampedMaxHour}
3005
+ timeslots={timeslots}
3006
+ isRTL={isRTL}
3007
+ highlightWeekends={highlightWeekends}
3008
+ calendarCellStyle={calendarCellStyle}
3009
+ businessHours={businessHours}
3010
+ renderBusinessHours={renderBusinessHours}
3011
+ renderBackgroundEvent={renderBackgroundEvent}
3012
+ showNowIndicator={showNowIndicator}
3013
+ renderEvent={labeledRenderEvent}
3014
+ keyExtractor={keyExtractor}
3015
+ snapMinutes={Math.max(1, dragStepMinutes)}
3016
+ minEventHeight={minEventHeight}
3017
+ eventGap={eventGap}
3018
+ showDragHandle={showDragHandle}
3019
+ eventStartEditable={eventStartEditable}
3020
+ eventDurationEditable={eventDurationEditable}
3021
+ onPressEvent={onPressEvent}
3022
+ onLongPressEvent={onLongPressEvent}
3023
+ onDragEvent={onDragEvent}
3024
+ onDragStart={onDragStart}
3025
+ onPressCell={handlePressCell}
3026
+ onLongPressCell={onLongPressCell}
3027
+ onCreateEvent={onCreateEvent}
3028
+ onEdgeAdvance={goToPage}
3029
+ pageIndex={index}
3030
+ laneHeight={laneHeight}
3031
+ scrollY={scrollY}
3032
+ showAllDayEventCell={showAllDayEventCell}
3033
+ onLaneLayout={reportLaneHeight}
3034
+ height={pagerHeight}
3035
+ pagedHeader={pagedHeader}
3036
+ weekdayFormat={weekdayFormat}
3037
+ locale={locale}
3038
+ activeDate={activeDate}
3039
+ onPressDateHeader={onPressDateHeader}
3040
+ />
2675
3041
  ),
2676
3042
  [
2677
- containerWidth,
2678
- pageHeight,
2679
- handleGridTop,
3043
+ columnsWidth,
3044
+ pagerHeight,
3045
+ pagedHeader,
3046
+ weekdayFormat,
3047
+ locale,
3048
+ activeDate,
3049
+ onPressDateHeader,
3050
+ laneHeight,
3051
+ scrollY,
3052
+ showAllDayEventCell,
3053
+ reportLaneHeight,
2680
3054
  mode,
2681
3055
  numberOfDays,
2682
3056
  events,
2683
3057
  cellHeight,
2684
- hourHeight,
2685
3058
  committedCellHeight,
2686
- scrollY,
2687
3059
  activeIndex,
2688
- seedDefaultY,
2689
- captureOffsetSeed,
2690
3060
  weekStartsOn,
2691
3061
  weekEndsOn,
2692
- hourColumnWidth,
2693
3062
  clampedMinHour,
2694
3063
  clampedMaxHour,
2695
- ampm,
2696
3064
  timeslots,
2697
3065
  isRTL,
2698
- showAllDayEventCell,
2699
3066
  highlightWeekends,
2700
- showVerticalScrollIndicator,
2701
- verticalScrollEnabled,
2702
- hourComponent,
2703
3067
  calendarCellStyle,
2704
3068
  businessHours,
2705
- minHourHeight,
2706
- maxHourHeight,
3069
+ renderBusinessHours,
3070
+ renderBackgroundEvent,
2707
3071
  showNowIndicator,
2708
3072
  labeledRenderEvent,
2709
3073
  keyExtractor,
@@ -2731,98 +3095,150 @@ function TimeGridInner<T>({
2731
3095
  // and only re-renders them when `data` or `extraData` changes. Feed both `events`
2732
3096
  // (so a moved event repaints in place) and `activeIndex` (so each page's
2733
3097
  // `isActive` updates as you swipe). Without `activeIndex`, a page that pages in
2734
- // never learns it became active and stays at its seeded scroll offset.
2735
- const listExtraData = useMemo(() => ({ events, activeIndex }), [events, activeIndex]);
3098
+ // never learns it became active, so its zoom source and now line would lag.
3099
+ // `columnsWidth` resizes the mounted pages when the grid is re-measured.
3100
+ const listExtraData = useMemo(
3101
+ () => ({ events, activeIndex, columnsWidth }),
3102
+ [events, activeIndex, columnsWidth],
3103
+ );
2736
3104
 
2737
3105
  return (
2738
3106
  <SlotStylesProvider classNames={classNames} styles={styleOverrides}>
2739
3107
  <EdgePagingContext.Provider value={edgePaging}>
2740
- <View ref={containerRef} style={styles.container}>
2741
- {renderHeader ? (
2742
- renderHeader(headerDays)
2743
- ) : (
2744
- <DefaultHeader
2745
- days={headerDays}
2746
- mode={mode}
2747
- width={containerWidth}
2748
- hourColumnWidth={hourColumnWidth}
2749
- showWeekNumber={showWeekNumber}
2750
- weekNumberPrefix={weekNumberPrefix}
2751
- weekdayFormat={weekdayFormat}
2752
- locale={locale}
2753
- activeDate={activeDate}
2754
- onPressDateHeader={onPressDateHeader}
2755
- />
2756
- )}
3108
+ <View
3109
+ ref={containerRef}
3110
+ style={styles.container}
3111
+ onLayout={(event) => setContainerWidth(event.nativeEvent.layout.width)}
3112
+ >
3113
+ {renderHeader ? renderHeader(headerDays) : null}
2757
3114
 
2758
3115
  {headerComponent}
2759
3116
 
2760
3117
  <View
2761
- ref={pagerRef}
2762
- style={styles.pager}
2763
- onLayout={(event) => {
2764
- setPageHeight(event.nativeEvent.layout.height);
2765
- setContainerWidth(event.nativeEvent.layout.width);
2766
- setMeasured(true);
2767
- // Record the pager's window-space frame for the drag worklets' edge
2768
- // detection and ghost placement (layout gives parent-relative coords,
2769
- // not window).
2770
- pagerRef.current?.measureInWindow((x, y, w) => {
3118
+ ref={viewportRef}
3119
+ style={styles.viewport}
3120
+ onLayout={() => {
3121
+ seedWebScroll();
3122
+ // Window-space top of the scroll viewport, for the drag worklets'
3123
+ // ghost placement (layout gives parent-relative coords, not window).
3124
+ viewportRef.current?.measureInWindow((_x, y) => {
2771
3125
  // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2772
- pagerLeft.value = x;
2773
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2774
- pagerTop.value = y;
2775
- // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2776
- pagerWidth.value = w;
3126
+ viewportTop.value = y;
2777
3127
  });
2778
3128
  }}
2779
3129
  >
2780
- <LegendList
2781
- // Remount only on the seed→measured transition (see `measured`), not on
2782
- // every height change, so a day↔week header-height difference resizes the
2783
- // items in place instead of remounting and blanking the page.
2784
- key={measured ? "grid" : "grid-seed"}
2785
- ref={listRef}
2786
- style={isWeb ? [styles.pagerList, styles.webNoScroll] : styles.pagerList}
2787
- data={pageDates}
2788
- extraData={listExtraData}
2789
- horizontal
2790
- recycleItems={false}
2791
- keyExtractor={keyExtractorList}
2792
- getFixedItemSize={getFixedItemSize}
2793
- // On web LegendList ignores these RN scroll props (it leaks them to the
2794
- // DOM as unknown attributes), so omit them there and disable horizontal
2795
- // scroll via `webNoScroll`; paging is driven by the arrow keys instead.
2796
- // Native: paging makes each swipe hard-stop at the adjacent page, while
2797
- // `freeSwipe` lets momentum carry across pages and snap to a boundary.
2798
- {...(isWeb
2799
- ? null
2800
- : {
2801
- // Frozen mid-edge-page so the programmatic advance lands under
2802
- // the held finger instead of waiting for the touch to end.
2803
- scrollEnabled: swipeEnabled && !edgePagingLock,
2804
- pagingEnabled: !freeSwipe,
2805
- snapToIndices: freeSwipe ? snapToIndices : undefined,
2806
- })}
2807
- initialScrollIndex={activeIndex}
2808
- showsHorizontalScrollIndicator={false}
2809
- viewabilityConfig={PAGE_VIEWABILITY}
2810
- onViewableItemsChanged={handleViewableItemsChanged}
2811
- renderItem={renderItem}
2812
- />
2813
- {liftedEvent ? (
2814
- <DragGhost
2815
- x={ghostX}
2816
- y={ghostY}
2817
- w={ghostW}
2818
- h={ghostH}
2819
- visible={ghostVisible}
2820
- event={liftedEvent}
2821
- mode={mode}
2822
- renderEvent={labeledRenderEvent}
2823
- eventGap={eventGap}
2824
- />
2825
- ) : null}
3130
+ <GestureDetector gesture={zoomGesture}>
3131
+ <Animated.ScrollView
3132
+ ref={scrollRef}
3133
+ showsVerticalScrollIndicator={showVerticalScrollIndicator}
3134
+ scrollEnabled={verticalScrollEnabled}
3135
+ onScroll={scrollHandler}
3136
+ scrollEventThrottle={16}
3137
+ refreshControl={verticalScrollEnabled ? refreshControl : undefined}
3138
+ contentOffset={{ x: 0, y: seedDefaultY }}
3139
+ >
3140
+ <Animated.View testID="time-grid-hours" style={[styles.gridRow, gridHeightStyle]}>
3141
+ {hourColumnWidth > 0 ? (
3142
+ <HourGutter
3143
+ width={hourColumnWidth}
3144
+ minHour={clampedMinHour}
3145
+ maxHour={clampedMaxHour}
3146
+ cellHeight={cellHeight}
3147
+ laneHeight={laneHeight}
3148
+ scrollY={scrollY}
3149
+ showLane={showAllDayEventCell}
3150
+ showAllDayLabel={showAllDayLabel}
3151
+ headerHeight={headerOffset}
3152
+ weekNumber={weekNumber}
3153
+ ampm={ampm}
3154
+ hourComponent={hourComponent}
3155
+ />
3156
+ ) : null}
3157
+ <View
3158
+ ref={pagerRef}
3159
+ testID="time-grid-pager"
3160
+ style={[styles.pager, { left: hourColumnWidth, height: pagerHeight }]}
3161
+ onLayout={(event) => {
3162
+ // Window-space frame of the pager for the drag worklets' edge
3163
+ // detection and ghost placement. Only a width change matters
3164
+ // (the grid's or the hour column's); the zoom changes the
3165
+ // height every frame, so those layouts are skipped.
3166
+ const laidOutWidth = event.nativeEvent.layout.width;
3167
+ if (laidOutWidth === pagerLayoutWidthRef.current) return;
3168
+ pagerLayoutWidthRef.current = laidOutWidth;
3169
+ setPagerLayoutWidth(laidOutWidth);
3170
+ pagerRef.current?.measureInWindow((x, _y, measuredWidth) => {
3171
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
3172
+ pagerLeft.value = x;
3173
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
3174
+ pagerWidth.value = measuredWidth;
3175
+ });
3176
+ }}
3177
+ >
3178
+ {pagerReady ? (
3179
+ <AnimatedLegendList
3180
+ // Mounts once the pager has measured, so the fixed item size is
3181
+ // right from the list's first layout; the key remounts it on a
3182
+ // later width change (a rotation, a re-measured container).
3183
+ key={`grid-${columnsWidth}`}
3184
+ ref={listRef}
3185
+ style={isWeb ? [styles.pagerList, styles.webNoScroll] : styles.pagerList}
3186
+ data={pageDates}
3187
+ extraData={listExtraData}
3188
+ horizontal
3189
+ recycleItems={false}
3190
+ keyExtractor={keyExtractorList}
3191
+ getFixedItemSize={getFixedItemSize}
3192
+ // Mount the next pages either side while idle, not mid-swipe.
3193
+ drawDistance={columnsWidth * 2}
3194
+ // The live horizontal offset, kept on the UI thread, drives the
3195
+ // all-day band's height.
3196
+ sharedValues={pagerSharedValues}
3197
+ // On web LegendList ignores these RN scroll props (it leaks them to the
3198
+ // DOM as unknown attributes), so omit them there and disable horizontal
3199
+ // scroll via `webNoScroll`; paging is driven by the arrow keys instead.
3200
+ // Native: paging makes each swipe hard-stop at the adjacent page, while
3201
+ // `freeSwipe` lets momentum carry across pages and snap to a boundary.
3202
+ {...(isWeb
3203
+ ? null
3204
+ : {
3205
+ scrollEnabled: swipeEnabled,
3206
+ pagingEnabled: !freeSwipe,
3207
+ snapToIndices: freeSwipe ? snapToIndices : undefined,
3208
+ // Paging: snap to the adjacent page quickly instead of the
3209
+ // slow platform glide, and stop at that page rather than
3210
+ // drifting, so rapid one-week swipes land crisply instead of
3211
+ // queuing a long chain of drawn-out snaps. `freeSwipe` keeps
3212
+ // its momentum, so it can still fling across several pages.
3213
+ decelerationRate: freeSwipe ? ("normal" as const) : ("fast" as const),
3214
+ disableIntervalMomentum: !freeSwipe,
3215
+ scrollEventThrottle: 16,
3216
+ onMomentumScrollEnd: handlePagerSettled,
3217
+ })}
3218
+ initialScrollIndex={activeIndex}
3219
+ showsHorizontalScrollIndicator={false}
3220
+ viewabilityConfig={PAGE_VIEWABILITY}
3221
+ onViewableItemsChanged={handleViewableItemsChanged}
3222
+ renderItem={renderItem}
3223
+ />
3224
+ ) : null}
3225
+ {liftedEvent ? (
3226
+ <DragGhost
3227
+ x={ghostX}
3228
+ y={ghostY}
3229
+ w={ghostW}
3230
+ h={ghostH}
3231
+ visible={ghostVisible}
3232
+ event={liftedEvent}
3233
+ mode={mode}
3234
+ renderEvent={labeledRenderEvent}
3235
+ eventGap={eventGap}
3236
+ />
3237
+ ) : null}
3238
+ </View>
3239
+ </Animated.View>
3240
+ </Animated.ScrollView>
3241
+ </GestureDetector>
2826
3242
  </View>
2827
3243
  </View>
2828
3244
  </EdgePagingContext.Provider>
@@ -2851,58 +3267,30 @@ function TimeGridInner<T>({
2851
3267
  */
2852
3268
  export const TimeGrid = memo(TimeGridInner) as typeof TimeGridInner;
2853
3269
 
2854
- type DefaultHeaderProps = {
3270
+ type DayHeaderRowProps = {
2855
3271
  days: Date[];
2856
3272
  mode: CalendarMode;
2857
- width: number;
2858
- hourColumnWidth: number;
2859
- showWeekNumber?: boolean;
2860
- weekNumberPrefix?: string;
3273
+ dayWidth: number;
2861
3274
  weekdayFormat?: WeekdayFormat;
2862
3275
  locale?: Locale;
2863
3276
  activeDate?: Date;
2864
3277
  onPressDateHeader?: (date: Date) => void;
2865
3278
  };
2866
3279
 
2867
- const DefaultHeader = ({
3280
+ // The row of weekday/date columns, rendered once per page so it pages with the
3281
+ // grid. The header slot is the wrapper in the page; this fills it.
3282
+ const DayHeaderRow = ({
2868
3283
  days,
2869
3284
  mode,
2870
- width,
2871
- hourColumnWidth,
2872
- showWeekNumber,
2873
- weekNumberPrefix = "W",
3285
+ dayWidth,
2874
3286
  weekdayFormat,
2875
3287
  locale,
2876
3288
  activeDate,
2877
3289
  onPressDateHeader,
2878
- }: DefaultHeaderProps) => {
2879
- const theme = useCalendarTheme();
3290
+ }: DayHeaderRowProps) => {
2880
3291
  const slot = useSlots<TimeGridSlot>();
2881
- // Match the grid below: an hour-column spacer, then one column per day.
2882
- const dayWidth = (width - hourColumnWidth) / days.length;
2883
-
2884
3292
  return (
2885
- <View
2886
- {...slot("header", {
2887
- base: styles.headerRow,
2888
- themed: { borderBottomColor: theme.colors.gridLine },
2889
- })}
2890
- >
2891
- <View style={[styles.weekNumberGutter, { width: hourColumnWidth }]}>
2892
- {showWeekNumber && hourColumnWidth > 0 && days[0] ? (
2893
- <Text
2894
- {...slot<TextStyle>("weekNumber", {
2895
- themed: [theme.text.hourLabel, { color: theme.colors.textMuted }],
2896
- })}
2897
- allowFontScaling={false}
2898
- >
2899
- {/* Reference the visible Thursday: an ISO week is defined by its Thursday,
2900
- so a Sunday-start week still shows the week number its Mon–Sat body
2901
- belongs to. */}
2902
- {`${weekNumberPrefix}${getISOWeek(days.find((d) => d.getDay() === 4) ?? days[0])}`}
2903
- </Text>
2904
- ) : null}
2905
- </View>
3293
+ <View {...slot("header", { base: styles.headerRow })}>
2906
3294
  {days.map((day) => (
2907
3295
  <DayHeader
2908
3296
  key={day.toISOString()}
@@ -3014,8 +3402,11 @@ const DayHeader = ({
3014
3402
  };
3015
3403
 
3016
3404
  const styles = StyleSheet.create({
3405
+ // Beside the hour column, at the fixed pager height (see `pagerHeight`).
3017
3406
  pager: {
3018
- flex: 1,
3407
+ position: "absolute",
3408
+ top: 0,
3409
+ right: 0,
3019
3410
  },
3020
3411
  pagerList: {
3021
3412
  flex: 1,
@@ -3023,17 +3414,63 @@ const styles = StyleSheet.create({
3023
3414
  container: {
3024
3415
  flex: 1,
3025
3416
  },
3417
+ viewport: {
3418
+ flex: 1,
3419
+ },
3420
+ // The scroll content: the hour column and the pager sit inside it, absolutely.
3421
+ // Clipped, so the pager's fixed extra height neither draws nor (on the web)
3422
+ // extends the scroll range below the hours.
3423
+ gridRow: {
3424
+ position: "relative",
3425
+ overflow: "hidden",
3426
+ },
3427
+ hourGutter: {
3428
+ position: "absolute",
3429
+ top: 0,
3430
+ left: 0,
3431
+ bottom: 0,
3432
+ },
3433
+ fill: {
3434
+ position: "absolute",
3435
+ top: 0,
3436
+ left: 0,
3437
+ right: 0,
3438
+ bottom: 0,
3439
+ },
3440
+ // One hour (or sub-hour slot) of a flex column spanning the hour window.
3441
+ hourCell: {
3442
+ flex: 1,
3443
+ },
3444
+ // The day-header row fills the pinned header wrapper in a page.
3026
3445
  headerRow: {
3446
+ flex: 1,
3447
+ flexDirection: "row",
3448
+ alignItems: "center",
3449
+ },
3450
+ // The pinned day-header row at the top of a page; rides the scroll offset so it
3451
+ // holds still while the hours pass, and slides with the page during a swipe.
3452
+ pagedHeader: {
3453
+ position: "absolute",
3454
+ top: 0,
3455
+ left: 0,
3456
+ right: 0,
3457
+ height: DAY_HEADER_HEIGHT,
3458
+ zIndex: 2,
3027
3459
  flexDirection: "row",
3028
- // Center the weekday/number block vertically; the day header's own symmetric
3029
- // paddingVertical provides the spacing, matching the dom renderer (no extra
3030
- // bottom padding that would push the content up).
3031
3460
  alignItems: "center",
3032
3461
  borderBottomWidth: StyleSheet.hairlineWidth,
3033
3462
  },
3034
- weekNumberGutter: {
3463
+ // The hour column's corner above the "all-day" cell, aligned with the header.
3464
+ gutterCorner: {
3465
+ position: "absolute",
3466
+ top: 0,
3467
+ left: 0,
3468
+ right: 0,
3469
+ zIndex: 2,
3035
3470
  alignItems: "center",
3036
3471
  justifyContent: "flex-end",
3472
+ paddingBottom: 6,
3473
+ borderBottomWidth: StyleSheet.hairlineWidth,
3037
3474
  },
3038
3475
  dayHeader: {
3039
3476
  alignItems: "center",
@@ -3048,14 +3485,53 @@ const styles = StyleSheet.create({
3048
3485
  justifyContent: "center",
3049
3486
  alignItems: "center",
3050
3487
  },
3051
- content: {
3052
- width: "100%",
3488
+ page: {
3053
3489
  position: "relative",
3054
3490
  },
3491
+ // The hours of one page, below its all-day band and the label inset.
3492
+ grid: {
3493
+ position: "absolute",
3494
+ left: 0,
3495
+ right: 0,
3496
+ },
3497
+ // A page's all-day band: pinned to the top of the viewport by riding the scroll
3498
+ // offset, painted over the hours that pass beneath it. It draws the lane's
3499
+ // bottom rule at its live height, so the rule stays level with the hour
3500
+ // column's cell while a swipe interpolates between two weeks.
3501
+ laneBand: {
3502
+ position: "absolute",
3503
+ top: 0,
3504
+ left: 0,
3505
+ right: 0,
3506
+ overflow: "hidden",
3507
+ zIndex: 2,
3508
+ },
3509
+ // The hour column's "all-day" cell, pinned like the pages' bands.
3510
+ laneCell: {
3511
+ position: "absolute",
3512
+ top: 0,
3513
+ left: 0,
3514
+ right: 0,
3515
+ zIndex: 2,
3516
+ justifyContent: "center",
3517
+ overflow: "hidden",
3518
+ borderBottomWidth: StyleSheet.hairlineWidth,
3519
+ },
3520
+ allDayLabel: {
3521
+ fontSize: 10,
3522
+ textAlign: "right",
3523
+ paddingRight: 6,
3524
+ },
3525
+ gutterRows: {
3526
+ position: "absolute",
3527
+ left: 0,
3528
+ right: 0,
3529
+ },
3055
3530
  cellPressLayer: {
3056
3531
  position: "absolute",
3057
3532
  top: 0,
3058
3533
  bottom: 0,
3534
+ left: 0,
3059
3535
  right: 0,
3060
3536
  },
3061
3537
  createGhost: {
@@ -3069,6 +3545,7 @@ const styles = StyleSheet.create({
3069
3545
  },
3070
3546
  shadeBand: {
3071
3547
  position: "absolute",
3548
+ overflow: "hidden",
3072
3549
  },
3073
3550
  daySeparator: {
3074
3551
  position: "absolute",
@@ -3077,6 +3554,7 @@ const styles = StyleSheet.create({
3077
3554
  },
3078
3555
  hourRow: {
3079
3556
  position: "absolute",
3557
+ top: 0,
3080
3558
  left: 0,
3081
3559
  right: 0,
3082
3560
  flexDirection: "row",
@@ -3087,12 +3565,18 @@ const styles = StyleSheet.create({
3087
3565
  textAlign: "right",
3088
3566
  paddingRight: 6,
3089
3567
  },
3568
+ // A line sits at the top of its hour or sub-hour cell.
3090
3569
  hourLine: {
3091
- flex: 1,
3570
+ position: "absolute",
3571
+ top: 0,
3572
+ left: 0,
3573
+ right: 0,
3092
3574
  height: StyleSheet.hairlineWidth,
3093
3575
  },
3094
3576
  timeslotLine: {
3095
3577
  position: "absolute",
3578
+ top: 0,
3579
+ left: 0,
3096
3580
  right: 0,
3097
3581
  height: StyleSheet.hairlineWidth,
3098
3582
  opacity: 0.5,
@@ -3142,6 +3626,10 @@ const styles = StyleSheet.create({
3142
3626
  nonInteractive: {
3143
3627
  pointerEvents: "none",
3144
3628
  },
3629
+ // Touches pass through the view itself but still reach its children.
3630
+ passThrough: {
3631
+ pointerEvents: "box-none",
3632
+ },
3145
3633
  // Disable user-driven horizontal scroll on web; programmatic paging still works.
3146
3634
  webNoScroll: {
3147
3635
  overflow: "hidden",