@super-calendar/native 2.18.0 → 2.20.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.
@@ -34,11 +34,13 @@ const isWeb = Platform.OS === "web";
34
34
  // React 18 forwards the canonical string; React 19 treats it as a boolean attribute.
35
35
  const webPreviewProps = isWeb ? { "aria-hidden": true, inert: "inert" } : {};
36
36
  import { useCalendarTheme } from "../theme";
37
+ import { MonthCellProbe, MonthGridSpacingProbe, type MonthCellGeometry } from "./MonthCellProbe";
37
38
  import type {
38
39
  CalendarEvent,
39
40
  EventDragHandler,
40
41
  EventDragStartHandler,
41
42
  EventKeyExtractor,
43
+ MonthDateInfo,
42
44
  RenderEvent,
43
45
  WeekStartsOn,
44
46
  } from "../types";
@@ -58,9 +60,8 @@ import {
58
60
  isDateSelectable,
59
61
  useCalendarSelection,
60
62
  weekdayFormatToken,
61
- } from "@super-calendar/core";
62
- import { dayBadgeKind, rangeBandKind } from "@super-calendar/core";
63
- import {
63
+ dayBadgeKind,
64
+ rangeBandKind,
64
65
  buildMonthWeeks,
65
66
  buildMultiWeekGrid,
66
67
  getIsToday,
@@ -69,11 +70,17 @@ import {
69
70
  getWeekDays,
70
71
  isSameCalendarDay,
71
72
  isWeekend,
72
- } from "@super-calendar/core";
73
- import { monthEventCapacity, monthVisibleCount } from "@super-calendar/core";
74
- import { layoutMonthWeek, type MonthWeekEvents } from "@super-calendar/core";
75
- import { monthCreateRange, monthDropBounds, overlapsOtherEvents } from "@super-calendar/core";
76
- import {
73
+ monthEventCapacity,
74
+ monthVisibleCount,
75
+ monthExtraLaneColumns,
76
+ monthVisibleBars,
77
+ keepMonthDraftVisible,
78
+ withDraftEventDays,
79
+ layoutMonthWeek,
80
+ type MonthWeekEvents,
81
+ monthCreateRange,
82
+ monthDropBounds,
83
+ overlapsOtherEvents,
77
84
  compareDayEvents,
78
85
  groupEventsByDay,
79
86
  isAllDayEvent,
@@ -88,6 +95,7 @@ const DATE_BADGE_HEIGHT = 24;
88
95
  const BAND_CENTER_Y = DAY_CELL_PADDING_TOP + DATE_BADGE_HEIGHT / 2;
89
96
  const CELL_ROW_GAP = 2;
90
97
  const CHIP_PADDING_V = 2;
98
+ const MORE_LABEL_MARGIN_TOP = 2;
91
99
  // Stable empty layout for the events-free picker (avoids a fresh object per render).
92
100
  const EMPTY_LAYOUT = { segments: [], laneCount: 0 } as const;
93
101
  // Horizontal inset of a chip within its cell (mirrors `styles.monthEvent`).
@@ -296,10 +304,11 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
296
304
  /** Reject a drop that would overlap another event (default true = allowed). */
297
305
  eventOverlap?: boolean;
298
306
  /**
299
- * Replace the default date badge in each day cell. Receives the day; return
300
- * your own date label. Event chips and the "+N more" label still render below.
307
+ * Replace the default date badge in each day cell. Receives the day and its
308
+ * state (`isCurrentMonth`, `isToday`, `isSelected`, `isDisabled`); return your
309
+ * own date label. Event chips and the "+N more" label still render below.
301
310
  */
302
- renderCustomDateForMonth?: (date: Date) => React.ReactNode;
311
+ renderCustomDateForMonth?: (date: Date, info: MonthDateInfo) => React.ReactNode;
303
312
  };
304
313
 
305
314
  /**
@@ -340,7 +349,7 @@ function DateRowsInner<T>({
340
349
  events,
341
350
  maxVisibleEventCount,
342
351
  chipHeight,
343
- chipGap = CELL_ROW_GAP,
352
+ chipGap: chipGapProp,
344
353
  weekStartsOn,
345
354
  hiddenDays,
346
355
  weekdayFormat = "short",
@@ -387,12 +396,19 @@ function DateRowsInner<T>({
387
396
  }: DateRowsProps<T>): ReactElement {
388
397
  const { date } = source;
389
398
  const multiWeek = source.kind === "multiweek";
399
+ const chipGap = chipGapProp ?? CELL_ROW_GAP;
400
+ const defaultCellSpacing = !multiWeek || !classNames?.day;
401
+ // A custom create preview needs lanes even before the first event exists.
402
+ const createContentEnabled = onCreateEvent != null && RenderCreateGhost != null;
403
+ const showGrid = multiWeek || events.length > 0 || createContentEnabled;
390
404
  const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
391
405
  const showSixWeeks = source.kind === "month" ? source.showSixWeeks : false;
392
406
  const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : undefined;
393
407
  const theme = useCalendarTheme();
394
- const badgeArea = DAY_CELL_PADDING_TOP + DATE_BADGE_HEIGHT + chipGap;
395
- const slot = createSlots<MonthViewSlot>({ classNames, styles: styleOverrides });
408
+ const slot = useMemo(
409
+ () => createSlots<MonthViewSlot>({ classNames, styles: styleOverrides }),
410
+ [classNames, styleOverrides],
411
+ );
396
412
  const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
397
413
  // Selection comes from context (so cached pages still repaint), but explicit
398
414
  // props win for direct/standalone use of MonthView.
@@ -411,6 +427,8 @@ function DateRowsInner<T>({
411
427
  // dimensions map a drag's position onto a day cell.
412
428
  const [gridSize, setGridSize] = useState({ width: 0, height: 0 });
413
429
  const gridHeight = gridSize.height;
430
+ const weekTops = useRef<number[]>([]);
431
+ const [drawnWeek, setDrawnWeek] = useState({ width: 0, height: 0 });
414
432
  // Web-only hover highlight on the day badge (mouse pointers); stays null on
415
433
  // touch/native, so it never re-renders there. Mirrors the dom renderer.
416
434
  const [hoveredKey, setHoveredKey] = useState<string | null>(null);
@@ -453,18 +471,202 @@ function DateRowsInner<T>({
453
471
  return isRTL ? days.reverse() : days;
454
472
  }, [date, weekStartsOn, isRTL, hiddenDays]);
455
473
 
456
- // The built-in chip's height and per-row stride, from the theme's title type.
457
- // Shared by the capacity estimate and the spanning-bar overlay so the bars line
458
- // up exactly with the rows the cells reserve for them.
459
- const chipMetrics = useMemo(() => {
474
+ // The built-in chip's height, from the theme's title type. Shared by the
475
+ // capacity estimate, the cells' lane spacers and the spanning-bar overlay so the
476
+ // bars line up exactly with the rows the cells reserve for them.
477
+ const laneChipHeight = useMemo(() => {
460
478
  const fontSize = numericStyle(theme.text.eventTitle.fontSize, 12);
461
479
  const lineHeight = numericStyle(theme.text.eventTitle.lineHeight, Math.ceil(fontSize * 1.3));
462
- const height = chipHeight ?? lineHeight + CHIP_PADDING_V * 2;
463
- return { chipHeight: height, chipRowHeight: height + chipGap };
464
- }, [theme, chipHeight, chipGap]);
465
- const minimumRowHeight =
466
- badgeArea +
467
- Math.max(1, maxVisibleEventCount ?? FALLBACK_VISIBLE_COUNT) * chipMetrics.chipRowHeight;
480
+ return chipHeight ?? lineHeight + CHIP_PADDING_V * 2;
481
+ }, [theme, chipHeight]);
482
+ // The one-line "+N more" label, resolved once so the cells draw it with the same
483
+ // style the row height is measured from: theme, chip height and `styles.more`.
484
+ const moreSlot = slot<TextStyle>("more", {
485
+ base: [styles.moreLabel, chipHeight != null && { height: chipHeight }],
486
+ themed: [theme.text.more, { color: theme.colors.textMuted }],
487
+ });
488
+ // The label's vertical extent below the last lane, margins included. A hidden
489
+ // copy of the label is measured once laid out (see `moreProbe`), which covers
490
+ // borders, minimum heights and class names; until then, estimate it from the
491
+ // style: margins, then a set height, else one line plus padding.
492
+ const [measuredMoreArea, setMeasuredMoreArea] = useState(0);
493
+ const moreLabelArea =
494
+ measuredMoreArea ||
495
+ (() => {
496
+ const style = StyleSheet.flatten(moreSlot.style) ?? {};
497
+ const edge = (value: unknown) => (typeof value === "number" ? value : 0);
498
+ const margin =
499
+ edge(style.marginTop ?? style.marginVertical ?? style.margin) +
500
+ edge(style.marginBottom ?? style.marginVertical ?? style.margin);
501
+ const padding =
502
+ edge(style.paddingTop ?? style.paddingVertical ?? style.padding) +
503
+ edge(style.paddingBottom ?? style.paddingVertical ?? style.padding);
504
+ const line = numericStyle(
505
+ style.lineHeight,
506
+ Math.ceil(numericStyle(style.fontSize, 11) * 1.3),
507
+ );
508
+ return margin + (typeof style.height === "number" ? style.height : line + padding);
509
+ })();
510
+ // A row draws its date, then each lane with the gap after it, then the label when
511
+ // events overflow. A fixed cap shows all its lanes and the label; the auto-fit
512
+ // capacity gives up lanes for the label but always keeps one.
513
+ // The tallest date (built-in badge or custom) among the shown days, measured as
514
+ // multi-week cells lay out, so a fixed row never clips a date restyled or
515
+ // rendered taller than the 24pt badge. Kept per day and read for the shown days
516
+ // only, so it shrinks when a date does or leaves the view.
517
+ const [daySizes, setDaySizes] = useState<Record<string, { width?: number; dateHeight?: number }>>(
518
+ {},
519
+ );
520
+ const shownDayKeys = useMemo(
521
+ () => new Set(weeks.flat().map((day) => day.toISOString())),
522
+ [weeks],
523
+ );
524
+ const recordDaySize = (dayKey: string, dimension: "width" | "dateHeight", size: number) =>
525
+ setDaySizes((previous) => {
526
+ if (previous[dayKey]?.[dimension] === size) return previous;
527
+ const next: typeof previous = { [dayKey]: { ...previous[dayKey], [dimension]: size } };
528
+ for (const key in previous) {
529
+ if (key !== dayKey && shownDayKeys.has(key)) next[key] = previous[key];
530
+ }
531
+ return next;
532
+ });
533
+ const dateHeight = useMemo(() => {
534
+ if (!multiWeek) return DATE_BADGE_HEIGHT;
535
+ let tallest = DATE_BADGE_HEIGHT;
536
+ for (const key of shownDayKeys) tallest = Math.max(tallest, daySizes[key]?.dateHeight ?? 0);
537
+ return tallest;
538
+ }, [multiWeek, daySizes, shownDayKeys]);
539
+ const dayCellBase = useMemo(
540
+ () => [
541
+ styles.dayCell,
542
+ defaultCellSpacing && styles.dayCellPadding,
543
+ (defaultCellSpacing || chipGapProp != null) && { gap: chipGap },
544
+ showGrid && styles.dayCellEvents,
545
+ ],
546
+ [defaultCellSpacing, chipGapProp, chipGap, showGrid],
547
+ );
548
+ const dayCellLines = useMemo(
549
+ () =>
550
+ showGrid && {
551
+ borderTopWidth: StyleSheet.hairlineWidth,
552
+ borderRightWidth: StyleSheet.hairlineWidth,
553
+ borderColor: theme.colors.gridLine,
554
+ },
555
+ [showGrid, theme.colors.gridLine],
556
+ );
557
+ const probeDay = useMemo(
558
+ () => slot("day", { base: dayCellBase, themed: [dayCellLines, theme.containers.dayCell] }),
559
+ [slot, dayCellBase, dayCellLines, theme.containers.dayCell],
560
+ );
561
+ const probeWeek = useMemo(
562
+ () => slot("week", { base: styles.weekRowFixed, themed: theme.containers.weekRow }),
563
+ [slot, theme.containers.weekRow],
564
+ );
565
+ const cellStyles = useMemo(() => {
566
+ const probes = new Map<string, { style: StyleProp<ViewStyle>; width: number }>();
567
+ const byDay = new Map<string, string>();
568
+ if (multiWeek) {
569
+ const ids = new Map<StyleProp<ViewStyle>, string>();
570
+ for (const week of weeks) {
571
+ for (const day of week) {
572
+ const dayKey = day.toISOString();
573
+ const style = calendarCellStyle?.(day) ?? undefined;
574
+ const styleId = ids.get(style) ?? (style ? dayKey : "default");
575
+ ids.set(style, styleId);
576
+ const width = daySizes[dayKey]?.width ?? 0;
577
+ const id = `${styleId}:${width}`;
578
+ probes.set(id, { style, width });
579
+ byDay.set(dayKey, id);
580
+ }
581
+ }
582
+ }
583
+ return { probes, byDay };
584
+ }, [multiWeek, weeks, calendarCellStyle, daySizes]);
585
+ const [measuredCells, setMeasuredCells] = useState<Record<string, MonthCellGeometry>>({});
586
+ const recordCell = useCallback(
587
+ (id: string, measured: MonthCellGeometry) => {
588
+ setMeasuredCells((previous) => {
589
+ const old = previous[id];
590
+ if (
591
+ old &&
592
+ old.minimumHeight === measured.minimumHeight &&
593
+ old.top === measured.top &&
594
+ old.bottom === measured.bottom &&
595
+ old.gap === measured.gap &&
596
+ old.overlayTop === measured.overlayTop &&
597
+ old.weekMargin === measured.weekMargin &&
598
+ old.weekMarginTop === measured.weekMarginTop
599
+ )
600
+ return previous;
601
+ const next: Record<string, MonthCellGeometry> = { [id]: measured };
602
+ for (const key of cellStyles.probes.keys()) {
603
+ if (key !== id && previous[key]) next[key] = previous[key];
604
+ }
605
+ return next;
606
+ });
607
+ },
608
+ [cellStyles],
609
+ );
610
+ const estimatedCell = useMemo(
611
+ () => ({
612
+ minimumHeight: 0,
613
+ top: defaultCellSpacing
614
+ ? DAY_CELL_PADDING_TOP + (multiWeek ? StyleSheet.hairlineWidth : 0)
615
+ : 0,
616
+ bottom: 0,
617
+ gap: defaultCellSpacing ? chipGap : (chipGapProp ?? 0),
618
+ overlayTop: 0,
619
+ weekMargin: 0,
620
+ weekMarginTop: 0,
621
+ }),
622
+ [multiWeek, defaultCellSpacing, chipGap, chipGapProp],
623
+ );
624
+ const cellGeometry = useMemo(() => {
625
+ let common: MonthCellGeometry | undefined;
626
+ for (const id of cellStyles.probes.keys()) {
627
+ const cell = measuredCells[id] ?? estimatedCell;
628
+ if (!common) common = { ...cell };
629
+ else {
630
+ common.minimumHeight = Math.max(common.minimumHeight, cell.minimumHeight);
631
+ common.top = Math.max(common.top, cell.top);
632
+ common.bottom = Math.max(common.bottom, cell.bottom);
633
+ common.gap = Math.max(common.gap, cell.gap);
634
+ }
635
+ }
636
+ return common ?? estimatedCell;
637
+ }, [cellStyles, measuredCells, estimatedCell]);
638
+ // Hit testing uses the top of the row including its margin. The overlay
639
+ // positions bars from inside the row's border instead.
640
+ const dateArea = cellGeometry.top + dateHeight;
641
+ const cellLaneHeight = laneChipHeight + cellGeometry.gap;
642
+ const laneTop = dateArea + cellGeometry.gap;
643
+ const barTop = laneTop - cellGeometry.overlayTop;
644
+ const contentHeight =
645
+ dateArea +
646
+ cellGeometry.gap +
647
+ cellGeometry.bottom +
648
+ (maxVisibleEventCount != null
649
+ ? Math.max(1, maxVisibleEventCount) * cellLaneHeight + moreLabelArea
650
+ : Math.max(FALLBACK_VISIBLE_COUNT * cellLaneHeight, cellLaneHeight + moreLabelArea));
651
+ const minimumRowHeight = Math.max(contentHeight, cellGeometry.minimumHeight);
652
+ // In a scroll view, rows with an automatic basis can grow with their events.
653
+ // Start each week at the same height and let the grid share the available space.
654
+ const [viewportHeight, setViewportHeight] = useState(0);
655
+ const gridProbe = useMemo(
656
+ () => (multiWeek && (classNames?.grid || styleOverrides?.grid) ? slot("grid") : null),
657
+ [multiWeek, classNames?.grid, styleOverrides?.grid, slot],
658
+ );
659
+ const [gridInnerSpacing, setGridInnerSpacing] = useState(0);
660
+ const [gridOuterSpacing, setGridOuterSpacing] = useState(0);
661
+ const heightForWeeks = viewportHeight - (gridProbe ? gridOuterSpacing : 0);
662
+ const multiWeekRowHeight =
663
+ multiWeek && viewportHeight > 0
664
+ ? Math.max(minimumRowHeight, heightForWeeks / weeks.length) - cellGeometry.weekMargin
665
+ : undefined;
666
+ const rowHeight =
667
+ multiWeek && drawnWeek.height > 0
668
+ ? drawnWeek.height + cellGeometry.weekMargin
669
+ : gridHeight / weeks.length;
468
670
 
469
671
  // How many chips fit per cell: a fixed cap when `maxVisibleEventCount` is set,
470
672
  // else derived from the measured cell height and the (default) chip metrics.
@@ -475,12 +677,35 @@ function DateRowsInner<T>({
475
677
  if (gridHeight <= 0 || weeks.length === 0) {
476
678
  return { full: FALLBACK_VISIBLE_COUNT, withMore: FALLBACK_VISIBLE_COUNT };
477
679
  }
478
- const rowHeight = gridHeight / weeks.length;
479
- const moreFontSize = numericStyle(theme.text.more.fontSize, 11);
480
- const moreRowHeight = (chipHeight ?? Math.ceil(moreFontSize * 1.3)) + chipGap;
481
- const available = rowHeight - DAY_CELL_PADDING_TOP - DATE_BADGE_HEIGHT;
482
- return monthEventCapacity(available, chipMetrics.chipRowHeight, moreRowHeight);
483
- }, [maxVisibleEventCount, gridHeight, weeks.length, theme, chipMetrics, chipHeight, chipGap]);
680
+ // Lanes start below the date (the built-in badge, or a taller custom date) and
681
+ // end above the cell's bottom inset.
682
+ const available = rowHeight - dateArea - cellGeometry.bottom;
683
+ return monthEventCapacity(available, cellLaneHeight, moreLabelArea + cellGeometry.gap);
684
+ }, [
685
+ maxVisibleEventCount,
686
+ gridHeight,
687
+ weeks.length,
688
+ rowHeight,
689
+ dateArea,
690
+ cellGeometry,
691
+ cellLaneHeight,
692
+ moreLabelArea,
693
+ ]);
694
+
695
+ // The lanes a week row shows. When the auto-fit capacity leaves room for one lane
696
+ // more than the row shows, a day whose only hidden event sits on that lane draws
697
+ // it in place of a "+1 more" label (see monthExtraLaneColumns).
698
+ const rowLanes = useCallback(
699
+ (rowLayout: MonthWeekEvents<T>, columns: number) => {
700
+ const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
701
+ const extraLane =
702
+ capacity.full > visibleLanes
703
+ ? monthExtraLaneColumns(rowLayout, visibleLanes, columns)
704
+ : Array.from({ length: columns }, () => false);
705
+ return { visibleLanes, extraLane };
706
+ },
707
+ [capacity],
708
+ );
484
709
 
485
710
  // Group events by calendar day once per `events` change (shared with the dom
486
711
  // renderer via core's `groupEventsByDay`), rather than scanning the whole list
@@ -496,11 +721,6 @@ function DateRowsInner<T>({
496
721
  return map;
497
722
  }, [events, sortedMonthView]);
498
723
 
499
- // Custom drafts need event lanes before the first event exists. Keep the
500
- // events-free picker layout when no creation content is requested.
501
- const createContentEnabled = onCreateEvent != null && RenderCreateGhost != null;
502
- const showGrid = multiWeek || events.length > 0 || createContentEnabled;
503
-
504
724
  // Lay out each week row's spanning bars once per data change, not per render.
505
725
  const weekLayouts = useMemo(
506
726
  () =>
@@ -526,6 +746,38 @@ function DateRowsInner<T>({
526
746
  : null,
527
747
  [createContentEnabled, drag],
528
748
  );
749
+ // While a create sweep draws its content, lay the rows it covers out with the
750
+ // draft as an all-day event, so it takes the lane the created event will land on
751
+ // and the other bars move aside the same way.
752
+ const draftEvent = useMemo(
753
+ () =>
754
+ createRange
755
+ ? ({
756
+ title: "",
757
+ start: createRange.start,
758
+ end: createRange.end,
759
+ allDay: true,
760
+ } as CalendarEvent<T>)
761
+ : null,
762
+ [createRange],
763
+ );
764
+ const rowLayouts = useMemo(() => {
765
+ if (!draftEvent) return weekLayouts;
766
+ const days = withDraftEventDays(eventsByDay, draftEvent, sortedMonthView);
767
+ return weeks.map((week, index) => {
768
+ const base = weekLayouts[index] ?? EMPTY_LAYOUT;
769
+ if (!week.some((day) => day >= draftEvent.start && day < draftEvent.end)) return base;
770
+ return keepMonthDraftVisible(
771
+ layoutMonthWeek(week, collectRowEvents(week, days)),
772
+ base,
773
+ draftEvent,
774
+ {
775
+ visibleLanes: (laneCount) => monthVisibleCount(laneCount, capacity),
776
+ extraLaneFits: (visibleLanes) => capacity.full > visibleLanes,
777
+ },
778
+ );
779
+ });
780
+ }, [draftEvent, weekLayouts, eventsByDay, sortedMonthView, weeks, capacity]);
529
781
  const dragRef = useRef<MonthDrag<T> | null>(null);
530
782
  const interactionWindow = useRef(windowKey);
531
783
  interactionWindow.current = windowKey;
@@ -608,8 +860,26 @@ function DateRowsInner<T>({
608
860
  (x: number, y: number): { day: Date; event: CalendarEvent<T> | null } | null => {
609
861
  const { width, height } = gridSize;
610
862
  if (width <= 0 || height <= 0 || weeks.length === 0) return null;
611
- const rowHeight = height / weeks.length;
612
- const row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / rowHeight)));
863
+ let row = Math.min(weeks.length - 1, Math.max(0, Math.floor(y / rowHeight)));
864
+ let rowTop = row * rowHeight;
865
+ if (multiWeek) {
866
+ // A styled grid can have padding, space between weeks, or overflowing rows.
867
+ // Web layout notifications can miss a move that does not resize the row.
868
+ const grid =
869
+ isWeb && typeof Element !== "undefined" && gridRef.current instanceof Element
870
+ ? gridRef.current
871
+ : null;
872
+ const gridTop = grid?.getBoundingClientRect().top ?? 0;
873
+ const topOf = (index: number) => {
874
+ const node = grid?.children[index];
875
+ const borderTop = node
876
+ ? node.getBoundingClientRect().top - gridTop
877
+ : weekTops.current[index];
878
+ return borderTop == null ? index * rowHeight : borderTop - cellGeometry.weekMarginTop;
879
+ };
880
+ row = weekAtOffset(y, weeks.length, topOf);
881
+ rowTop = topOf(row);
882
+ }
613
883
  const cols = weeks[row].length;
614
884
  const col = Math.min(cols - 1, Math.max(0, Math.floor(x / (width / cols))));
615
885
  const day = weeks[row][col];
@@ -618,10 +888,12 @@ function DateRowsInner<T>({
618
888
  if (!isDateSelectable(day, { minDate, maxDate, isDateDisabled })) return null;
619
889
  // Which lane row the point lands on, mirroring the bar overlay's geometry.
620
890
  const rowLayout = weekLayouts[row] ?? EMPTY_LAYOUT;
621
- const lane = Math.floor((y - row * rowHeight - badgeArea) / chipMetrics.chipRowHeight);
622
- const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
891
+ const laneOffset = y - rowTop - laneTop;
892
+ const lane = Math.floor(laneOffset / cellLaneHeight);
893
+ const insideBar = !multiWeek || laneOffset - lane * cellLaneHeight < laneChipHeight;
894
+ const { visibleLanes, extraLane } = rowLanes(rowLayout, cols);
623
895
  const segment =
624
- lane >= 0 && lane < visibleLanes
896
+ insideBar && lane >= 0 && lane < visibleLanes + (extraLane[col] ? 1 : 0)
625
897
  ? rowLayout.segments.find((s) => s.lane === lane && s.startCol <= col && s.endCol >= col)
626
898
  : undefined;
627
899
  return { day, event: segment?.event ?? null };
@@ -630,9 +902,13 @@ function DateRowsInner<T>({
630
902
  gridSize,
631
903
  weeks,
632
904
  weekLayouts,
633
- capacity,
634
- chipMetrics,
635
- badgeArea,
905
+ rowLanes,
906
+ multiWeek,
907
+ rowHeight,
908
+ cellGeometry.weekMarginTop,
909
+ laneChipHeight,
910
+ laneTop,
911
+ cellLaneHeight,
636
912
  showAdjacentMonths,
637
913
  date,
638
914
  minDate,
@@ -833,7 +1109,7 @@ function DateRowsInner<T>({
833
1109
  day: Date,
834
1110
  dayCol: number,
835
1111
  rowLayout: MonthWeekEvents<T>,
836
- visibleLanes: number,
1112
+ dayLanes: number,
837
1113
  ) => {
838
1114
  const isCurrentMonth = multiWeek || isSameMonth(day, date);
839
1115
 
@@ -843,7 +1119,7 @@ function DateRowsInner<T>({
843
1119
  <View
844
1120
  key={day.toISOString()}
845
1121
  {...slot("day", {
846
- base: [styles.dayCell, { gap: chipGap }],
1122
+ base: [styles.dayCell, styles.dayCellPadding, { gap: chipGap }],
847
1123
  themed: [
848
1124
  showGrid && {
849
1125
  borderTopWidth: StyleSheet.hairlineWidth,
@@ -873,7 +1149,13 @@ function DateRowsInner<T>({
873
1149
  // Events past the visible lanes (this day's segments the row can't show)
874
1150
  // collapse into "+N more"; the popover still lists the whole day.
875
1151
  const hiddenEvents = rowLayout.segments
876
- .filter((s) => s.startCol <= dayCol && s.endCol >= dayCol && s.lane >= visibleLanes)
1152
+ .filter(
1153
+ (s) =>
1154
+ s.startCol <= dayCol &&
1155
+ s.endCol >= dayCol &&
1156
+ s.lane >= dayLanes &&
1157
+ s.event !== draftEvent,
1158
+ )
877
1159
  .map((s) => s.event);
878
1160
  const hiddenCount = hiddenEvents.length;
879
1161
 
@@ -884,6 +1166,13 @@ function DateRowsInner<T>({
884
1166
  const hasBand =
885
1167
  rangeBandKind({ isInRange, isRangeStart, isRangeEnd }, fillCellOnSelection) !== "none";
886
1168
  const dayKey = day.toISOString();
1169
+ const probeId = cellStyles.byDay.get(dayKey) ?? "default";
1170
+ const cellStyle = multiWeek ? cellStyles.probes.get(probeId)?.style : calendarCellStyle?.(day);
1171
+ const cell = measuredCells[probeId] ?? estimatedCell;
1172
+ // Reserve the common lane stack beneath this date. The next child starts
1173
+ // after the cell's own gap, which may differ from its neighbor's.
1174
+ const dateMargin =
1175
+ laneTop - cell.top - (daySizes[dayKey]?.dateHeight ?? DATE_BADGE_HEIGHT) - cell.gap;
887
1176
  // Tint the days a drag is currently over: every day of a create sweep, or the
888
1177
  // one an event would land on.
889
1178
  const isDragPreview =
@@ -931,17 +1220,49 @@ function DateRowsInner<T>({
931
1220
  labels,
932
1221
  });
933
1222
 
1223
+ const dateElement = renderCustomDateForMonth ? (
1224
+ renderCustomDateForMonth(day, { isCurrentMonth, isToday, isSelected, isDisabled })
1225
+ ) : (
1226
+ <View
1227
+ {...slot("dayBadge", {
1228
+ base: [
1229
+ styles.dateBadge,
1230
+ showGrid && styles.dateBadgeEvents,
1231
+ // Tap feedback lives on the badge, not the cell (picker only);
1232
+ // kept even under a class so the press still reads.
1233
+ !showGrid && pressedKey === dayKey && { opacity: 0.2 },
1234
+ ],
1235
+ themed: [
1236
+ isFilledBadge && {
1237
+ backgroundColor: isHighlighted
1238
+ ? theme.colors.todayBackground
1239
+ : theme.colors.selectedBackground,
1240
+ borderRadius: theme.todayBadgeRadius,
1241
+ },
1242
+ isHovered &&
1243
+ !isFilledBadge && {
1244
+ backgroundColor: theme.colors.hoverBackground,
1245
+ borderRadius: theme.todayBadgeRadius,
1246
+ },
1247
+ theme.containers.dayBadge,
1248
+ ],
1249
+ })}
1250
+ >
1251
+ <Text
1252
+ {...slot<TextStyle>("dayBadgeText", {
1253
+ themed: [theme.text.dateCell, { color: dateColor }],
1254
+ })}
1255
+ allowFontScaling={false}
1256
+ >
1257
+ {format(day, "d")}
1258
+ </Text>
1259
+ </View>
1260
+ );
1261
+
934
1262
  const daySlot = slot("day", {
935
- // Events mode mirrors the dom renderer: left-aligned cell content with
936
- // the date badge in the top-right. The picker (no grid) stays centered
937
- // so the selection range band lines up with the centered badge.
938
- base: [styles.dayCell, { gap: chipGap }, showGrid && styles.dayCellEvents],
1263
+ base: dayCellBase,
939
1264
  themed: [
940
- showGrid && {
941
- borderTopWidth: StyleSheet.hairlineWidth,
942
- borderRightWidth: StyleSheet.hairlineWidth,
943
- borderColor: theme.colors.gridLine,
944
- },
1265
+ dayCellLines,
945
1266
  highlightWeekends && isWeekend(day) && { backgroundColor: theme.colors.weekendBackground },
946
1267
  // The drag preview sits on top of the weekend tint: the span being swept
947
1268
  // out, or the day an event is about to land on.
@@ -954,9 +1275,13 @@ function DateRowsInner<T>({
954
1275
  <TouchableOpacity
955
1276
  key={day.toISOString()}
956
1277
  {...daySlot}
957
- // The consumer's per-date style is an explicit override, so it merges
958
- // after the slot (and survives a `day` class).
959
- style={[daySlot.style, calendarCellStyle?.(day)]}
1278
+ // Multi-week dates stay above the bars even when the day slot uses flex-end.
1279
+ style={[daySlot.style, cellStyle, multiWeek && styles.dayCellStacked]}
1280
+ onLayout={
1281
+ multiWeek
1282
+ ? (event) => recordDaySize(dayKey, "width", event.nativeEvent.layout.width)
1283
+ : undefined
1284
+ }
960
1285
  // In the picker, don't dim the whole cell on press: the tap should show on
961
1286
  // the badge (the circle) only, not the cell background. `onPressIn/Out` drive
962
1287
  // the badge's own opacity below. The events calendar keeps the default
@@ -1032,59 +1357,33 @@ function DateRowsInner<T>({
1032
1357
  })}
1033
1358
  />
1034
1359
  ) : null}
1035
- {renderCustomDateForMonth ? (
1036
- renderCustomDateForMonth(day)
1037
- ) : (
1360
+ {multiWeek ? (
1038
1361
  <View
1039
- {...slot("dayBadge", {
1040
- base: [
1041
- styles.dateBadge,
1042
- showGrid && styles.dateBadgeEvents,
1043
- // Tap feedback lives on the badge, not the cell (picker only);
1044
- // kept even under a class so the press still reads.
1045
- !showGrid && pressedKey === dayKey && { opacity: 0.2 },
1046
- ],
1047
- themed: [
1048
- isFilledBadge && {
1049
- backgroundColor: isHighlighted
1050
- ? theme.colors.todayBackground
1051
- : theme.colors.selectedBackground,
1052
- borderRadius: theme.todayBadgeRadius,
1053
- },
1054
- isHovered &&
1055
- !isFilledBadge && {
1056
- backgroundColor: theme.colors.hoverBackground,
1057
- borderRadius: theme.todayBadgeRadius,
1058
- },
1059
- theme.containers.dayBadge,
1060
- ],
1061
- })}
1362
+ style={[
1363
+ renderCustomDateForMonth ? undefined : styles.dateWrapperStretch,
1364
+ hiddenCount > 0 && {
1365
+ marginBottom: Math.max(0, dateMargin) + dayLanes * cellLaneHeight,
1366
+ },
1367
+ ]}
1368
+ onLayout={(event) =>
1369
+ recordDaySize(dayKey, "dateHeight", event.nativeEvent.layout.height)
1370
+ }
1062
1371
  >
1063
- <Text
1064
- {...slot<TextStyle>("dayBadgeText", {
1065
- themed: [theme.text.dateCell, { color: dateColor }],
1066
- })}
1067
- allowFontScaling={false}
1068
- >
1069
- {format(day, "d")}
1070
- </Text>
1372
+ {dateElement}
1071
1373
  </View>
1374
+ ) : (
1375
+ dateElement
1072
1376
  )}
1073
1377
  {/* Reserve one row per visible lane so the overlay bars have space and
1074
1378
  "+more" sits below them; the bars themselves render in the row overlay
1075
1379
  (they span cells). */}
