@super-calendar/native 2.8.2 → 2.9.1

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,10 +1,11 @@
1
1
  import { format, type Locale, isSameMonth, startOfDay } from "date-fns";
2
- import { memo, type ReactElement, useMemo, useState } from "react";
2
+ import { memo, type ReactElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import {
4
4
  type DimensionValue,
5
5
  type LayoutChangeEvent,
6
6
  Modal,
7
7
  Platform,
8
+ type PointerEvent as RNPointerEvent,
8
9
  Pressable,
9
10
  ScrollView,
10
11
  StyleSheet,
@@ -15,12 +16,20 @@ import {
15
16
  View,
16
17
  type ViewStyle,
17
18
  } from "react-native";
19
+ import { Gesture, GestureDetector } from "react-native-gesture-handler";
18
20
 
19
21
  // Web drag-to-select relays cell pointer events up to MonthList; native drag is
20
22
  // driven by a list-level pan there instead.
21
23
  const isWeb = Platform.OS === "web";
22
24
  import { useCalendarTheme } from "../theme";
23
- import type { CalendarEvent, EventKeyExtractor, RenderEvent, WeekStartsOn } from "../types";
25
+ import type {
26
+ CalendarEvent,
27
+ EventDragHandler,
28
+ EventDragStartHandler,
29
+ EventKeyExtractor,
30
+ RenderEvent,
31
+ WeekStartsOn,
32
+ } from "../types";
24
33
  import { createSlots, type SlotStyleProps } from "../utils/slots";
25
34
  import { withEventAccessibilityLabel } from "../utils/withEventAccessibilityLabel";
26
35
  import {
@@ -28,6 +37,7 @@ import {
28
37
  type EventAccessibilityLabeler,
29
38
  type WeekdayFormat,
30
39
  daySelectionState,
40
+ isDateSelectable,
31
41
  useCalendarSelection,
32
42
  weekdayFormatToken,
33
43
  } from "@super-calendar/core";
@@ -42,6 +52,7 @@ import {
42
52
  } from "@super-calendar/core";
43
53
  import { monthEventCapacity, monthVisibleCount } from "@super-calendar/core";
44
54
  import { layoutMonthWeek, type MonthWeekEvents } from "@super-calendar/core";
55
+ import { monthCreateRange, monthDropBounds, overlapsOtherEvents } from "@super-calendar/core";
45
56
  import {
46
57
  compareDayEvents,
47
58
  groupEventsByDay,
@@ -65,6 +76,12 @@ const EMPTY_LAYOUT = { segments: [], laneCount: 0 } as const;
65
76
  const CHIP_INSET_H = 4;
66
77
  // Pre-measure fallback so the first paint isn't empty or overflowing.
67
78
  const FALLBACK_VISIBLE_COUNT = 3;
79
+ // Hold this long to start a month drag. Shorter than TouchableOpacity's own
80
+ // 500ms long-press so the pan wins the race and the cell's `onLongPressDay`
81
+ // doesn't also fire.
82
+ const DRAG_LONG_PRESS_MS = 400;
83
+ // Opacity of an event bar while it is being dragged to another day.
84
+ const DRAGGED_BAR_OPACITY = 0.4;
68
85
 
69
86
  const numericStyle = (value: number | string | undefined, fallback: number) =>
70
87
  typeof value === "number" ? value : fallback;
@@ -92,6 +109,21 @@ function collectRowEvents<T>(
92
109
 
93
110
  const pct = (n: number): DimensionValue => `${n}%` as DimensionValue;
94
111
 
112
+ // An in-progress month drag: either a day span being swept out for a new event,
113
+ // or an existing event being carried to another day.
114
+ type MonthDrag<T> =
115
+ | { kind: "create"; anchor: Date; hover: Date }
116
+ | { kind: "move"; event: CalendarEvent<T>; from: Date; to: Date };
117
+
118
+ // True when `day` falls inside the span swept out so far (either direction).
119
+ function isInCreateSpan<T>(drag: MonthDrag<T> | null, day: Date): boolean {
120
+ if (drag?.kind !== "create") return false;
121
+ const time = startOfDay(day).getTime();
122
+ const a = startOfDay(drag.anchor).getTime();
123
+ const b = startOfDay(drag.hover).getTime();
124
+ return time >= Math.min(a, b) && time <= Math.max(a, b);
125
+ }
126
+
95
127
  /**
96
128
  * The styleable parts of {@link MonthView}. Mirrors the dom renderer's slot
97
129
  * names where the structure matches; `dayBadgeText` is native-only (React
@@ -182,9 +214,47 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
182
214
  keyExtractor: EventKeyExtractor<T>;
183
215
  onPressDay?: (date: Date) => void;
184
216
  onLongPressDay?: (date: Date) => void;
217
+ /**
218
+ * Tap an empty day cell. Fires alongside `onPressDay` with the same day at
219
+ * midnight, so one handler can create events across month and week/day modes.
220
+ */
221
+ onPressCell?: (date: Date) => void;
185
222
  onPressEvent: (event: CalendarEvent<T>) => void;
186
223
  onLongPressEvent?: (event: CalendarEvent<T>) => void;
187
224
  onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
225
+ /**
226
+ * Enable drag-to-create: **long-press an empty day** and sweep across others
227
+ * (**press and drag** on the web), then release to fire this with the **all-day**
228
+ * range — `start` at midnight of the first day, `end` at midnight after the last
229
+ * (exclusive). A sweep that never leaves its day still yields that one day. A
230
+ * plain tap fires `onPressDay`/`onPressCell` instead.
231
+ */
232
+ onCreateEvent?: (start: Date, end: Date) => void;
233
+ /**
234
+ * Reports the day span of a create sweep **as it happens**, as the ordered
235
+ * inclusive `[start, end]` days (both at midnight), so a selection highlight can
236
+ * follow the drag instead of appearing only on release. Pair it with
237
+ * `useDateRange`'s `selectRange` to drive `selectedRange`. Enables the sweep on
238
+ * its own, so it works without `onCreateEvent`.
239
+ */
240
+ onSelectDrag?: (start: Date, end: Date) => void;
241
+ /**
242
+ * Enable drag-to-reschedule: **long-press an event bar** and drag it onto
243
+ * another day (**press and drag** on the web). Called on release with the event
244
+ * and its new `start`/`end`, both shifted by the whole days dragged, so the time
245
+ * of day and duration are preserved. Return `false` to reject the drop. Update
246
+ * your own event state in response.
247
+ */
248
+ onDragEvent?: EventDragHandler<T>;
249
+ /**
250
+ * Fired the instant an event is picked up for a month drag, before anything is
251
+ * committed. Use it for haptic feedback. Inert unless `onDragEvent` is also set.
252
+ */
253
+ onDragStart?: EventDragStartHandler<T>;
254
+ /** Allow moving events by default (per-event `startEditable` overrides). Default true. */
255
+ eventStartEditable?: boolean;
256
+ /** Reject a drop that would overlap another event (default true = allowed). */
257
+ eventOverlap?: boolean;
188
258
  /**
189
259
  * Replace the default date badge in each day cell. Receives the day; return
190
260
  * your own date label. Event chips and the "+N more" label still render below.
@@ -222,9 +292,16 @@ function MonthViewInner<T>({
222
292
  keyExtractor,
223
293
  onPressDay,
224
294
  onLongPressDay,
295
+ onPressCell,
225
296
  onPressEvent,
226
297
  onLongPressEvent,
227
298
  onPressMore,
299
+ onCreateEvent,
300
+ onSelectDrag,
301
+ onDragEvent,
302
+ onDragStart,
303
+ eventStartEditable = true,
304
+ eventOverlap = true,
228
305
  renderCustomDateForMonth,
229
306
  onDayPointerDown,
230
307
  onDayPointerEnter,
@@ -246,8 +323,10 @@ function MonthViewInner<T>({
246
323
  () => withEventAccessibilityLabel(renderEvent, eventAccessibilityLabel, false),
247
324
  [renderEvent, eventAccessibilityLabel],
248
325
  );
249
- // Measured grid height, used to auto-fit the event chips per cell.
250
- const [gridHeight, setGridHeight] = useState(0);
326
+ // Measured grid box: the height auto-fits the event chips per cell, and both
327
+ // dimensions map a drag's position onto a day cell.
328
+ const [gridSize, setGridSize] = useState({ width: 0, height: 0 });
329
+ const gridHeight = gridSize.height;
251
330
  // Web-only hover highlight on the day badge (mouse pointers); stays null on
252
331
  // touch/native, so it never re-renders there. Mirrors the dom renderer.
253
332
  const [hoveredKey, setHoveredKey] = useState<string | null>(null);
@@ -326,6 +405,202 @@ function MonthViewInner<T>({
326
405
  [showGrid, weeks, eventsByDay],
327
406
  );
328
407
 
408
+ // ---- drag to create a day span / reschedule an event ----------------------
409
+ const dragEnabled = onCreateEvent != null || onSelectDrag != null || onDragEvent != null;
410
+ const gridRef = useRef<View>(null);
411
+ // The live drag drives the preview; the ref is what the gesture and the web
412
+ // pointer listeners read, so neither has to be rebuilt as the hover day moves
413
+ // (rebuilding the gesture mid-drag would cancel it).
414
+ const [drag, setDrag] = useState<MonthDrag<T> | null>(null);
415
+ const dragRef = useRef<MonthDrag<T> | null>(null);
416
+ // Whether the pointer has reached a different day than it started on. The web
417
+ // has no long-press to disambiguate, so a create only commits once it moves.
418
+ const movedRef = useRef(false);
419
+ // Web only: a committed drag has to swallow the click the browser fires next,
420
+ // so a reschedule doesn't also open the day (or the event) it landed on.
421
+ const suppressPressRef = useRef(false);
422
+
423
+ const applyDrag = useCallback((next: MonthDrag<T> | null) => {
424
+ dragRef.current = next;
425
+ setDrag(next);
426
+ }, []);
427
+
428
+ // True when this press is the click trailing a just-committed web drag, which
429
+ // the caller should swallow. Clears the flag so only that one press is eaten.
430
+ const consumeSuppressedPress = useCallback(() => {
431
+ if (!suppressPressRef.current) return false;
432
+ suppressPressRef.current = false;
433
+ return true;
434
+ }, []);
435
+
436
+ // `disabled` and `draggable: false` lock an event outright; `startEditable`
437
+ // (per event, falling back to the grid default) allows or blocks a move.
438
+ const canMoveEvent = useCallback(
439
+ (event: CalendarEvent<T>) =>
440
+ !event.disabled && event.draggable !== false && (event.startEditable ?? eventStartEditable),
441
+ [eventStartEditable],
442
+ );
443
+
444
+ // The day under a grid-relative point, plus the event bar drawn there (if any).
445
+ // Returns null for a point on a blanked adjacent-month cell or an unselectable
446
+ // day, so neither can be a drag's origin or its drop target.
447
+ const hitTest = useCallback(
448
+ (x: number, y: number): { day: Date; event: CalendarEvent<T> | null } | null => {
449
+ const { width, height } = gridSize;
450
+ if (width <= 0 || height <= 0 || weeks.length === 0) return null;
451
+ const rowHeight = height / weeks.length;
452
+ const row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / rowHeight)));
453
+ const cols = weeks[row].length;
454
+ const col = Math.min(cols - 1, Math.max(0, Math.floor(x / (width / cols))));
455
+ const day = weeks[row][col];
456
+ if (!day) return null;
457
+ if (!showAdjacentMonths && !isSameMonth(day, date)) return null;
458
+ if (!isDateSelectable(day, { minDate, maxDate, isDateDisabled })) return null;
459
+ // Which lane row the point lands on, mirroring the bar overlay's geometry.
460
+ const rowLayout = weekLayouts[row] ?? EMPTY_LAYOUT;
461
+ const lane = Math.floor((y - row * rowHeight - BADGE_AREA) / chipMetrics.chipRowHeight);
462
+ const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
463
+ const segment =
464
+ lane >= 0 && lane < visibleLanes
465
+ ? rowLayout.segments.find((s) => s.lane === lane && s.startCol <= col && s.endCol >= col)
466
+ : undefined;
467
+ return { day, event: segment?.event ?? null };
468
+ },
469
+ [
470
+ gridSize,
471
+ weeks,
472
+ weekLayouts,
473
+ capacity,
474
+ chipMetrics,
475
+ showAdjacentMonths,
476
+ date,
477
+ minDate,
478
+ maxDate,
479
+ isDateDisabled,
480
+ ],
481
+ );
482
+
483
+ const beginDrag = useCallback(
484
+ (x: number, y: number) => {
485
+ // A fresh press starts a new interaction, so any guard left over from the
486
+ // previous one (a drag whose trailing click never reached a cell) is stale.
487
+ suppressPressRef.current = false;
488
+ movedRef.current = false;
489
+ const hit = hitTest(x, y);
490
+ if (!hit) return;
491
+ if (hit.event) {
492
+ if (!onDragEvent || !canMoveEvent(hit.event)) return;
493
+ applyDrag({ kind: "move", event: hit.event, from: hit.day, to: hit.day });
494
+ onDragStart?.(hit.event);
495
+ return;
496
+ }
497
+ if (onCreateEvent || onSelectDrag) {
498
+ applyDrag({ kind: "create", anchor: hit.day, hover: hit.day });
499
+ }
500
+ },
501
+ [hitTest, onDragEvent, onCreateEvent, onSelectDrag, onDragStart, canMoveEvent, applyDrag],
502
+ );
503
+
504
+ const extendDrag = useCallback(
505
+ (x: number, y: number) => {
506
+ const current = dragRef.current;
507
+ if (!current) return;
508
+ const hit = hitTest(x, y);
509
+ if (!hit) return;
510
+ const previous = current.kind === "create" ? current.hover : current.to;
511
+ if (startOfDay(hit.day).getTime() === startOfDay(previous).getTime()) return;
512
+ movedRef.current = true;
513
+ applyDrag(
514
+ current.kind === "create" ? { ...current, hover: hit.day } : { ...current, to: hit.day },
515
+ );
516
+ // A sweep reports its span live, so a selection can track the drag; a move
517
+ // has nothing to report until it is dropped.
518
+ if (current.kind === "create") {
519
+ const a = startOfDay(current.anchor);
520
+ const b = startOfDay(hit.day);
521
+ const [lo, hi] = a.getTime() <= b.getTime() ? [a, b] : [b, a];
522
+ onSelectDrag?.(lo, hi);
523
+ }
524
+ },
525
+ [hitTest, applyDrag, onSelectDrag],
526
+ );
527
+
528
+ const endDrag = useCallback(() => {
529
+ const current = dragRef.current;
530
+ applyDrag(null);
531
+ if (!current) return;
532
+ if (isWeb) suppressPressRef.current = movedRef.current;
533
+ if (current.kind === "create") {
534
+ // A stationary hold is a deliberate one-day create on native, where the
535
+ // gesture only starts after a long press; on the web it is just a click.
536
+ if (isWeb && !movedRef.current) return;
537
+ const range = monthCreateRange(current.anchor, current.hover);
538
+ onCreateEvent?.(range.start, range.end);
539
+ return;
540
+ }
541
+ const next = monthDropBounds(current.event, current.from, current.to);
542
+ if (!next) return;
543
+ // Reject a drop that would land the event on top of another when
544
+ // `eventOverlap` is off, before the consumer's handler ever sees it.
545
+ if (
546
+ eventOverlap === false &&
547
+ overlapsOtherEvents(events, current.event, next.start, next.end)
548
+ ) {
549
+ return;
550
+ }
551
+ onDragEvent?.(current.event, next.start, next.end);
552
+ }, [applyDrag, onCreateEvent, onDragEvent, eventOverlap, events]);
553
+
554
+ // Native: a pan over the grid, held first so it doesn't hijack a tap or the
555
+ // pager's own horizontal swipe.
556
+ const dragGesture = useMemo(() => {
557
+ if (!dragEnabled || isWeb) return undefined;
558
+ return Gesture.Pan()
559
+ .activateAfterLongPress(DRAG_LONG_PRESS_MS)
560
+ .runOnJS(true)
561
+ .onStart((event) => beginDrag(event.x, event.y))
562
+ .onUpdate((event) => extendDrag(event.x, event.y))
563
+ .onEnd((_event, success) => {
564
+ if (success) endDrag();
565
+ })
566
+ .onFinalize(() => {
567
+ if (dragRef.current) applyDrag(null);
568
+ });
569
+ }, [dragEnabled, beginDrag, extendDrag, endDrag, applyDrag]);
570
+
571
+ // Web: the cell touchables swallow the pan above, so drive the same three steps
572
+ // from pointer events on the grid instead. Positions come from the grid's own
573
+ // box, so they line up with the hit test's grid-relative coordinates.
574
+ const gridPoint = useCallback((clientX: number, clientY: number) => {
575
+ const node = gridRef.current as unknown as {
576
+ getBoundingClientRect?: () => { left: number; top: number };
577
+ } | null;
578
+ const rect = node?.getBoundingClientRect?.();
579
+ return rect ? { x: clientX - rect.left, y: clientY - rect.top } : null;
580
+ }, []);
581
+ useEffect(() => {
582
+ if (!isWeb || !dragEnabled) return;
583
+ // A drag can be released anywhere, so commit on the window rather than the grid.
584
+ const up = () => {
585
+ if (dragRef.current) endDrag();
586
+ };
587
+ const target = globalThis as unknown as {
588
+ addEventListener?: (type: string, cb: () => void) => void;
589
+ removeEventListener?: (type: string, cb: () => void) => void;
590
+ };
591
+ target.addEventListener?.("pointerup", up);
592
+ // Let a touch drag sketch a span instead of scrolling the page under it, and
593
+ // stop a sweep from text-selecting the day numbers it passes over.
594
+ const node = gridRef.current as unknown as {
595
+ style?: { touchAction?: string; userSelect?: string };
596
+ } | null;
597
+ if (node?.style) {
598
+ node.style.touchAction = "none";
599
+ node.style.userSelect = "none";
600
+ }
601
+ return () => target.removeEventListener?.("pointerup", up);
602
+ }, [dragEnabled, endDrag]);
603
+
329
604
  const renderDay = (
330
605
  day: Date,
331
606
  dayCol: number,
@@ -381,6 +656,13 @@ function MonthViewInner<T>({
381
656
  const hasBand =
382
657
  rangeBandKind({ isInRange, isRangeStart, isRangeEnd }, fillCellOnSelection) !== "none";
383
658
  const dayKey = day.toISOString();
659
+ // Tint the days a drag is currently over: every day of a create sweep, or the
660
+ // one an event would land on.
661
+ const isDragPreview =
662
+ isInCreateSpan(drag, day) ||
663
+ (drag?.kind === "move" &&
664
+ isSameCalendarDay(day, drag.to) &&
665
+ !isSameCalendarDay(day, drag.from));
384
666
  // A hovered, non-filled day gets the subtle badge highlight on the web, but only
385
667
  // in the events-free picker. The events calendar (month and list views) has no
386
668
  // hover, matching the dom renderer (its events-mode cell omits it).
@@ -396,7 +678,16 @@ function MonthViewInner<T>({
396
678
  : theme.colors.textDisabled;
397
679
 
398
680
  // Disabled days ignore taps; pass the guards through so a press never fires.
399
- const handlePressDay = isDisabled || !onPressDay ? undefined : () => onPressDay(day);
681
+ // `onPressCell` receives the same day at midnight, so one handler covers both
682
+ // the month grid and the week/day grid's empty slots.
683
+ const handlePressDay =
684
+ isDisabled || (!onPressDay && !onPressCell)
685
+ ? undefined
686
+ : () => {
687
+ if (consumeSuppressedPress()) return;
688
+ onPressDay?.(day);
689
+ onPressCell?.(startOfDay(day));
690
+ };
400
691
  const handleLongPressDay =
401
692
  isDisabled || !onLongPressDay ? undefined : () => onLongPressDay(day);
402
693
 
@@ -417,6 +708,9 @@ function MonthViewInner<T>({
417
708
  borderColor: theme.colors.gridLine,
418
709
  },
419
710
  highlightWeekends && isWeekend(day) && { backgroundColor: theme.colors.weekendBackground },
711
+ // The drag preview sits on top of the weekend tint: the span being swept
712
+ // out, or the day an event is about to land on.
713
+ isDragPreview && { backgroundColor: theme.colors.rangeBackground },
420
714
  theme.containers.dayCell,
421
715
  ],
422
716
  });
@@ -441,7 +735,7 @@ function MonthViewInner<T>({
441
735
  })}
442
736
  onPress={handlePressDay}
443
737
  onLongPress={handleLongPressDay}
444
- disabled={isDisabled || (!onPressDay && !onLongPressDay)}
738
+ disabled={isDisabled || (!onPressDay && !onLongPressDay && !onPressCell)}
445
739
  // Web only: track hover for the badge highlight, and (when drag-select is
446
740
  // wired) relay pointer down/enter so MonthList can extend a range as the
447
741
  // pressed pointer sweeps across cells. Native uses a pan, no hover.
@@ -573,8 +867,10 @@ function MonthViewInner<T>({
573
867
  };
574
868
 
575
869
  const handleLayout = (event: LayoutChangeEvent) => {
576
- const next = event.nativeEvent.layout.height;
577
- setGridHeight((prev) => (prev === next ? prev : next));
870
+ const { width, height } = event.nativeEvent.layout;
871
+ setGridSize((prev) =>
872
+ prev.width === width && prev.height === height ? prev : { width, height },
873
+ );
578
874
  };
579
875
 
580
876
  return (
@@ -655,79 +951,122 @@ function MonthViewInner<T>({
655
951
  </Pressable>
656
952
  </Modal>
657
953
  ) : null}
658
- <View {...slot("grid", { base: styles.container })} onLayout={handleLayout}>
659
- {weeks.map((week, weekIndex) => {
660
- // Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
661
- // event is one bar across its columns, stacked into lanes; the bars render
662
- // in an overlay so they can span cells, and the cells reserve the lane rows
663
- // so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
664
- const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
665
- const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
666
- const cols = week.length;
667
- // With adjacent months hidden, clamp bars to the current-month columns so
668
- // none draw over the blank leading/trailing cells.
669
- let firstVisCol = 0;
670
- let lastVisCol = cols - 1;
671
- if (showGrid && !showAdjacentMonths) {
672
- const first = week.findIndex((d) => isSameMonth(d, date));
673
- if (first !== -1) {
674
- firstVisCol = first;
675
- lastVisCol = cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
954
+ <MonthGridSurface gesture={dragGesture}>
955
+ <View
956
+ ref={gridRef}
957
+ testID="month-grid"
958
+ {...slot("grid", { base: styles.container })}
959
+ onLayout={handleLayout}
960
+ {...(isWeb && dragEnabled
961
+ ? {
962
+ onPointerDown: (event: RNPointerEvent) => {
963
+ const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
964
+ if (point) beginDrag(point.x, point.y);
965
+ },
966
+ onPointerMove: (event: RNPointerEvent) => {
967
+ if (!dragRef.current) return;
968
+ const point = gridPoint(event.nativeEvent.clientX, event.nativeEvent.clientY);
969
+ if (point) extendDrag(point.x, point.y);
970
+ },
971
+ }
972
+ : null)}
973
+ >
974
+ {weeks.map((week, weekIndex) => {
975
+ // Spanning bars for this row (laid out once in `weekLayouts`). A multi-day
976
+ // event is one bar across its columns, stacked into lanes; the bars render
977
+ // in an overlay so they can span cells, and the cells reserve the lane rows
978
+ // so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
979
+ const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
980
+ const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
981
+ const cols = week.length;
982
+ // With adjacent months hidden, clamp bars to the current-month columns so
983
+ // none draw over the blank leading/trailing cells.
984
+ let firstVisCol = 0;
985
+ let lastVisCol = cols - 1;
986
+ if (showGrid && !showAdjacentMonths) {
987
+ const first = week.findIndex((d) => isSameMonth(d, date));
988
+ if (first !== -1) {
989
+ firstVisCol = first;
990
+ lastVisCol = cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
991
+ }
676
992
  }
677
- }
678
- return (
679
- <View
680
- {...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
681
- key={week[0].toISOString()}
682
- >
683
- {week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
684
- {showGrid ? (
685
- <View style={[StyleSheet.absoluteFill, { pointerEvents: "box-none" }]}>
686
- {rowLayout.segments
687
- .filter((seg) => seg.lane < visibleLanes)
688
- .map((seg) => {
689
- const startCol = Math.max(seg.startCol, firstVisCol);
690
- const endCol = Math.min(seg.endCol, lastVisCol);
691
- if (startCol > endCol) return null;
692
- return (
693
- <View
694
- key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
695
- style={{
696
- position: "absolute",
697
- left: pct((startCol / cols) * 100),
698
- width: pct(((endCol - startCol + 1) / cols) * 100),
699
- top: BADGE_AREA + seg.lane * chipMetrics.chipRowHeight,
700
- height: chipMetrics.chipHeight,
701
- paddingHorizontal: CHIP_INSET_H,
702
- pointerEvents: "box-none",
703
- }}
704
- >
705
- <RenderEventComponent
706
- event={seg.event}
707
- mode="month"
708
- isAllDay={isAllDayEvent(seg.event)}
709
- onPress={
710
- disableMonthEventCellPress ? () => {} : () => onPressEvent(seg.event)
711
- }
712
- onLongPress={
713
- disableMonthEventCellPress || !onLongPressEvent
714
- ? undefined
715
- : () => onLongPressEvent(seg.event)
716
- }
717
- />
718
- </View>
719
- );
720
- })}
721
- </View>
722
- ) : null}
723
- </View>
724
- );
725
- })}
726
- </View>
993
+ return (
994
+ <View
995
+ {...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
996
+ key={week[0].toISOString()}
997
+ >
998
+ {week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
999
+ {showGrid ? (
1000
+ <View style={[StyleSheet.absoluteFill, { pointerEvents: "box-none" }]}>
1001
+ {rowLayout.segments
1002
+ .filter((seg) => seg.lane < visibleLanes)
1003
+ .map((seg) => {
1004
+ const startCol = Math.max(seg.startCol, firstVisCol);
1005
+ const endCol = Math.min(seg.endCol, lastVisCol);
1006
+ if (startCol > endCol) return null;
1007
+ // Fade the bar being carried, so the tinted drop target reads
1008
+ // as where it is going and this as where it came from.
1009
+ const isDragged = drag?.kind === "move" && drag.event === seg.event;
1010
+ return (
1011
+ <View
1012
+ key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
1013
+ style={{
1014
+ position: "absolute",
1015
+ left: pct((startCol / cols) * 100),
1016
+ width: pct(((endCol - startCol + 1) / cols) * 100),
1017
+ top: BADGE_AREA + seg.lane * chipMetrics.chipRowHeight,
1018
+ height: chipMetrics.chipHeight,
1019
+ paddingHorizontal: CHIP_INSET_H,
1020
+ // Let a sweep in progress reach the cells underneath.
1021
+ pointerEvents: drag ? "none" : "box-none",
1022
+ opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
1023
+ }}
1024
+ >
1025
+ <RenderEventComponent
1026
+ event={seg.event}
1027
+ mode="month"
1028
+ isAllDay={isAllDayEvent(seg.event)}
1029
+ onPress={
1030
+ disableMonthEventCellPress
1031
+ ? () => {}
1032
+ : () => {
1033
+ if (consumeSuppressedPress()) return;
1034
+ onPressEvent(seg.event);
1035
+ }
1036
+ }
1037
+ onLongPress={
1038
+ disableMonthEventCellPress || !onLongPressEvent
1039
+ ? undefined
1040
+ : () => onLongPressEvent(seg.event)
1041
+ }
1042
+ />
1043
+ </View>
1044
+ );
1045
+ })}
1046
+ </View>
1047
+ ) : null}
1048
+ </View>
1049
+ );
1050
+ })}
1051
+ </View>
1052
+ </MonthGridSurface>
727
1053
  </View>
728
1054
  );
729
1055
  }
730
1056
 
1057
+ // The grid, wrapped in a GestureDetector only when a month drag is wired up, so
1058
+ // the picker (and any month without drag handlers) mounts no gesture at all.
1059
+ function MonthGridSurface({
1060
+ gesture,
1061
+ children,
1062
+ }: {
1063
+ gesture?: ReturnType<typeof Gesture.Pan>;
1064
+ children: ReactElement;
1065
+ }): ReactElement {
1066
+ if (!gesture) return children;
1067
+ return <GestureDetector gesture={gesture}>{children}</GestureDetector>;
1068
+ }
1069
+
731
1070
  /**
732
1071
  * A single month rendered as a 7-column grid of day cells, each showing its
733
1072
  * event chips with a "+N more" overflow. Render it on its own for a static