@super-calendar/native 2.6.0 → 2.8.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.
@@ -15,7 +15,17 @@ import {
15
15
  startOfDay,
16
16
  startOfWeek,
17
17
  } from "date-fns";
18
- import { memo, type ReactElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
18
+ import {
19
+ createContext,
20
+ memo,
21
+ type ReactElement,
22
+ useCallback,
23
+ useContext,
24
+ useEffect,
25
+ useMemo,
26
+ useRef,
27
+ useState,
28
+ } from "react";
19
29
  import {
20
30
  type AccessibilityActionEvent,
21
31
  type GestureResponderEvent,
@@ -44,6 +54,7 @@ import Animated, {
44
54
  import { useCalendarTheme } from "../theme";
45
55
  import type {
46
56
  BusinessHours,
57
+ BusinessHoursBand,
47
58
  CalendarEvent,
48
59
  CalendarMode,
49
60
  EventKeyExtractor,
@@ -59,8 +70,12 @@ import {
59
70
  viewDayCount,
60
71
  } from "@super-calendar/core";
61
72
  import {
73
+ backgroundBandsForDay,
62
74
  cellRangeFromDrag,
75
+ useNow,
63
76
  closedHourBands,
77
+ overlapsOtherEvents,
78
+ pageStepDays,
64
79
  resolveDraggedBounds,
65
80
  snapDeltaMinutes,
66
81
  } from "@super-calendar/core";
@@ -121,6 +136,87 @@ const DRAG_ACTIVATE_PX = 8;
121
136
  const RESIZE_HANDLE_HEIGHT = 14;
122
137
  // Default minutes a drag snaps to when `dragStepMinutes` isn't set.
123
138
  const DEFAULT_DRAG_STEP_MINUTES = 15;
139
+ // zIndex applied to an event while it's being dragged/resized so it sits above
140
+ // every other event (RN stacks siblings by order, so without this a dragged box
141
+ // moved over a later event would fall behind it).
142
+ const DRAG_EVENT_Z = 100;
143
+ // How long to hold the dragged event past the visible columns before the view
144
+ // pages one period toward that edge.
145
+ const EDGE_DWELL_MS = 500;
146
+ // How close (px) the dragging finger must get to the pager's left/right edge to
147
+ // count as "past the columns". Detecting by finger position, not by how many
148
+ // columns the drag has crossed, so an event in any column can reach either edge
149
+ // (a column-delta test can't reach the far edge from a near-side column).
150
+ const EDGE_ZONE_PX = 36;
151
+
152
+ /**
153
+ * Lets a per-event drag worklet, deep inside the pager, drive a cross-week drag:
154
+ * locate the pager's edges, freeze the swipe scroll while paging (a native
155
+ * programmatic scroll is otherwise deferred until the touch ends, so the view
156
+ * would only advance once the finger lifts), and hand the event off to a floating
157
+ * ghost that survives the source page paging away, then commit on release.
158
+ */
159
+ type EdgePaging = {
160
+ // Pager frame in window space, so the worklet can find the edges and place the
161
+ // ghost (its top-left is the window origin the finger coords are relative to).
162
+ pagerLeft: SharedValue<number>;
163
+ pagerTop: SharedValue<number>;
164
+ pagerWidth: SharedValue<number>;
165
+ lockScroll: (locked: boolean) => void;
166
+ // The floating "held" copy of the dragged event: pager-local top-left, size, and
167
+ // visibility, driven on the UI thread so it tracks the finger across the page.
168
+ ghostX: SharedValue<number>;
169
+ ghostY: SharedValue<number>;
170
+ ghostW: SharedValue<number>;
171
+ ghostH: SharedValue<number>;
172
+ ghostVisible: SharedValue<number>;
173
+ // Show the ghost for `event`, then drop it at pager-local `ghostLocalX` shifted
174
+ // in time by `minuteDelta` (clearing the ghost either way).
175
+ beginLift: (event: CalendarEvent<unknown>) => void;
176
+ commitLiftedDrop: (ghostLocalX: number, minuteDelta: number) => void;
177
+ };
178
+ const EdgePagingContext = createContext<EdgePaging | null>(null);
179
+
180
+ const noop = () => {};
181
+
182
+ /**
183
+ * The floating copy of a dragged event, rendered above the pager so a cross-week
184
+ * drag stays visible after its source page pages away. Position, size, and
185
+ * visibility are driven on the UI thread by the shared values so it tracks the
186
+ * finger without a React re-render.
187
+ */
188
+ function DragGhost<T>({
189
+ x,
190
+ y,
191
+ w,
192
+ h,
193
+ visible,
194
+ event,
195
+ mode,
196
+ renderEvent,
197
+ }: {
198
+ x: SharedValue<number>;
199
+ y: SharedValue<number>;
200
+ w: SharedValue<number>;
201
+ h: SharedValue<number>;
202
+ visible: SharedValue<number>;
203
+ event: CalendarEvent<T>;
204
+ mode: CalendarMode;
205
+ renderEvent: RenderEvent<T>;
206
+ }): ReactElement {
207
+ const RenderEventComponent = renderEvent;
208
+ const style = useAnimatedStyle(() => ({
209
+ transform: [{ translateX: x.value }, { translateY: y.value }],
210
+ width: w.value,
211
+ height: h.value,
212
+ opacity: visible.value,
213
+ }));
214
+ return (
215
+ <Animated.View style={[styles.eventBox, styles.dragGhost, style]} pointerEvents="none">
216
+ <RenderEventComponent event={event} mode={mode} boxHeight={h} onPress={noop} />
217
+ </Animated.View>
218
+ );
219
+ }
124
220
 
125
221
  /**
126
222
  * Called when an event is dragged (moved or resized) to new start/end times.
@@ -143,21 +239,6 @@ export type EventDragStartHandler<T> = (event: CalendarEvent<T>) => void;
143
239
  // scroll content by the same amount so the top-most label is never clipped.
144
240
  const HOUR_LABEL_TOP_INSET = 12;
145
241
  const HOUR_LABEL_NUDGE = 6;
146
- const NOW_TICK_MS = 60_000;
147
-
148
- // A `Date` that advances every minute while `enabled`, so the now-indicator
149
- // tracks the wall clock instead of freezing at mount. Off-screen pages pass
150
- // `enabled = false` and re-read the time when they become active.
151
- function useNow(enabled: boolean): Date {
152
- const [now, setNow] = useState(() => new Date());
153
- useEffect(() => {
154
- if (!enabled) return;
155
- setNow(new Date());
156
- const id = setInterval(() => setNow(new Date()), NOW_TICK_MS);
157
- return () => clearInterval(id);
158
- }, [enabled]);
159
- return now;
160
- }
161
242
 
162
243
  type AnimatedEventBoxProps<T> = {
163
244
  positioned: PositionedEvent<T>;
@@ -170,7 +251,14 @@ type AnimatedEventBoxProps<T> = {
170
251
  dayWidth: number;
171
252
  dayIndex: number;
172
253
  dayCount: number;
254
+ // Calendar-day offset of each visible column from the first (plain numbers, so
255
+ // the worklet can close over them). Lets a cross-day move map a column delta to
256
+ // the right calendar-day delta when hiddenDays makes the columns non-contiguous.
257
+ dayOrdinals: number[];
173
258
  mode: CalendarMode;
259
+ // Calendar days one page spans, for the "move to next/previous page" screen-
260
+ // reader actions (the accessible equivalent of dragging an event to the edge).
261
+ daysPerPage: number;
174
262
  renderEvent: RenderEvent<T>;
175
263
  snapMinutes: number;
176
264
  onPress: (event: CalendarEvent<T>) => void;
@@ -178,6 +266,13 @@ type AnimatedEventBoxProps<T> = {
178
266
  onDragEvent?: EventDragHandler<T>;
179
267
  onDragStart?: EventDragStartHandler<T>;
180
268
  showDragHandle: boolean;
269
+ // Grid-level defaults for move/resize, overridden per event by
270
+ // `startEditable`/`durationEditable`.
271
+ eventStartEditable: boolean;
272
+ eventDurationEditable: boolean;
273
+ // Page the view one period (dir -1/+1) when the event is dragged past the
274
+ // visible columns and held there. Absent disables edge auto-advance.
275
+ onEdgeAdvance?: (dir: number) => void;
181
276
  };
182
277
 
183
278
  function AnimatedEventBox<T>({
@@ -189,30 +284,74 @@ function AnimatedEventBox<T>({
189
284
  dayWidth,
190
285
  dayIndex,
191
286
  dayCount,
287
+ dayOrdinals,
192
288
  mode,
289
+ daysPerPage,
193
290
  renderEvent,
194
291
  snapMinutes,
195
292
  onPress,
196
293
  onLongPress,
197
294
  onDragEvent,
198
295
  onDragStart,
296
+ onEdgeAdvance,
199
297
  showDragHandle,
298
+ eventStartEditable,
299
+ eventDurationEditable,
200
300
  }: AnimatedEventBoxProps<T>) {
201
301
  const RenderEventComponent = renderEvent;
202
302
  const theme = useCalendarTheme();
203
303
  const slot = useSlots<TimeGridSlot>();
304
+ // Pager geometry + scroll lock, so a cross-week edge drag can find the edges
305
+ // and page the view live under the finger (see EdgePaging). The two edge
306
+ // shared values are pulled out so the move worklet closes over them directly
307
+ // rather than over the whole context object (which also holds a JS callback).
308
+ const edgePaging = useContext(EdgePagingContext);
309
+ const pagerLeftSV = edgePaging?.pagerLeft;
310
+ const pagerTopSV = edgePaging?.pagerTop;
311
+ const pagerWidthSV = edgePaging?.pagerWidth;
312
+ const ghostXSV = edgePaging?.ghostX;
313
+ const ghostYSV = edgePaging?.ghostY;
314
+ const commitLiftedDrop = edgePaging?.commitLiftedDrop;
204
315
  // Drag-to-move/resize. Native picks the event up on long-press (so a tap or
205
316
  // scroll isn't hijacked); web activates after a small drag threshold, so a
206
317
  // plain click still selects and a right-click still opens a context menu.
207
- const draggable = onDragEvent != null && !positioned.event.disabled;
318
+ // `draggable: false` locks a single event (keeps taps, blocks move/resize);
319
+ // `startEditable`/`durationEditable` (per event, falling back to the grid
320
+ // defaults) split whether it can be moved vs resized.
321
+ const editable =
322
+ onDragEvent != null && !positioned.event.disabled && positioned.event.draggable !== false;
323
+ const canMove = editable && (positioned.event.startEditable ?? eventStartEditable);
324
+ const canResize = editable && (positioned.event.durationEditable ?? eventDurationEditable);
208
325
  // Only the segment that owns the real end may be resized.
209
- const resizable = draggable && !positioned.continuesAfter;
326
+ const resizable = canResize && !positioned.continuesAfter;
327
+ // Only the segment that owns the real start may be resized from the top edge.
328
+ // Disabled on react-native-web: moving the box's top during its own child
329
+ // gesture drops the gesture there (a web-only gesture-handler quirk); on a
330
+ // device the top grip wins over the long-press move as usual. The dom renderer
331
+ // provides top-edge resize on the web.
332
+ const resizableFromStart = canResize && !positioned.continuesBefore && !isWeb;
210
333
 
211
334
  // Live preview offsets (px), reset to 0 once the committed change re-renders.
212
335
  // moveOffsetX shifts the box across day columns during a cross-day drag.
213
336
  const moveOffset = useSharedValue(0);
214
337
  const moveOffsetX = useSharedValue(0);
338
+ // Bottom-edge resize (changes the end) and top-edge resize (changes the start).
215
339
  const resizeDelta = useSharedValue(0);
340
+ const resizeStartDelta = useSharedValue(0);
341
+ // Raised to DRAG_EVENT_Z while a gesture is active so the dragged event floats
342
+ // above all the others, then back to 0 when it settles.
343
+ const dragZ = useSharedValue(0);
344
+ // Edge auto-advance: which side the drag has pushed past the visible columns
345
+ // (-1 left / 0 none / +1 right).
346
+ const edgeDir = useSharedValue(0);
347
+ // 1 once the event has been lifted into the floating ghost (cross-week drag),
348
+ // plus where in the box it was grabbed and the live finger position, so the
349
+ // ghost can be seeded from the JS dwell timer and track the finger after.
350
+ const lifted = useSharedValue(0);
351
+ const grabX = useSharedValue(0);
352
+ const grabY = useSharedValue(0);
353
+ const liveAbsX = useSharedValue(0);
354
+ const liveAbsY = useSharedValue(0);
216
355
 
217
356
  // Pull the geometry out as primitives so the worklets below close over plain
218
357
  // numbers, not `positioned` itself. Referencing `positioned.*` inside a
@@ -227,15 +366,21 @@ function AnimatedEventBox<T>({
227
366
  // renderers can reveal detail progressively as the grid zooms, without
228
367
  // re-rendering. Explicit deps so the worklet re-captures the event's geometry.
229
368
  const boxHeight = useDerivedValue(
230
- () => Math.max(durationHours * cellHeight.value + resizeDelta.value, MIN_EVENT_HEIGHT),
369
+ () =>
370
+ Math.max(
371
+ durationHours * cellHeight.value + resizeDelta.value - resizeStartDelta.value,
372
+ MIN_EVENT_HEIGHT,
373
+ ),
231
374
  [durationHours],
232
375
  );
233
376
 
234
377
  const boxStyle = useAnimatedStyle(
235
378
  () => ({
236
- top: (startHours - minHour) * cellHeight.value + moveOffset.value,
379
+ // A top-edge resize pushes the box down and shortens it (start moves later).
380
+ top: (startHours - minHour) * cellHeight.value + moveOffset.value + resizeStartDelta.value,
237
381
  height: boxHeight.value,
238
382
  transform: [{ translateX: moveOffsetX.value }],
383
+ zIndex: dragZ.value,
239
384
  }),
240
385
  [startHours, durationHours, minHour],
241
386
  );
@@ -251,7 +396,16 @@ function AnimatedEventBox<T>({
251
396
  moveOffsetX.value = 0;
252
397
  // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
253
398
  resizeDelta.value = 0;
254
- }, [positioned.startHours, positioned.durationHours, moveOffset, moveOffsetX, resizeDelta]);
399
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
400
+ resizeStartDelta.value = 0;
401
+ }, [
402
+ positioned.startHours,
403
+ positioned.durationHours,
404
+ moveOffset,
405
+ moveOffsetX,
406
+ resizeDelta,
407
+ resizeStartDelta,
408
+ ]);
255
409
 
256
410
  // Keep the latest event/handler in a ref so the gestures stay memoized but
257
411
  // never call into a stale closure.
@@ -266,7 +420,9 @@ function AnimatedEventBox<T>({
266
420
  moveOffsetX.value = 0;
267
421
  // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
268
422
  resizeDelta.value = 0;
269
- }, [moveOffset, moveOffsetX, resizeDelta]);
423
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
424
+ resizeStartDelta.value = 0;
425
+ }, [moveOffset, moveOffsetX, resizeDelta, resizeStartDelta]);
270
426
 
271
427
  const commitDrag = useCallback(
272
428
  (deltaStartMin: number, deltaEndMin: number) => {
@@ -297,17 +453,112 @@ function AnimatedEventBox<T>({
297
453
  latest.current.onDragStart?.(latest.current.event);
298
454
  }, []);
299
455
 
456
+ // Edge auto-advance dwell. Dragging the event past the visible columns and
457
+ // holding there pages the view one period and carries the event onto it: same
458
+ // weekday, keeping whatever time the vertical drag has reached. It fires once
459
+ // per drag (the box unmounts as the page changes), matching "hold at the edge
460
+ // to move to the next/previous week"; the tested commit path does the move.
461
+ const dwellTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
462
+ const disarmEdge = useCallback(() => {
463
+ if (dwellTimer.current) {
464
+ clearTimeout(dwellTimer.current);
465
+ dwellTimer.current = null;
466
+ }
467
+ }, []);
468
+ // Cancel a pending dwell and hand the pager's swipe scroll back. Runs on every
469
+ // gesture end so a lock taken by an edge-page is always released.
470
+ const releaseEdge = useCallback(() => {
471
+ disarmEdge();
472
+ edgePaging?.lockScroll(false);
473
+ }, [disarmEdge, edgePaging]);
474
+ const armEdge = useCallback(
475
+ (dir: number) => {
476
+ disarmEdge();
477
+ dwellTimer.current = setTimeout(() => {
478
+ dwellTimer.current = null;
479
+ if (!edgePaging) return;
480
+ // Freeze the pager's own swipe before paging: on native a programmatic
481
+ // scroll is deferred while the touch is tracked, so without this the view
482
+ // wouldn't advance until the finger lifts.
483
+ edgePaging.lockScroll(true);
484
+ // First edge fire: lift the event into the floating ghost. It must NOT
485
+ // commit here — committing relocates the event off this page, which
486
+ // unmounts the dragging box and kills the gesture. Instead the ghost
487
+ // (seeded at the current finger position) carries the event across the
488
+ // page, and the drop commits on release. The source box stays mounted, so
489
+ // the same gesture keeps tracking after the page changes.
490
+ if (!lifted.value) {
491
+ lifted.value = 1;
492
+ edgePaging.ghostW.value = width;
493
+ edgePaging.ghostH.value = boxHeight.value;
494
+ edgePaging.ghostX.value = liveAbsX.value - grabX.value - edgePaging.pagerLeft.value;
495
+ edgePaging.ghostY.value = liveAbsY.value - grabY.value - edgePaging.pagerTop.value;
496
+ edgePaging.ghostVisible.value = 1;
497
+ edgePaging.beginLift(latest.current.event as CalendarEvent<unknown>);
498
+ }
499
+ onEdgeAdvance?.(dir);
500
+ }, EDGE_DWELL_MS);
501
+ },
502
+ [
503
+ disarmEdge,
504
+ edgePaging,
505
+ lifted,
506
+ width,
507
+ boxHeight,
508
+ liveAbsX,
509
+ liveAbsY,
510
+ grabX,
511
+ grabY,
512
+ onEdgeAdvance,
513
+ ],
514
+ );
515
+
300
516
  const moveGesture = useMemo(() => {
301
517
  const pan = Gesture.Pan()
302
- .enabled(draggable)
303
- .onStart(() => {
518
+ .enabled(canMove)
519
+ .onStart((event) => {
520
+ dragZ.value = DRAG_EVENT_Z;
521
+ edgeDir.value = 0;
522
+ lifted.value = 0;
523
+ // Where in the box the finger grabbed, and the live finger position, so
524
+ // the ghost can be seeded and tracked in window space (see armEdge).
525
+ grabX.value = event.x;
526
+ grabY.value = event.y;
527
+ liveAbsX.value = event.absoluteX;
528
+ liveAbsY.value = event.absoluteY;
304
529
  runOnJS(notifyDragStart)();
305
530
  })
306
531
  .onUpdate((event) => {
307
- moveOffset.value = event.translationY;
308
- moveOffsetX.value = event.translationX;
532
+ liveAbsX.value = event.absoluteX;
533
+ liveAbsY.value = event.absoluteY;
534
+ // Once lifted, the box itself has paged off-screen; the ghost (a sibling of
535
+ // the pager) tracks the finger in pager-local space instead.
536
+ if (lifted.value && pagerLeftSV && pagerTopSV && ghostXSV && ghostYSV) {
537
+ ghostXSV.value = event.absoluteX - grabX.value - pagerLeftSV.value;
538
+ ghostYSV.value = event.absoluteY - grabY.value - pagerTopSV.value;
539
+ } else {
540
+ moveOffset.value = event.translationY;
541
+ moveOffsetX.value = event.translationX;
542
+ }
543
+ // Dragging the finger to the pager's left/right edge arms an edge dwell
544
+ // that pages the view. Measured by absolute finger position (not by how
545
+ // many columns the drag crossed), so an event in any column can reach
546
+ // either edge. `onEdgeAdvance` is only wired when paging is available.
547
+ if (onEdgeAdvance && pagerLeftSV && pagerWidthSV) {
548
+ const fx = event.absoluteX - pagerLeftSV.value;
549
+ const dir = fx > pagerWidthSV.value - EDGE_ZONE_PX ? 1 : fx < EDGE_ZONE_PX ? -1 : 0;
550
+ if (dir !== edgeDir.value) {
551
+ edgeDir.value = dir;
552
+ if (dir === 0) runOnJS(disarmEdge)();
553
+ else runOnJS(armEdge)(dir);
554
+ }
555
+ }
309
556
  })
310
557
  .onEnd((event) => {
558
+ // A cross-week drag is committed in onFinalize (which fires whether the
559
+ // gesture ends cleanly or is cancelled as the page moves under it), so the
560
+ // drop lands even when onEnd doesn't fire on device. Nothing to do here.
561
+ if (lifted.value) return;
311
562
  const minuteDelta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
312
563
  // Map the horizontal drag to whole day columns, clamped so the event
313
564
  // can't leave the visible range.
@@ -323,10 +574,27 @@ function AnimatedEventBox<T>({
323
574
  // original before the committed re-render lands.
324
575
  moveOffset.value = (minuteDelta / MINUTES_PER_HOUR) * cellHeight.value;
325
576
  moveOffsetX.value = dayDelta * dayWidth;
326
- // Fold the day shift into the minute delta; shiftMinutes carries it into
327
- // the date, so both edges move together and the duration is preserved.
328
- const totalDelta = minuteDelta + dayDelta * MINUTES_PER_DAY;
577
+ // Map the column shift to a calendar-day shift: with hiddenDays the
578
+ // columns aren't contiguous days, so a one-column move can span several
579
+ // calendar days. Fold that into the minute delta; shiftMinutes carries it
580
+ // into the date, so both edges move together and the duration is preserved.
581
+ const calendarDayDelta = dayOrdinals[targetDay] - dayOrdinals[dayIndex];
582
+ const totalDelta = minuteDelta + calendarDayDelta * MINUTES_PER_DAY;
329
583
  runOnJS(commitDrag)(totalDelta, totalDelta);
584
+ })
585
+ .onFinalize(() => {
586
+ dragZ.value = 0;
587
+ // Commit the cross-week drop here: onFinalize fires on every gesture end,
588
+ // including the cancel RNGH reports when the source page moves under the
589
+ // touch, so committing from the last finger position (ghost column + the
590
+ // vertical drag) guarantees the drop lands instead of silently vanishing.
591
+ if (lifted.value && ghostXSV && ghostYSV && commitLiftedDrop) {
592
+ runOnJS(commitLiftedDrop)(ghostXSV.value, ghostYSV.value);
593
+ moveOffset.value = 0;
594
+ moveOffsetX.value = 0;
595
+ lifted.value = 0;
596
+ }
597
+ runOnJS(releaseEdge)();
330
598
  });
331
599
  // Native: long-press to pick up. Web: activate past a small drag in either
332
600
  // axis so clicks/right-clicks pass through but horizontal drags still move.
@@ -336,16 +604,34 @@ function AnimatedEventBox<T>({
336
604
  .activeOffsetY([-DRAG_ACTIVATE_PX, DRAG_ACTIVATE_PX])
337
605
  : pan.activateAfterLongPress(MOVE_ACTIVATE_MS);
338
606
  }, [
339
- draggable,
607
+ canMove,
340
608
  snapMinutes,
341
609
  cellHeight,
342
610
  moveOffset,
343
611
  moveOffsetX,
612
+ dragZ,
613
+ edgeDir,
614
+ lifted,
615
+ grabX,
616
+ grabY,
617
+ liveAbsX,
618
+ liveAbsY,
619
+ pagerLeftSV,
620
+ pagerTopSV,
621
+ pagerWidthSV,
622
+ ghostXSV,
623
+ ghostYSV,
624
+ commitLiftedDrop,
344
625
  dayWidth,
345
626
  dayIndex,
346
627
  dayCount,
628
+ dayOrdinals,
347
629
  commitDrag,
348
630
  notifyDragStart,
631
+ onEdgeAdvance,
632
+ armEdge,
633
+ disarmEdge,
634
+ releaseEdge,
349
635
  ]);
350
636
 
351
637
  const resizeGesture = useMemo(
@@ -353,6 +639,7 @@ function AnimatedEventBox<T>({
353
639
  Gesture.Pan()
354
640
  .enabled(resizable)
355
641
  .onStart(() => {
642
+ dragZ.value = DRAG_EVENT_Z;
356
643
  runOnJS(notifyDragStart)();
357
644
  })
358
645
  .onUpdate((event) => {
@@ -366,33 +653,87 @@ function AnimatedEventBox<T>({
366
653
  }
367
654
  resizeDelta.value = (delta / MINUTES_PER_HOUR) * cellHeight.value;
368
655
  runOnJS(commitDrag)(0, delta);
656
+ })
657
+ .onFinalize(() => {
658
+ dragZ.value = 0;
369
659
  }),
370
- [resizable, snapMinutes, cellHeight, resizeDelta, commitDrag, notifyDragStart],
660
+ [resizable, snapMinutes, cellHeight, resizeDelta, dragZ, commitDrag, notifyDragStart],
661
+ );
662
+
663
+ // Top-edge resize: dragging the top changes the start (end fixed). Mirrors the
664
+ // bottom resize but commits a start-delta and previews via resizeStartDelta.
665
+ const resizeStartGesture = useMemo(
666
+ () =>
667
+ Gesture.Pan()
668
+ .enabled(resizableFromStart)
669
+ .onStart(() => {
670
+ dragZ.value = DRAG_EVENT_Z;
671
+ runOnJS(notifyDragStart)();
672
+ })
673
+ .onUpdate((event) => {
674
+ resizeStartDelta.value = event.translationY;
675
+ })
676
+ .onEnd((event) => {
677
+ const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
678
+ if (delta === 0) {
679
+ resizeStartDelta.value = 0;
680
+ return;
681
+ }
682
+ resizeStartDelta.value = (delta / MINUTES_PER_HOUR) * cellHeight.value;
683
+ runOnJS(commitDrag)(delta, 0);
684
+ })
685
+ .onFinalize(() => {
686
+ dragZ.value = 0;
687
+ }),
688
+ [
689
+ resizableFromStart,
690
+ snapMinutes,
691
+ cellHeight,
692
+ resizeStartDelta,
693
+ dragZ,
694
+ commitDrag,
695
+ notifyDragStart,
696
+ ],
371
697
  );
372
698
 
373
699
  const handlePress = () => onPress(positioned.event);
374
- // When draggable, a long press grabs the event to move it, so don't also fire
700
+ // When movable, a long press grabs the event to move it, so don't also fire
375
701
  // the consumer's long-press handler.
376
- const handleLongPress =
377
- !draggable && onLongPress ? () => onLongPress(positioned.event) : undefined;
702
+ const handleLongPress = !canMove && onLongPress ? () => onLongPress(positioned.event) : undefined;
378
703
 
379
704
  // Dragging is gesture-only, so expose the same move/resize commit path as
380
705
  // discrete screen-reader actions (VoiceOver/TalkBack invoke them from the
381
706
  // actions menu). Steps are one `snapMinutes` unit, matching a drag snap.
382
707
  const unit = (n: number) => `${n} minute${n === 1 ? "" : "s"}`;
383
- const accessibilityActions = draggable
384
- ? [
385
- { name: "move-later", label: `Move ${unit(snapMinutes)} later` },
386
- { name: "move-earlier", label: `Move ${unit(snapMinutes)} earlier` },
387
- ...(resizable
388
- ? [
389
- { name: "extend", label: `Extend by ${unit(snapMinutes)}` },
390
- { name: "shrink", label: `Shorten by ${unit(snapMinutes)}` },
391
- ]
392
- : []),
393
- ]
394
- : undefined;
395
- const handleAccessibilityAction = draggable
708
+ // Label the whole-page move by what a page means in this mode.
709
+ const pageUnit =
710
+ mode === "week"
711
+ ? "week"
712
+ : daysPerPage === 1
713
+ ? "day"
714
+ : `${daysPerPage} day${daysPerPage === 1 ? "" : "s"}`;
715
+ const dragActions = [
716
+ ...(canMove
717
+ ? [
718
+ { name: "move-later", label: `Move ${unit(snapMinutes)} later` },
719
+ { name: "move-earlier", label: `Move ${unit(snapMinutes)} earlier` },
720
+ ]
721
+ : []),
722
+ ...(resizable
723
+ ? [
724
+ { name: "extend", label: `Extend by ${unit(snapMinutes)}` },
725
+ { name: "shrink", label: `Shorten by ${unit(snapMinutes)}` },
726
+ ]
727
+ : []),
728
+ ...(canMove
729
+ ? [
730
+ { name: "move-next-page", label: `Move to next ${pageUnit}` },
731
+ { name: "move-previous-page", label: `Move to previous ${pageUnit}` },
732
+ ]
733
+ : []),
734
+ ];
735
+ const accessibilityActions = dragActions.length ? dragActions : undefined;
736
+ const handleAccessibilityAction = accessibilityActions
396
737
  ? (e: AccessibilityActionEvent) => {
397
738
  switch (e.nativeEvent.actionName) {
398
739
  case "move-later":
@@ -407,6 +748,12 @@ function AnimatedEventBox<T>({
407
748
  case "shrink":
408
749
  commitDrag(0, -snapMinutes);
409
750
  break;
751
+ case "move-next-page":
752
+ commitDrag(daysPerPage * MINUTES_PER_DAY, daysPerPage * MINUTES_PER_DAY);
753
+ break;
754
+ case "move-previous-page":
755
+ commitDrag(-daysPerPage * MINUTES_PER_DAY, -daysPerPage * MINUTES_PER_DAY);
756
+ break;
410
757
  }
411
758
  }
412
759
  : undefined;
@@ -428,6 +775,15 @@ function AnimatedEventBox<T>({
428
775
  onPress={handlePress}
429
776
  onLongPress={handleLongPress}
430
777
  />
778
+ {resizableFromStart ? (
779
+ <GestureDetector gesture={resizeStartGesture}>
780
+ <Animated.View style={styles.resizeHandleTop}>
781
+ {showDragHandle ? (
782
+ <View style={[styles.resizeGrip, { backgroundColor: theme.colors.eventText }]} />
783
+ ) : null}
784
+ </Animated.View>
785
+ </GestureDetector>
786
+ ) : null}
431
787
  {resizable ? (
432
788
  <GestureDetector gesture={resizeGesture}>
433
789
  <Animated.View style={styles.resizeHandle}>
@@ -442,7 +798,9 @@ function AnimatedEventBox<T>({
442
798
  </Animated.View>
443
799
  );
444
800
 
445
- if (!draggable) return box;
801
+ // Only wrap in the move gesture when movable; the resize grips inside `box`
802
+ // carry their own gestures, so a resize-only event still works.
803
+ if (!canMove) return box;
446
804
  return <GestureDetector gesture={moveGesture}>{box}</GestureDetector>;
447
805
  }
448
806
 
@@ -563,7 +921,12 @@ type ShadeBandProps = {
563
921
  minHour: number;
564
922
  left: number;
565
923
  width: number;
566
- color: string;
924
+ /** Themed fill. Omit when a render override owns the band's look. */
925
+ color?: string;
926
+ /** Which slot/testID the band belongs to (closed hours vs background events). */
927
+ slotName?: "businessHours" | "backgroundEvent";
928
+ testID?: string;
929
+ children?: React.ReactNode;
567
930
  };
568
931
 
569
932
  // A muted band over a closed hour-range of one day column (driven by the live
@@ -576,6 +939,9 @@ const ShadeBand = ({
576
939
  left,
577
940
  width,
578
941
  color,
942
+ slotName = "businessHours",
943
+ testID = "business-hours-shade",
944
+ children,
579
945
  }: ShadeBandProps) => {
580
946
  const slot = useSlots<TimeGridSlot>();
581
947
  const animatedStyle = useAnimatedStyle(
@@ -585,22 +951,30 @@ const ShadeBand = ({
585
951
  }),
586
952
  [startHour, endHour, minHour],
587
953
  );
588
- const bandSlot = slot("businessHours", {
954
+ const bandSlot = slot(slotName, {
589
955
  base: [styles.shadeBand, styles.nonInteractive, { left, width }],
590
- themed: { backgroundColor: color },
956
+ themed: color === undefined ? undefined : { backgroundColor: color },
591
957
  });
592
958
  return (
593
959
  <Animated.View
594
- testID="business-hours-shade"
960
+ testID={testID}
961
+ // Decorative, like the dom bands' aria-hidden: never announced or focused.
962
+ accessibilityElementsHidden
963
+ importantForAccessibility="no-hide-descendants"
595
964
  {...bandSlot}
596
965
  style={[bandSlot.style, animatedStyle]}
597
- />
966
+ >
967
+ {children}
968
+ </Animated.View>
598
969
  );
599
970
  };
600
971
 
601
972
  type TimetablePageProps<T> = {
602
973
  mode: TimeGridMode;
603
974
  numberOfDays: number;
975
+ hiddenDays?: number[];
976
+ now?: Date;
977
+ nowTimeZone?: string;
604
978
  date: Date;
605
979
  events: CalendarEvent<T>[];
606
980
  cellHeight: SharedValue<number>;
@@ -627,11 +1001,13 @@ type TimetablePageProps<T> = {
627
1001
  timeslots: number;
628
1002
  isRTL: boolean;
629
1003
  showAllDayEventCell: boolean;
1004
+ highlightWeekends: boolean;
630
1005
  showVerticalScrollIndicator: boolean;
631
1006
  verticalScrollEnabled: boolean;
632
1007
  hourComponent?: HourRenderer;
633
1008
  calendarCellStyle?: (date: Date) => StyleProp<ViewStyle>;
634
1009
  businessHours?: BusinessHours;
1010
+ renderBusinessHours?: (band: BusinessHoursBand) => React.ReactNode;
635
1011
  minHourHeight: number;
636
1012
  maxHourHeight: number;
637
1013
  showNowIndicator: boolean;
@@ -639,6 +1015,8 @@ type TimetablePageProps<T> = {
639
1015
  keyExtractor: EventKeyExtractor<T>;
640
1016
  snapMinutes: number;
641
1017
  showDragHandle: boolean;
1018
+ eventStartEditable: boolean;
1019
+ eventDurationEditable: boolean;
642
1020
  onPressEvent: (event: CalendarEvent<T>) => void;
643
1021
  onLongPressEvent?: (event: CalendarEvent<T>) => void;
644
1022
  onDragEvent?: EventDragHandler<T>;
@@ -646,6 +1024,10 @@ type TimetablePageProps<T> = {
646
1024
  onPressCell?: (date: Date) => void;
647
1025
  onLongPressCell?: (date: Date) => void;
648
1026
  onCreateEvent?: (start: Date, end: Date) => void;
1027
+ onEdgeAdvance?: (dir: number) => void;
1028
+ /** Report this page's hour-grid top (below the all-day lane), while it is the
1029
+ * active page, so a cross-week drop can map a ghost's Y to the right time. */
1030
+ onGridTop?: (y: number) => void;
649
1031
  };
650
1032
 
651
1033
  // A single date's grid: the pinch-zoomable, vertically-scrolling time column.
@@ -654,6 +1036,9 @@ type TimetablePageProps<T> = {
654
1036
  function TimetablePageInner<T>({
655
1037
  mode,
656
1038
  numberOfDays,
1039
+ hiddenDays,
1040
+ now: nowProp,
1041
+ nowTimeZone,
657
1042
  date,
658
1043
  events,
659
1044
  cellHeight,
@@ -673,6 +1058,7 @@ function TimetablePageInner<T>({
673
1058
  timeslots,
674
1059
  isRTL,
675
1060
  showAllDayEventCell,
1061
+ highlightWeekends,
676
1062
  showVerticalScrollIndicator,
677
1063
  verticalScrollEnabled,
678
1064
  hourComponent,
@@ -681,10 +1067,13 @@ function TimetablePageInner<T>({
681
1067
  maxHourHeight,
682
1068
  showNowIndicator,
683
1069
  businessHours,
1070
+ renderBusinessHours,
684
1071
  renderEvent,
685
1072
  keyExtractor,
686
1073
  snapMinutes,
687
1074
  showDragHandle,
1075
+ eventStartEditable,
1076
+ eventDurationEditable,
688
1077
  onPressEvent,
689
1078
  onLongPressEvent,
690
1079
  onDragEvent,
@@ -692,10 +1081,18 @@ function TimetablePageInner<T>({
692
1081
  onPressCell,
693
1082
  onLongPressCell,
694
1083
  onCreateEvent,
1084
+ onEdgeAdvance,
1085
+ onGridTop,
695
1086
  }: TimetablePageProps<T>) {
696
1087
  const theme = useCalendarTheme();
697
1088
  const slot = useSlots<TimeGridSlot>();
698
1089
  const scrollRef = useAnimatedRef<Animated.ScrollView>();
1090
+ // The hour grid sits below the all-day lane; capture its top on layout and
1091
+ // report it up while this page is active (the lane height differs per week).
1092
+ const gridTopRef = useRef(0);
1093
+ useEffect(() => {
1094
+ if (isActive) onGridTop?.(gridTopRef.current);
1095
+ }, [isActive, onGridTop]);
699
1096
 
700
1097
  // The visible page tracks the live cellHeight (animates every pinch frame);
701
1098
  // off-screen pages track committedCellHeight (settles once per gesture).
@@ -782,9 +1179,12 @@ function TimetablePageInner<T>({
782
1179
  );
783
1180
 
784
1181
  const days = useMemo(
785
- () => getViewDays(mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn),
786
- [mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn],
1182
+ () => getViewDays(mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays),
1183
+ [mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays],
787
1184
  );
1185
+ // Calendar days one page spans (7 for week, the column count otherwise), for
1186
+ // the "move to next/previous page" screen-reader actions.
1187
+ const daysPerPage = pageStepDays(mode, date, weekStartsOn, numberOfDays);
788
1188
 
789
1189
  // Plain number for worklets to close over: reading `days.length` inside a
790
1190
  // gesture worklet would capture the whole `days` array (of `Date`s), which
@@ -793,6 +1193,15 @@ function TimetablePageInner<T>({
793
1193
  const dayWidth = (width - hourColumnWidth) / dayCount;
794
1194
  const dayLeft = (dayIndex: number) => hourColumnWidth + dayIndex * dayWidth;
795
1195
 
1196
+ // Calendar-day offset of each column from the first, as plain numbers a drag
1197
+ // worklet can close over. Identity (0,1,2,…) for contiguous days; with
1198
+ // hiddenDays the gaps widen, so a cross-day move shifts by the right number of
1199
+ // calendar days. Signed correctly for RTL (columns run high→low).
1200
+ const dayOrdinals = useMemo(
1201
+ () => days.map((day) => differenceInCalendarDays(day, days[0])),
1202
+ [days],
1203
+ );
1204
+
796
1205
  const dayLayouts = useMemo(() => days.map((day) => layoutDayEvents(events, day)), [days, events]);
797
1206
 
798
1207
  // Map a tap on empty grid space back to the date+time it represents. Reads the
@@ -823,8 +1232,10 @@ function TimetablePageInner<T>({
823
1232
  [minHour, maxHour],
824
1233
  );
825
1234
 
826
- const now = useNow(showNowIndicator && isActive);
827
- const nowDayIndex = days.findIndex((day) => getIsToday(day));
1235
+ const now = useNow(showNowIndicator && isActive, { now: nowProp, timeZone: nowTimeZone });
1236
+ // "Today" follows the (possibly zone-shifted or overridden) now, so the line
1237
+ // lands in the column the events are displayed in.
1238
+ const nowDayIndex = days.findIndex((day) => isSameCalendarDay(day, now));
828
1239
  const nowHours = (getHours(now) * MINUTES_PER_HOUR + getMinutes(now)) / MINUTES_PER_HOUR;
829
1240
  const nowInWindow = nowHours >= minHour && nowHours <= maxHour;
830
1241
 
@@ -1049,6 +1460,12 @@ function TimetablePageInner<T>({
1049
1460
  scrollEnabled={verticalScrollEnabled}
1050
1461
  onScroll={scrollHandler}
1051
1462
  scrollEventThrottle={16}
1463
+ onLayout={(event) => {
1464
+ // The scroll view's offset within the page equals the all-day lane
1465
+ // height above it: the hour grid's top. Report it while active.
1466
+ gridTopRef.current = event.nativeEvent.layout.y;
1467
+ if (isActive) onGridTop?.(gridTopRef.current);
1468
+ }}
1052
1469
  contentContainerStyle={{ paddingTop: HOUR_LABEL_TOP_INSET }}
1053
1470
  contentOffset={{ x: 0, y: initialScrollY }}
1054
1471
  >
@@ -1062,7 +1479,7 @@ function TimetablePageInner<T>({
1062
1479
  )}
1063
1480
 
1064
1481
  {days.map((day, dayIndex) => {
1065
- if (!isWeekend(day)) return null;
1482
+ if (!highlightWeekends || !isWeekend(day)) return null;
1066
1483
  const shadeSlot = slot("weekendShade", {
1067
1484
  base: [
1068
1485
  styles.weekendColumn,
@@ -1074,6 +1491,7 @@ function TimetablePageInner<T>({
1074
1491
  return (
1075
1492
  <Animated.View
1076
1493
  key={`weekend-${day.toISOString()}`}
1494
+ testID="weekend-shade"
1077
1495
  {...shadeSlot}
1078
1496
  style={[shadeSlot.style, fullHeightStyle]}
1079
1497
  />
@@ -1109,12 +1527,39 @@ function TimetablePageInner<T>({
1109
1527
  minHour={minHour}
1110
1528
  left={dayLeft(dayIndex)}
1111
1529
  width={dayWidth}
1112
- color={theme.colors.outsideHoursBackground}
1113
- />
1530
+ color={renderBusinessHours ? undefined : theme.colors.outsideHoursBackground}
1531
+ >
1532
+ {renderBusinessHours?.({ date: day, start: band.start, end: band.end })}
1533
+ </ShadeBand>
1114
1534
  )),
1115
1535
  )
1116
1536
  : null}
1117
1537
 
1538
+ {/* Background events: shaded, non-interactive time ranges. */}
1539
+ {days.flatMap((day, dayIndex) =>
1540
+ backgroundBandsForDay(events, day)
1541
+ .map((b) => ({
1542
+ ...b,
1543
+ startHours: Math.max(b.startHours, minHour),
1544
+ endHours: Math.min(b.endHours, maxHour),
1545
+ }))
1546
+ .filter((b) => b.endHours > b.startHours)
1547
+ .map((b, bandIndex) => (
1548
+ <ShadeBand
1549
+ key={`bg-${day.toISOString()}-${bandIndex}`}
1550
+ cellHeight={heightSource}
1551
+ startHour={b.startHours}
1552
+ endHour={b.endHours}
1553
+ minHour={minHour}
1554
+ left={dayLeft(dayIndex)}
1555
+ width={dayWidth}
1556
+ color={theme.colors.backgroundEvent}
1557
+ slotName="backgroundEvent"
1558
+ testID="background-event-shade"
1559
+ />
1560
+ )),
1561
+ )}
1562
+
1118
1563
  {days.map((day, dayIndex) => {
1119
1564
  const separatorSlot = slot("daySeparator", {
1120
1565
  base: [styles.daySeparator, styles.nonInteractive, { left: dayLeft(dayIndex) }],
@@ -1177,14 +1622,19 @@ function TimetablePageInner<T>({
1177
1622
  dayWidth={dayWidth}
1178
1623
  dayIndex={dayIndex}
1179
1624
  dayCount={days.length}
1625
+ dayOrdinals={dayOrdinals}
1180
1626
  mode={mode}
1627
+ daysPerPage={daysPerPage}
1181
1628
  renderEvent={renderEvent}
1182
1629
  snapMinutes={snapMinutes}
1183
1630
  showDragHandle={showDragHandle}
1631
+ eventStartEditable={eventStartEditable}
1632
+ eventDurationEditable={eventDurationEditable}
1184
1633
  onPress={onPressEvent}
1185
1634
  onLongPress={onLongPressEvent}
1186
1635
  onDragEvent={onDragEvent}
1187
1636
  onDragStart={onDragStart}
1637
+ onEdgeAdvance={onEdgeAdvance}
1188
1638
  />
1189
1639
  );
1190
1640
  }),
@@ -1237,6 +1687,7 @@ export type TimeGridSlot =
1237
1687
  | "hourLabel"
1238
1688
  | "gridLines"
1239
1689
  | "businessHours"
1690
+ | "backgroundEvent"
1240
1691
  | "weekendShade"
1241
1692
  | "daySeparator"
1242
1693
  | "event"
@@ -1254,6 +1705,12 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
1254
1705
  * precedence over `numberOfDays`. Ignored by other modes.
1255
1706
  */
1256
1707
  weekEndsOn?: WeekStartsOn;
1708
+ /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
1709
+ hiddenDays?: number[];
1710
+ /** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
1711
+ now?: Date;
1712
+ /** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
1713
+ timeZone?: string;
1257
1714
  date: Date;
1258
1715
  events: CalendarEvent<T>[];
1259
1716
  cellHeight: SharedValue<number>;
@@ -1278,9 +1735,19 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
1278
1735
  timeslots?: number;
1279
1736
  /** Show the all-day lane above the grid. Default true. */
1280
1737
  showAllDayEventCell?: boolean;
1738
+ /** Tint Saturday/Sunday columns with the weekend background. Default true. Set
1739
+ * false to treat weekends like any other day. */
1740
+ highlightWeekends?: boolean;
1281
1741
  /** Per-date style merged onto each day column. */
1282
1742
  calendarCellStyle?: (date: Date) => StyleProp<ViewStyle>;
1283
1743
  businessHours?: BusinessHours;
1744
+ /**
1745
+ * Render a closed-hours band's content yourself (a label, icon, pattern).
1746
+ * The grid keeps positioning the band; when set, the themed tint is dropped
1747
+ * and your output fills the band instead. Decorative only: the
1748
+ * band stays non-interactive and hidden from assistive tech.
1749
+ */
1750
+ renderBusinessHours?: (band: BusinessHoursBand) => React.ReactNode;
1284
1751
  /** Show the ISO week number in the header gutter. Default false. */
1285
1752
  showWeekNumber?: boolean;
1286
1753
  /** Element rendered between the day header and the grid. */
@@ -1319,6 +1786,13 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
1319
1786
  * drag-to-move and drag-to-resize working while hiding the visible indicator.
1320
1787
  */
1321
1788
  showDragHandle?: boolean;
1789
+ /** Allow moving events by default (per-event `startEditable` overrides). Default true. */
1790
+ eventStartEditable?: boolean;
1791
+ /** Allow resizing events by default (per-event `durationEditable` overrides). Default true. */
1792
+ eventDurationEditable?: boolean;
1793
+ /** Allow a dragged/resized event to overlap another (default true). Set false to
1794
+ * reject a drop that would collide, snapping the event back. */
1795
+ eventOverlap?: boolean;
1322
1796
  onPressEvent: (event: CalendarEvent<T>) => void;
1323
1797
  onLongPressEvent?: (event: CalendarEvent<T>) => void;
1324
1798
  /**
@@ -1356,8 +1830,10 @@ function TimeGridInner<T>({
1356
1830
  hideHours = false,
1357
1831
  timeslots = 1,
1358
1832
  showAllDayEventCell = true,
1833
+ highlightWeekends = true,
1359
1834
  calendarCellStyle,
1360
1835
  businessHours,
1836
+ renderBusinessHours,
1361
1837
  showWeekNumber = false,
1362
1838
  headerComponent,
1363
1839
  minHour = 0,
@@ -1373,14 +1849,20 @@ function TimeGridInner<T>({
1373
1849
  showVerticalScrollIndicator = true,
1374
1850
  verticalScrollEnabled = true,
1375
1851
  weekNumberPrefix = "W",
1852
+ hiddenDays,
1853
+ now,
1854
+ timeZone,
1376
1855
  hourComponent,
1377
1856
  activeDate,
1378
1857
  resetPageOnPressCell = false,
1379
1858
  dragStepMinutes = DEFAULT_DRAG_STEP_MINUTES,
1380
1859
  showDragHandle = true,
1860
+ eventStartEditable = true,
1861
+ eventDurationEditable = true,
1862
+ eventOverlap = true,
1381
1863
  onPressEvent,
1382
1864
  onLongPressEvent,
1383
- onDragEvent,
1865
+ onDragEvent: onDragEventProp,
1384
1866
  onDragStart,
1385
1867
  onPressCell,
1386
1868
  onLongPressCell,
@@ -1405,8 +1887,20 @@ function TimeGridInner<T>({
1405
1887
  [renderEvent, eventAccessibilityLabel, ampm],
1406
1888
  );
1407
1889
 
1890
+ // Reject a drop that would overlap another event when `eventOverlap` is false,
1891
+ // so every commit path (drag, resize, cross-week, screen-reader actions) enforces
1892
+ // it without the consumer wiring it in `onDragEvent`.
1893
+ const onDragEvent = useMemo(() => {
1894
+ if (!onDragEventProp || eventOverlap !== false) return onDragEventProp;
1895
+ return (event: CalendarEvent<T>, start: Date, end: Date) =>
1896
+ overlapsOtherEvents(events, event, start, end) ? false : onDragEventProp(event, start, end);
1897
+ }, [onDragEventProp, eventOverlap, events]);
1898
+
1408
1899
  const { width, height } = useWindowDimensions();
1409
1900
  const listRef = useRef<LegendListRef>(null);
1901
+ // The pager's own view; measured in the window so an event drag can locate the
1902
+ // horizontal edges (its screen-space left and width) for cross-week paging.
1903
+ const pagerRef = useRef<View>(null);
1410
1904
  // The grid's outer view; on web its ref resolves to the DOM node we attach the
1411
1905
  // Ctrl/Cmd + scroll zoom listener to.
1412
1906
  const containerRef = useRef<View>(null);
@@ -1437,6 +1931,123 @@ function TimeGridInner<T>({
1437
1931
  const seedDefaultY =
1438
1932
  Math.max(0, scrollOffsetMinutes / MINUTES_PER_HOUR - clampedMinHour) * hourHeight;
1439
1933
  const scrollY = useSharedValue(seedDefaultY);
1934
+ // Pager frame in window space (refined on layout) and a swipe-scroll freeze,
1935
+ // shared with the event drag worklets through EdgePagingContext so a cross-week
1936
+ // edge drag can detect the edges and page the view live under a held finger.
1937
+ const pagerLeft = useSharedValue(0);
1938
+ const pagerTop = useSharedValue(0);
1939
+ const pagerWidth = useSharedValue(width);
1940
+ const [edgePagingLock, setEdgePagingLock] = useState(false);
1941
+ // Floating "held" ghost that carries a dragged event across a page change (see
1942
+ // EdgePaging): pager-local top-left, size, visibility, and the event to draw.
1943
+ const ghostX = useSharedValue(0);
1944
+ const ghostY = useSharedValue(0);
1945
+ const ghostW = useSharedValue(0);
1946
+ const ghostH = useSharedValue(0);
1947
+ const ghostVisible = useSharedValue(0);
1948
+ // Pager-local top of the active page's hour grid (the all-day lane above it
1949
+ // varies in height per week), so a cross-week drop maps the ghost's screen
1950
+ // position to the right time on the page it lands on.
1951
+ const gridTop = useSharedValue(0);
1952
+ const [liftedEvent, setLiftedEvent] = useState<CalendarEvent<T> | null>(null);
1953
+ const liftedEventRef = useRef<CalendarEvent<T> | null>(null);
1954
+ // The drop commit needs the live page's columns and handler; keep them in a ref
1955
+ // refreshed each render so the callbacks below stay identity-stable. A changing
1956
+ // context value would re-memo every event's gesture and tear down an in-progress
1957
+ // drag (the gesture must outlive the page change to finish a cross-week drop).
1958
+ const dropRef = useRef({
1959
+ headerDays: [] as Date[],
1960
+ containerWidth,
1961
+ hourColumnWidth,
1962
+ minHour: clampedMinHour,
1963
+ snapMinutes: Math.max(1, dragStepMinutes),
1964
+ onDragEvent,
1965
+ onChangeDate,
1966
+ });
1967
+ const beginLift = useCallback((event: CalendarEvent<unknown>) => {
1968
+ liftedEventRef.current = event as CalendarEvent<T>;
1969
+ setLiftedEvent(event as CalendarEvent<T>);
1970
+ }, []);
1971
+ const clearLift = useCallback(() => {
1972
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
1973
+ ghostVisible.value = 0;
1974
+ liftedEventRef.current = null;
1975
+ setLiftedEvent(null);
1976
+ setEdgePagingLock(false);
1977
+ }, [ghostVisible]);
1978
+ const commitLiftedDrop = useCallback(
1979
+ (ghostLocalX: number, ghostLocalY: number) => {
1980
+ const {
1981
+ headerDays: days,
1982
+ containerWidth: cw,
1983
+ hourColumnWidth: hcw,
1984
+ minHour: min,
1985
+ snapMinutes: snap,
1986
+ onDragEvent: onDrag,
1987
+ onChangeDate: onDate,
1988
+ } = dropRef.current;
1989
+ const ev = liftedEventRef.current;
1990
+ const duration = ev ? ev.end.getTime() - ev.start.getTime() : 0;
1991
+ clearLift();
1992
+ if (!ev || !onDrag || days.length === 0) return;
1993
+ // Map the ghost's drawn position on the page it landed on back to a cell:
1994
+ // its left edge picks the day column, its top edge picks the time. Reading
1995
+ // the live grid geometry (the all-day lane pushes the grid down, the grid
1996
+ // scrolls, pinch changes the row height) keeps the drop under the ghost.
1997
+ const dayWidth = (cw - hcw) / days.length;
1998
+ const col = Math.min(
1999
+ Math.max(Math.floor((ghostLocalX - hcw) / dayWidth), 0),
2000
+ days.length - 1,
2001
+ );
2002
+ const hoursFromMin =
2003
+ (ghostLocalY - gridTop.value - HOUR_LABEL_TOP_INSET + scrollY.value) / cellHeight.value;
2004
+ const rawMinutes = (min + hoursFromMin) * MINUTES_PER_HOUR;
2005
+ const minutes = Math.round(rawMinutes / snap) * snap;
2006
+ const start = new Date(days[col]);
2007
+ start.setHours(0, 0, 0, 0);
2008
+ start.setMinutes(minutes);
2009
+ const end = new Date(start.getTime() + duration);
2010
+ // A rejected drop (handler returned false) leaves the event on its original
2011
+ // week, which the drag has paged away from. Page back to it so the reject
2012
+ // reads as a visible snap-back instead of the event seeming to vanish.
2013
+ if (onDrag(ev, start, end) === false) onDate(ev.start);
2014
+ },
2015
+ [clearLift, gridTop, scrollY, cellHeight],
2016
+ );
2017
+ const handleGridTop = useCallback(
2018
+ (y: number) => {
2019
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2020
+ gridTop.value = y;
2021
+ },
2022
+ [gridTop],
2023
+ );
2024
+ const edgePaging = useMemo<EdgePaging>(
2025
+ () => ({
2026
+ pagerLeft,
2027
+ pagerTop,
2028
+ pagerWidth,
2029
+ lockScroll: setEdgePagingLock,
2030
+ ghostX,
2031
+ ghostY,
2032
+ ghostW,
2033
+ ghostH,
2034
+ ghostVisible,
2035
+ beginLift,
2036
+ commitLiftedDrop,
2037
+ }),
2038
+ [
2039
+ pagerLeft,
2040
+ pagerTop,
2041
+ pagerWidth,
2042
+ ghostX,
2043
+ ghostY,
2044
+ ghostW,
2045
+ ghostH,
2046
+ ghostVisible,
2047
+ beginLift,
2048
+ commitLiftedDrop,
2049
+ ],
2050
+ );
1440
2051
  // Plain mirror of the last settled vertical offset. A page that mounts after a
1441
2052
  // scroll seeds its contentOffset here instead of the default, so it appears at the
1442
2053
  // saved time straight away rather than rendering at the default and snapping (the
@@ -1506,10 +2117,23 @@ function TimeGridInner<T>({
1506
2117
  numberOfDays,
1507
2118
  isRTL,
1508
2119
  weekEndsOn,
2120
+ hiddenDays,
1509
2121
  ),
1510
- [mode, pageDates, activeIndex, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn],
2122
+ [mode, pageDates, activeIndex, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays],
1511
2123
  );
1512
2124
 
2125
+ // Keep the cross-week drop's page columns + handler current without changing the
2126
+ // identity-stable EdgePaging callbacks (see dropRef).
2127
+ dropRef.current = {
2128
+ headerDays,
2129
+ containerWidth,
2130
+ hourColumnWidth,
2131
+ minHour: clampedMinHour,
2132
+ snapMinutes: Math.max(1, dragStepMinutes),
2133
+ onDragEvent,
2134
+ onChangeDate,
2135
+ };
2136
+
1513
2137
  const handleViewableItemsChanged = useCallback(
1514
2138
  (info: OnViewableItemsChangedInfo<Date>) => {
1515
2139
  // On the web the pager can't be swiped (overflow is hidden); every page change
@@ -1668,6 +2292,9 @@ function TimeGridInner<T>({
1668
2292
  <TimetablePage
1669
2293
  mode={mode}
1670
2294
  numberOfDays={numberOfDays}
2295
+ hiddenDays={hiddenDays}
2296
+ now={now}
2297
+ nowTimeZone={timeZone}
1671
2298
  date={item}
1672
2299
  width={containerWidth}
1673
2300
  events={events}
@@ -1687,11 +2314,13 @@ function TimeGridInner<T>({
1687
2314
  timeslots={timeslots}
1688
2315
  isRTL={isRTL}
1689
2316
  showAllDayEventCell={showAllDayEventCell}
2317
+ highlightWeekends={highlightWeekends}
1690
2318
  showVerticalScrollIndicator={showVerticalScrollIndicator}
1691
2319
  verticalScrollEnabled={verticalScrollEnabled}
1692
2320
  hourComponent={hourComponent}
1693
2321
  calendarCellStyle={calendarCellStyle}
1694
2322
  businessHours={businessHours}
2323
+ renderBusinessHours={renderBusinessHours}
1695
2324
  minHourHeight={minHourHeight}
1696
2325
  maxHourHeight={maxHourHeight}
1697
2326
  showNowIndicator={showNowIndicator}
@@ -1699,6 +2328,8 @@ function TimeGridInner<T>({
1699
2328
  keyExtractor={keyExtractor}
1700
2329
  snapMinutes={Math.max(1, dragStepMinutes)}
1701
2330
  showDragHandle={showDragHandle}
2331
+ eventStartEditable={eventStartEditable}
2332
+ eventDurationEditable={eventDurationEditable}
1702
2333
  onPressEvent={onPressEvent}
1703
2334
  onLongPressEvent={onLongPressEvent}
1704
2335
  onDragEvent={onDragEvent}
@@ -1706,12 +2337,15 @@ function TimeGridInner<T>({
1706
2337
  onPressCell={handlePressCell}
1707
2338
  onLongPressCell={onLongPressCell}
1708
2339
  onCreateEvent={onCreateEvent}
2340
+ onEdgeAdvance={goToPage}
2341
+ onGridTop={handleGridTop}
1709
2342
  />
1710
2343
  </View>
1711
2344
  ),
1712
2345
  [
1713
2346
  containerWidth,
1714
2347
  pageHeight,
2348
+ handleGridTop,
1715
2349
  mode,
1716
2350
  numberOfDays,
1717
2351
  events,
@@ -1731,6 +2365,7 @@ function TimeGridInner<T>({
1731
2365
  timeslots,
1732
2366
  isRTL,
1733
2367
  showAllDayEventCell,
2368
+ highlightWeekends,
1734
2369
  showVerticalScrollIndicator,
1735
2370
  verticalScrollEnabled,
1736
2371
  hourComponent,
@@ -1743,6 +2378,8 @@ function TimeGridInner<T>({
1743
2378
  keyExtractor,
1744
2379
  dragStepMinutes,
1745
2380
  showDragHandle,
2381
+ eventStartEditable,
2382
+ eventDurationEditable,
1746
2383
  onPressEvent,
1747
2384
  onLongPressEvent,
1748
2385
  onDragEvent,
@@ -1750,6 +2387,10 @@ function TimeGridInner<T>({
1750
2387
  handlePressCell,
1751
2388
  onLongPressCell,
1752
2389
  onCreateEvent,
2390
+ goToPage,
2391
+ hiddenDays,
2392
+ now,
2393
+ timeZone,
1753
2394
  ],
1754
2395
  );
1755
2396
 
@@ -1762,67 +2403,95 @@ function TimeGridInner<T>({
1762
2403
 
1763
2404
  return (
1764
2405
  <SlotStylesProvider classNames={classNames} styles={styleOverrides}>
1765
- <View ref={containerRef} style={styles.container}>
1766
- {renderHeader ? (
1767
- renderHeader(headerDays)
1768
- ) : (
1769
- <DefaultHeader
1770
- days={headerDays}
1771
- mode={mode}
1772
- width={containerWidth}
1773
- hourColumnWidth={hourColumnWidth}
1774
- showWeekNumber={showWeekNumber}
1775
- weekNumberPrefix={weekNumberPrefix}
1776
- weekdayFormat={weekdayFormat}
1777
- locale={locale}
1778
- activeDate={activeDate}
1779
- onPressDateHeader={onPressDateHeader}
1780
- />
1781
- )}
1782
-
1783
- {headerComponent}
1784
-
1785
- <View
1786
- style={styles.pager}
1787
- onLayout={(event) => {
1788
- setPageHeight(event.nativeEvent.layout.height);
1789
- setContainerWidth(event.nativeEvent.layout.width);
1790
- setMeasured(true);
1791
- }}
1792
- >
1793
- <LegendList
1794
- // Remount only on the seed→measured transition (see `measured`), not on
1795
- // every height change, so a day↔week header-height difference resizes the
1796
- // items in place instead of remounting and blanking the page.
1797
- key={measured ? "grid" : "grid-seed"}
1798
- ref={listRef}
1799
- style={isWeb ? [styles.pagerList, styles.webNoScroll] : styles.pagerList}
1800
- data={pageDates}
1801
- extraData={listExtraData}
1802
- horizontal
1803
- recycleItems={false}
1804
- keyExtractor={keyExtractorList}
1805
- getFixedItemSize={getFixedItemSize}
1806
- // On web LegendList ignores these RN scroll props (it leaks them to the
1807
- // DOM as unknown attributes), so omit them there and disable horizontal
1808
- // scroll via `webNoScroll`; paging is driven by the arrow keys instead.
1809
- // Native: paging makes each swipe hard-stop at the adjacent page, while
1810
- // `freeSwipe` lets momentum carry across pages and snap to a boundary.
1811
- {...(isWeb
1812
- ? null
1813
- : {
1814
- scrollEnabled: swipeEnabled,
1815
- pagingEnabled: !freeSwipe,
1816
- snapToIndices: freeSwipe ? snapToIndices : undefined,
1817
- })}
1818
- initialScrollIndex={activeIndex}
1819
- showsHorizontalScrollIndicator={false}
1820
- viewabilityConfig={PAGE_VIEWABILITY}
1821
- onViewableItemsChanged={handleViewableItemsChanged}
1822
- renderItem={renderItem}
1823
- />
2406
+ <EdgePagingContext.Provider value={edgePaging}>
2407
+ <View ref={containerRef} style={styles.container}>
2408
+ {renderHeader ? (
2409
+ renderHeader(headerDays)
2410
+ ) : (
2411
+ <DefaultHeader
2412
+ days={headerDays}
2413
+ mode={mode}
2414
+ width={containerWidth}
2415
+ hourColumnWidth={hourColumnWidth}
2416
+ showWeekNumber={showWeekNumber}
2417
+ weekNumberPrefix={weekNumberPrefix}
2418
+ weekdayFormat={weekdayFormat}
2419
+ locale={locale}
2420
+ activeDate={activeDate}
2421
+ onPressDateHeader={onPressDateHeader}
2422
+ />
2423
+ )}
2424
+
2425
+ {headerComponent}
2426
+
2427
+ <View
2428
+ ref={pagerRef}
2429
+ style={styles.pager}
2430
+ onLayout={(event) => {
2431
+ setPageHeight(event.nativeEvent.layout.height);
2432
+ setContainerWidth(event.nativeEvent.layout.width);
2433
+ setMeasured(true);
2434
+ // Record the pager's window-space frame for the drag worklets' edge
2435
+ // detection and ghost placement (layout gives parent-relative coords,
2436
+ // not window).
2437
+ pagerRef.current?.measureInWindow((x, y, w) => {
2438
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2439
+ pagerLeft.value = x;
2440
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2441
+ pagerTop.value = y;
2442
+ // eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
2443
+ pagerWidth.value = w;
2444
+ });
2445
+ }}
2446
+ >
2447
+ <LegendList
2448
+ // Remount only on the seed→measured transition (see `measured`), not on
2449
+ // every height change, so a day↔week header-height difference resizes the
2450
+ // items in place instead of remounting and blanking the page.
2451
+ key={measured ? "grid" : "grid-seed"}
2452
+ ref={listRef}
2453
+ style={isWeb ? [styles.pagerList, styles.webNoScroll] : styles.pagerList}
2454
+ data={pageDates}
2455
+ extraData={listExtraData}
2456
+ horizontal
2457
+ recycleItems={false}
2458
+ keyExtractor={keyExtractorList}
2459
+ getFixedItemSize={getFixedItemSize}
2460
+ // On web LegendList ignores these RN scroll props (it leaks them to the
2461
+ // DOM as unknown attributes), so omit them there and disable horizontal
2462
+ // scroll via `webNoScroll`; paging is driven by the arrow keys instead.
2463
+ // Native: paging makes each swipe hard-stop at the adjacent page, while
2464
+ // `freeSwipe` lets momentum carry across pages and snap to a boundary.
2465
+ {...(isWeb
2466
+ ? null
2467
+ : {
2468
+ // Frozen mid-edge-page so the programmatic advance lands under
2469
+ // the held finger instead of waiting for the touch to end.
2470
+ scrollEnabled: swipeEnabled && !edgePagingLock,
2471
+ pagingEnabled: !freeSwipe,
2472
+ snapToIndices: freeSwipe ? snapToIndices : undefined,
2473
+ })}
2474
+ initialScrollIndex={activeIndex}
2475
+ showsHorizontalScrollIndicator={false}
2476
+ viewabilityConfig={PAGE_VIEWABILITY}
2477
+ onViewableItemsChanged={handleViewableItemsChanged}
2478
+ renderItem={renderItem}
2479
+ />
2480
+ {liftedEvent ? (
2481
+ <DragGhost
2482
+ x={ghostX}
2483
+ y={ghostY}
2484
+ w={ghostW}
2485
+ h={ghostH}
2486
+ visible={ghostVisible}
2487
+ event={liftedEvent}
2488
+ mode={mode}
2489
+ renderEvent={labeledRenderEvent}
2490
+ />
2491
+ ) : null}
2492
+ </View>
1824
2493
  </View>
1825
- </View>
2494
+ </EdgePagingContext.Provider>
1826
2495
  </SlotStylesProvider>
1827
2496
  );
1828
2497
  }
@@ -2104,6 +2773,15 @@ const styles = StyleSheet.create({
2104
2773
  alignItems: "center",
2105
2774
  justifyContent: "center",
2106
2775
  },
2776
+ resizeHandleTop: {
2777
+ position: "absolute",
2778
+ left: 0,
2779
+ right: 0,
2780
+ top: 0,
2781
+ height: RESIZE_HANDLE_HEIGHT,
2782
+ alignItems: "center",
2783
+ justifyContent: "center",
2784
+ },
2107
2785
  resizeGrip: {
2108
2786
  width: 24,
2109
2787
  height: 3,
@@ -2117,6 +2795,13 @@ const styles = StyleSheet.create({
2117
2795
  // giving a small gap without touching the slot geometry above.
2118
2796
  padding: EVENT_GAP,
2119
2797
  },
2798
+ // The cross-week drag ghost: pinned to the pager's top-left, moved into place by
2799
+ // its transform, and floated above every page so it stays visible across a page.
2800
+ dragGhost: {
2801
+ top: 0,
2802
+ left: 0,
2803
+ zIndex: DRAG_EVENT_Z + 1,
2804
+ },
2120
2805
  nowIndicator: {
2121
2806
  position: "absolute",
2122
2807
  height: 2,