1076
- {Array.from({ length: visibleLanes }, (_, i) => (
1077
- <View
1078
- key={`lane-${i}`}
1079
- style={{ height: chipMetrics.chipHeight, pointerEvents: "none" }}
1080
- />
1081
- ))}
1380
+ {!multiWeek &&
1381
+ Array.from({ length: dayLanes }, (_, i) => (
1382
+ <View key={`lane-${i}`} style={{ height: laneChipHeight, pointerEvents: "none" }} />
1383
+ ))}
1082
1384
  {hiddenCount > 0 ? (
1083
1385
  <Text
1084
- {...slot<TextStyle>("more", {
1085
- base: [styles.moreLabel, chipHeight != null && { height: chipHeight }],
1086
- themed: [theme.text.more, { color: theme.colors.textMuted }],
1087
- })}
1386
+ {...moreSlot}
1088
1387
  onPress={
1089
1388
  onPressMore
1090
1389
  ? () => onPressMore(dayEvents, day)
@@ -1093,6 +1392,7 @@ function DateRowsInner<T>({
1093
1392
  accessibilityRole="button"
1094
1393
  accessibilityLabel={`${labels.moreEvents(hiddenCount)}, ${format(day, "d MMMM", { locale })}`}
1095
1394
  allowFontScaling={false}
1395
+ numberOfLines={1}
1096
1396
  >
1097
1397
  {moreLabel.replace("{moreCount}", String(hiddenCount))}
1098
1398
  </Text>
@@ -1111,6 +1411,50 @@ function DateRowsInner<T>({
1111
1411
  return (
1112
1412
  <CalendarLabelsContext.Provider value={labels}>
1113
1413
  <View style={styles.root}>
1414
+ {showGrid ? (
1415
+ <View
1416
+ testID="month-more-probe"
1417
+ style={styles.moreProbe}
1418
+ {...webPreviewProps}
1419
+ pointerEvents="none"
1420
+ accessible={false}
1421
+ accessibilityElementsHidden
1422
+ importantForAccessibility="no-hide-descendants"
1423
+ onLayout={(event) => {
1424
+ const { height } = event.nativeEvent.layout;
1425
+ setMeasuredMoreArea((previous) => (previous === height ? previous : height));
1426
+ }}
1427
+ >
1428
+ <Text {...moreSlot} allowFontScaling={false} numberOfLines={1}>
1429
+ {moreLabel.replace("{moreCount}", "99")}
1430
+ </Text>
1431
+ </View>
1432
+ ) : null}
1433
+ {gridProbe && (
1434
+ <MonthGridSpacingProbe
1435
+ grid={gridProbe}
1436
+ weeks={weeks.length}
1437
+ onInnerHeight={setGridInnerSpacing}
1438
+ onOuterHeight={setGridOuterSpacing}
1439
+ />
1440
+ )}
1441
+ {Array.from(
1442
+ cellStyles.probes,
1443
+ ([id, cell]) =>
1444
+ cell.width > 0 &&
1445
+ drawnWeek.width > 0 && (
1446
+ <MonthCellProbe
1447
+ key={id}
1448
+ id={id}
1449
+ week={probeWeek}
1450
+ day={probeDay}
1451
+ cellStyle={cell.style}
1452
+ dayWidth={cell.width}
1453
+ weekWidth={drawnWeek.width}
1454
+ onMeasure={recordCell}
1455
+ />
1456
+ ),
1457
+ )}
1114
1458
  {showTitle ? (
1115
1459
  <Text
1116
1460
  {...slot<TextStyle>("title", {
@@ -1192,7 +1536,7 @@ function DateRowsInner<T>({
1192
1536
  </Pressable>
1193
1537
  </Modal>
1194
1538
  ) : null}
1195
- <DateRowsViewport scrollable={multiWeek}>
1539
+ <DateRowsViewport scrollable={multiWeek} onHeight={setViewportHeight}>
1196
1540
  <MonthGridSurface gesture={dragGesture}>
1197
1541
  <View
1198
1542
  ref={gridRef}
@@ -1200,8 +1544,10 @@ function DateRowsInner<T>({
1200
1544
  accessibilityLabel={multiWeek ? title : undefined}
1201
1545
  {...slot("grid", {
1202
1546
  base: [
1203
- styles.container,
1204
- multiWeek ? { minHeight: minimumRowHeight * weeks.length } : undefined,
1547
+ !multiWeekRowHeight && styles.container,
1548
+ multiWeek && {
1549
+ minHeight: minimumRowHeight * weeks.length + (gridProbe ? gridInnerSpacing : 0),
1550
+ },
1205
1551
  ],
1206
1552
  })}
1207
1553
  onLayout={handleLayout}
@@ -1222,9 +1568,9 @@ function DateRowsInner<T>({
1222
1568
  // event is one bar across its columns, stacked into lanes; the bars render
1223
1569
  // in an overlay so they can span cells, and the cells reserve the lane rows
1224
1570
  // so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
1225
- const rowLayout = weekLayouts[weekIndex] ?? EMPTY_LAYOUT;
1226
- const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
1571
+ const rowLayout = rowLayouts[weekIndex] ?? EMPTY_LAYOUT;
1227
1572
  const cols = week.length;
1573
+ const { visibleLanes, extraLane } = rowLanes(rowLayout, cols);
1228
1574
  // With adjacent months hidden, clamp bars to the current-month columns so
1229
1575
  // none draw over the blank leading/trailing cells.
1230
1576
  let firstVisCol = 0;
@@ -1237,30 +1583,49 @@ function DateRowsInner<T>({
1237
1583
  cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
1238
1584
  }
1239
1585
  }
1240
- const draftColumns = createRange
1241
- ? week.flatMap((day, index) =>
1242
- (showAdjacentMonths || isSameMonth(day, date)) &&
1243
- day >= createRange.start &&
1244
- day < createRange.end
1245
- ? [index]
1246
- : [],
1247
- )
1248
- : [];
1249
- const draftStart = draftColumns[0];
1250
- const draftEnd = draftColumns.at(-1);
1251
- // Overlay a free lane when possible, without moving cells under the drag.
1252
- const draftLane = Math.min(visibleLanes, Math.max(0, capacity.full - 1));
1253
- const draftTop = badgeArea + draftLane * chipMetrics.chipRowHeight;
1254
- const draftHeight = Math.min(
1255
- chipMetrics.chipHeight,
1256
- Math.max(0, gridHeight / weeks.length - draftTop),
1257
- );
1586
+ // The draft's own lane and columns, clamped like the bars.
1587
+ const draftSegment = rowLayout.segments.find((s) => s.event === draftEvent);
1588
+ const draftStart = draftSegment ? Math.max(draftSegment.startCol, firstVisCol) : -1;
1589
+ const draftEnd = draftSegment ? Math.min(draftSegment.endCol, lastVisCol) : -1;
1590
+ const draftTop = barTop + (draftSegment?.lane ?? 0) * cellLaneHeight;
1591
+ const draftHeight = Math.min(laneChipHeight, Math.max(0, rowHeight - draftTop));
1258
1592
  return (
1259
1593
  <View
1260
- {...slot("week", { base: styles.weekRow, themed: theme.containers.weekRow })}
1594
+ {...slot("week", {
1595
+ // The grid slot can be larger or smaller than the viewport.
1596
+ // Size from the same basis, stopping where the contents fit.
1597
+ base: multiWeekRowHeight
1598
+ ? [
1599
+ styles.weekRowFixed,
1600
+ {
1601
+ height: multiWeekRowHeight,
1602
+ minHeight: minimumRowHeight - cellGeometry.weekMargin,
1603
+ flexGrow: 1,
1604
+ flexShrink: 1,
1605
+ },
1606
+ ]
1607
+ : styles.weekRow,
1608
+ themed: theme.containers.weekRow,
1609
+ })}
1261
1610
  key={multiWeekGrid?.weeks[weekIndex].id ?? week[0].toISOString()}
1611
+ onLayout={
1612
+ multiWeek
1613
+ ? (event) => {
1614
+ const { y, height, width } = event.nativeEvent.layout;
1615
+ weekTops.current[weekIndex] = y;
1616
+ if (weekIndex === 0)
1617
+ setDrawnWeek((previous) =>
1618
+ previous.width === width && previous.height === height
1619
+ ? previous
1620
+ : { width, height },
1621
+ );
1622
+ }
1623
+ : undefined
1624
+ }
1262
1625
  >
1263
- {week.map((day, dayCol) => renderDay(day, dayCol, rowLayout, visibleLanes))}
1626
+ {week.map((day, dayCol) =>
1627
+ renderDay(day, dayCol, rowLayout, visibleLanes + (extraLane[dayCol] ? 1 : 0)),
1628
+ )}
1264
1629
  {showGrid ? (
1265
1630
  <View
1266
1631
  style={[
@@ -1270,8 +1635,8 @@ function DateRowsInner<T>({
1270
1635
  : { pointerEvents: "box-none" },
1271
1636
  ]}
1272
1637
  >
1273
- {rowLayout.segments
1274
- .filter((seg) => seg.lane < visibleLanes)
1638
+ {monthVisibleBars(rowLayout, visibleLanes, extraLane)
1639
+ .filter((seg) => seg.event !== draftEvent)
1275
1640
  .map((seg) => {
1276
1641
  const startCol = Math.max(seg.startCol, firstVisCol);
1277
1642
  const endCol = Math.min(seg.endCol, lastVisCol);
@@ -1281,14 +1646,14 @@ function DateRowsInner<T>({
1281
1646
  const isDragged = drag?.kind === "move" && drag.event === seg.event;
1282
1647
  return (
1283
1648
  <View
1284
- key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}`}
1649
+ key={`bar-${seg.event.start.toISOString()}:${seg.event.title}:${seg.lane}:${seg.startCol}`}
1285
1650
  style={[
1286
1651
  {
1287
1652
  position: "absolute",
1288
1653
  left: pct((startCol / cols) * 100),
1289
1654
  width: pct(((endCol - startCol + 1) / cols) * 100),
1290
- top: badgeArea + seg.lane * chipMetrics.chipRowHeight,
1291
- height: chipMetrics.chipHeight,
1655
+ top: barTop + seg.lane * cellLaneHeight,
1656
+ height: laneChipHeight,
1292
1657
  paddingHorizontal: CHIP_INSET_H,
1293
1658
  // Let a sweep in progress reach the cells underneath.
1294
1659
  opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
@@ -1323,8 +1688,8 @@ function DateRowsInner<T>({
1323
1688
  })}
1324
1689
  {RenderCreateGhost &&
1325
1690
  createRange &&
1326
- draftStart !== undefined &&
1327
- draftEnd !== undefined &&
1691
+ draftStart >= 0 &&
1692
+ draftEnd >= draftStart &&
1328
1693
  draftHeight > 0 ? (
1329
1694
  <View
1330
1695
  testID="month-create-ghost"
@@ -1368,15 +1733,35 @@ function DateRowsInner<T>({
1368
1733
  );
1369
1734
  }
1370
1735
 
1736
+ // Find the last week whose top is at or above the pointer, clamping to the first
1737
+ // or last week when a drag crosses the grid boundary.
1738
+ function weekAtOffset(y: number, count: number, topOf: (index: number) => number): number {
1739
+ let first = 0;
1740
+ let end = count;
1741
+ while (first + 1 < end) {
1742
+ const middle = Math.floor((first + end) / 2);
1743
+ if (topOf(middle) <= y) first = middle;
1744
+ else end = middle;
1745
+ }
1746
+ return first;
1747
+ }
1748
+
1371
1749
  function DateRowsViewport({
1372
1750
  scrollable,
1751
+ onHeight,
1373
1752
  children,
1374
1753
  }: {
1375
1754
  scrollable: boolean;
1755
+ onHeight: (height: number) => void;
1376
1756
  children: ReactElement;
1377
1757
  }): ReactElement {
1378
1758
  return scrollable ? (
1379
- <ScrollView style={styles.container} contentContainerStyle={{ flexGrow: 1 }}>
1759
+ <ScrollView
1760
+ testID="multiweek-viewport"
1761
+ style={styles.multiWeekViewport}
1762
+ contentContainerStyle={{ flexGrow: 1 }}
1763
+ onLayout={(event) => onHeight(event.nativeEvent.layout.height)}
1764
+ >
1380
1765
  {children}
1381
1766
  </ScrollView>
1382
1767
  ) : (
@@ -1422,6 +1807,10 @@ export const MonthView = memo(MonthViewInner) as typeof MonthViewInner;
1422
1807
  export const DateRows = memo(DateRowsInner) as typeof DateRowsInner;
1423
1808
 
1424
1809
  const styles = StyleSheet.create({
1810
+ // Invisible, out of the flow: lays out one "+N more" label to measure its height.
1811
+ moreProbe: { position: "absolute", left: 0, top: 0, opacity: 0 },
1812
+ dateWrapperStretch: { alignSelf: "stretch" },
1813
+ dayCellStacked: { justifyContent: "flex-start", alignSelf: "stretch" },
1425
1814
  root: {
1426
1815
  flex: 1,
1427
1816
  },
@@ -1442,6 +1831,8 @@ const styles = StyleSheet.create({
1442
1831
  container: {
1443
1832
  flex: 1,
1444
1833
  },
1834
+ // A classic scrollbar must not change the column widths that determine the row heights.
1835
+ multiWeekViewport: { flex: 1, ...(isWeb && { scrollbarGutter: "stable" }) },
1445
1836
  // react-native-web needs registered styles to expand the child rules for box-none.
1446
1837
  childrenOnlyPointerEvents: { pointerEvents: "box-none" },
1447
1838
  noPointerEvents: { pointerEvents: "none" },
@@ -1449,13 +1840,16 @@ const styles = StyleSheet.create({
1449
1840
  flex: 1,
1450
1841
  flexDirection: "row",
1451
1842
  },
1843
+ // A multi-week row at a set height: no `flex`, which would override the height.
1844
+ weekRowFixed: {
1845
+ flexDirection: "row",
1846
+ },
1452
1847
  dayCell: {
1453
1848
  flex: 1,
1454
1849
  alignItems: "center",
1455
- paddingTop: 4,
1456
- gap: 2,
1457
1850
  overflow: "hidden",
1458
1851
  },
1852
+ dayCellPadding: { paddingTop: DAY_CELL_PADDING_TOP },
1459
1853
  dayCellEvents: {
1460
1854
  alignItems: "stretch",
1461
1855
  },
@@ -1478,7 +1872,7 @@ const styles = StyleSheet.create({
1478
1872
  marginHorizontal: 4,
1479
1873
  },
1480
1874
  moreLabel: {
1481
- marginTop: 2,
1875
+ marginTop: MORE_LABEL_MARGIN_TOP,
1482
1876
  marginHorizontal: 4,
1483
1877
  },
1484
1878
  // The built-in "+N more" popover card.