@super-calendar/native 2.17.0 → 2.19.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.
- package/README.md +23 -1
- package/dist/{DefaultMonthEvent-C3C30hfV.d.mts → DefaultMonthEvent-DzgQFuVp.d.mts} +47 -10
- package/dist/{DefaultMonthEvent-Dx3lD7ig.d.ts → DefaultMonthEvent-joYl8Tu2.d.ts} +47 -10
- package/dist/{MonthList-N1GVDIE4.mjs → MonthList-BGl1gTDr.mjs} +603 -97
- package/dist/{MonthList-B2TSGYp7.js → MonthList-DeO-x5VW.js} +601 -95
- package/dist/index.d.mts +40 -15
- package/dist/index.d.ts +40 -15
- package/dist/index.js +189 -63
- package/dist/index.mjs +161 -65
- package/dist/picker.d.mts +1 -1
- package/dist/picker.d.ts +1 -1
- package/dist/picker.js +1 -1
- package/dist/picker.mjs +1 -1
- package/package.json +2 -2
- package/src/components/Agenda.tsx +19 -3
- package/src/components/AllDayLane.tsx +64 -37
- package/src/components/Calendar.tsx +104 -30
- package/src/components/MonthCellProbe.tsx +201 -0
- package/src/components/MonthList.tsx +4 -2
- package/src/components/MonthPager.tsx +41 -4
- package/src/components/MonthView.tsx +597 -118
- package/src/components/ResourceTimeline.tsx +11 -2
- package/src/components/TimeGrid.tsx +82 -24
- package/src/components/YearView.tsx +12 -3
- package/src/index.tsx +11 -2
- package/src/types.ts +20 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addDays, format, type Locale, isSameMonth, startOfDay } from "date-fns";
|
|
2
2
|
import {
|
|
3
3
|
type ComponentRef,
|
|
4
|
+
type ComponentType,
|
|
4
5
|
memo,
|
|
5
6
|
type ReactElement,
|
|
6
7
|
useCallback,
|
|
@@ -30,12 +31,16 @@ import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
|
30
31
|
// Web drag-to-select relays cell pointer events up to MonthList; native drag is
|
|
31
32
|
// driven by a list-level pan there instead.
|
|
32
33
|
const isWeb = Platform.OS === "web";
|
|
34
|
+
// React 18 forwards the canonical string; React 19 treats it as a boolean attribute.
|
|
35
|
+
const webPreviewProps = isWeb ? { "aria-hidden": true, inert: "inert" } : {};
|
|
33
36
|
import { useCalendarTheme } from "../theme";
|
|
37
|
+
import { MonthCellProbe, MonthGridSpacingProbe, type MonthCellGeometry } from "./MonthCellProbe";
|
|
34
38
|
import type {
|
|
35
39
|
CalendarEvent,
|
|
36
40
|
EventDragHandler,
|
|
37
41
|
EventDragStartHandler,
|
|
38
42
|
EventKeyExtractor,
|
|
43
|
+
MonthDateInfo,
|
|
39
44
|
RenderEvent,
|
|
40
45
|
WeekStartsOn,
|
|
41
46
|
} from "../types";
|
|
@@ -45,6 +50,7 @@ import { holdWebDateDrag } from "../utils/holdWebDateDrag";
|
|
|
45
50
|
import { CalendarLabelsContext } from "../utils/labels";
|
|
46
51
|
import {
|
|
47
52
|
type CalendarLabels,
|
|
53
|
+
type CreateGhostArgs,
|
|
48
54
|
type DateRange,
|
|
49
55
|
type EventAccessibilityLabeler,
|
|
50
56
|
dayAccessibilityLabel,
|
|
@@ -54,21 +60,27 @@ import {
|
|
|
54
60
|
isDateSelectable,
|
|
55
61
|
useCalendarSelection,
|
|
56
62
|
weekdayFormatToken,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
import {
|
|
63
|
+
dayBadgeKind,
|
|
64
|
+
rangeBandKind,
|
|
60
65
|
buildMonthWeeks,
|
|
61
66
|
buildMultiWeekGrid,
|
|
62
67
|
getIsToday,
|
|
68
|
+
nowInTimeZone,
|
|
63
69
|
filterHiddenDays,
|
|
64
70
|
getWeekDays,
|
|
65
71
|
isSameCalendarDay,
|
|
66
72
|
isWeekend,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
monthEventCapacity,
|
|
74
|
+
monthVisibleCount,
|
|
75
|
+
monthExtraLaneColumns,
|
|
76
|
+
monthVisibleBars,
|
|
77
|
+
keepMonthDraftVisible,
|
|
78
|
+
withDraftEventDays,
|
|
79
|
+
layoutMonthWeek,
|
|
80
|
+
type MonthWeekEvents,
|
|
81
|
+
monthCreateRange,
|
|
82
|
+
monthDropBounds,
|
|
83
|
+
overlapsOtherEvents,
|
|
72
84
|
compareDayEvents,
|
|
73
85
|
groupEventsByDay,
|
|
74
86
|
isAllDayEvent,
|
|
@@ -83,6 +95,7 @@ const DATE_BADGE_HEIGHT = 24;
|
|
|
83
95
|
const BAND_CENTER_Y = DAY_CELL_PADDING_TOP + DATE_BADGE_HEIGHT / 2;
|
|
84
96
|
const CELL_ROW_GAP = 2;
|
|
85
97
|
const CHIP_PADDING_V = 2;
|
|
98
|
+
const MORE_LABEL_MARGIN_TOP = 2;
|
|
86
99
|
// Stable empty layout for the events-free picker (avoids a fresh object per render).
|
|
87
100
|
const EMPTY_LAYOUT = { segments: [], laneCount: 0 } as const;
|
|
88
101
|
// Horizontal inset of a chip within its cell (mirrors `styles.monthEvent`).
|
|
@@ -153,6 +166,7 @@ export type MonthViewSlot =
|
|
|
153
166
|
| "dayBadge"
|
|
154
167
|
| "dayBadgeText"
|
|
155
168
|
| "rangeBand"
|
|
169
|
+
| "createGhost"
|
|
156
170
|
| "more"
|
|
157
171
|
| "morePopover";
|
|
158
172
|
|
|
@@ -180,6 +194,13 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
|
|
|
180
194
|
/** Weekday header label width: `narrow` ("M"), `short` ("Mon", default), or `long` ("Monday"). */
|
|
181
195
|
weekdayFormat?: WeekdayFormat;
|
|
182
196
|
locale?: Locale;
|
|
197
|
+
/**
|
|
198
|
+
* The instant whose calendar day is highlighted as today. Defaults to the
|
|
199
|
+
* device clock, and is read in `timeZone` when one is set.
|
|
200
|
+
*/
|
|
201
|
+
now?: Date;
|
|
202
|
+
/** Highlight today as it is in this IANA time zone (default: the device's). */
|
|
203
|
+
timeZone?: string;
|
|
183
204
|
/** Sort each day's events by start time before slicing. Default true. */
|
|
184
205
|
sortedMonthView?: boolean;
|
|
185
206
|
/** Template for the overflow label; `{moreCount}` is replaced. Default "{moreCount} More". */
|
|
@@ -249,6 +270,14 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
|
|
|
249
270
|
* plain tap fires `onPressDay`/`onPressCell` instead.
|
|
250
271
|
*/
|
|
251
272
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
273
|
+
/**
|
|
274
|
+
* Content inside the drag-to-create preview. Receives the full all-day range,
|
|
275
|
+
* with an exclusive end, that `onCreateEvent` would receive on release. A span
|
|
276
|
+
* crossing rows renders the component once per row with the same range.
|
|
277
|
+
* Requires `onCreateEvent`; content is clipped, noninteractive, and hidden
|
|
278
|
+
* from screen readers. Omit to keep the day highlight without preview content.
|
|
279
|
+
*/
|
|
280
|
+
renderCreateGhost?: ComponentType<CreateGhostArgs>;
|
|
252
281
|
/**
|
|
253
282
|
* Reports the day span of a create sweep **as it happens**, as the ordered
|
|
254
283
|
* inclusive `[start, end]` days (both at midnight), so a selection highlight can
|
|
@@ -275,10 +304,11 @@ export type MonthViewProps<T> = SlotStyleProps<MonthViewSlot> & {
|
|
|
275
304
|
/** Reject a drop that would overlap another event (default true = allowed). */
|
|
276
305
|
eventOverlap?: boolean;
|
|
277
306
|
/**
|
|
278
|
-
* Replace the default date badge in each day cell. Receives the day
|
|
279
|
-
*
|
|
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.
|
|
280
310
|
*/
|
|
281
|
-
renderCustomDateForMonth?: (date: Date) => React.ReactNode;
|
|
311
|
+
renderCustomDateForMonth?: (date: Date, info: MonthDateInfo) => React.ReactNode;
|
|
282
312
|
};
|
|
283
313
|
|
|
284
314
|
/**
|
|
@@ -319,11 +349,13 @@ function DateRowsInner<T>({
|
|
|
319
349
|
events,
|
|
320
350
|
maxVisibleEventCount,
|
|
321
351
|
chipHeight,
|
|
322
|
-
chipGap
|
|
352
|
+
chipGap: chipGapProp,
|
|
323
353
|
weekStartsOn,
|
|
324
354
|
hiddenDays,
|
|
325
355
|
weekdayFormat = "short",
|
|
326
356
|
locale,
|
|
357
|
+
now,
|
|
358
|
+
timeZone,
|
|
327
359
|
sortedMonthView = true,
|
|
328
360
|
moreLabel = "{moreCount} More",
|
|
329
361
|
labels: labelsProp,
|
|
@@ -350,6 +382,7 @@ function DateRowsInner<T>({
|
|
|
350
382
|
onLongPressEvent,
|
|
351
383
|
onPressMore,
|
|
352
384
|
onCreateEvent,
|
|
385
|
+
renderCreateGhost: RenderCreateGhost,
|
|
353
386
|
onSelectDrag,
|
|
354
387
|
onDragEvent,
|
|
355
388
|
onDragStart,
|
|
@@ -363,12 +396,19 @@ function DateRowsInner<T>({
|
|
|
363
396
|
}: DateRowsProps<T>): ReactElement {
|
|
364
397
|
const { date } = source;
|
|
365
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;
|
|
366
404
|
const showAdjacentMonths = source.kind === "month" ? source.showAdjacentMonths : true;
|
|
367
405
|
const showSixWeeks = source.kind === "month" ? source.showSixWeeks : false;
|
|
368
406
|
const numberOfWeeks = source.kind === "multiweek" ? source.numberOfWeeks : undefined;
|
|
369
407
|
const theme = useCalendarTheme();
|
|
370
|
-
const
|
|
371
|
-
|
|
408
|
+
const slot = useMemo(
|
|
409
|
+
() => createSlots<MonthViewSlot>({ classNames, styles: styleOverrides }),
|
|
410
|
+
[classNames, styleOverrides],
|
|
411
|
+
);
|
|
372
412
|
const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
|
|
373
413
|
// Selection comes from context (so cached pages still repaint), but explicit
|
|
374
414
|
// props win for direct/standalone use of MonthView.
|
|
@@ -387,6 +427,8 @@ function DateRowsInner<T>({
|
|
|
387
427
|
// dimensions map a drag's position onto a day cell.
|
|
388
428
|
const [gridSize, setGridSize] = useState({ width: 0, height: 0 });
|
|
389
429
|
const gridHeight = gridSize.height;
|
|
430
|
+
const weekTops = useRef<number[]>([]);
|
|
431
|
+
const [drawnWeek, setDrawnWeek] = useState({ width: 0, height: 0 });
|
|
390
432
|
// Web-only hover highlight on the day badge (mouse pointers); stays null on
|
|
391
433
|
// touch/native, so it never re-renders there. Mirrors the dom renderer.
|
|
392
434
|
const [hoveredKey, setHoveredKey] = useState<string | null>(null);
|
|
@@ -400,6 +442,7 @@ function DateRowsInner<T>({
|
|
|
400
442
|
events: CalendarEvent<T>[];
|
|
401
443
|
} | null>(null);
|
|
402
444
|
|
|
445
|
+
const today = nowInTimeZone(now, timeZone);
|
|
403
446
|
const multiWeekGrid = useMemo(
|
|
404
447
|
() =>
|
|
405
448
|
numberOfWeeks === undefined
|
|
@@ -428,18 +471,202 @@ function DateRowsInner<T>({
|
|
|
428
471
|
return isRTL ? days.reverse() : days;
|
|
429
472
|
}, [date, weekStartsOn, isRTL, hiddenDays]);
|
|
430
473
|
|
|
431
|
-
// The built-in chip's height
|
|
432
|
-
//
|
|
433
|
-
// up exactly with the rows the cells reserve for them.
|
|
434
|
-
const
|
|
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(() => {
|
|
435
478
|
const fontSize = numericStyle(theme.text.eventTitle.fontSize, 12);
|
|
436
479
|
const lineHeight = numericStyle(theme.text.eventTitle.lineHeight, Math.ceil(fontSize * 1.3));
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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;
|
|
443
670
|
|
|
444
671
|
// How many chips fit per cell: a fixed cap when `maxVisibleEventCount` is set,
|
|
445
672
|
// else derived from the measured cell height and the (default) chip metrics.
|
|
@@ -450,12 +677,35 @@ function DateRowsInner<T>({
|
|
|
450
677
|
if (gridHeight <= 0 || weeks.length === 0) {
|
|
451
678
|
return { full: FALLBACK_VISIBLE_COUNT, withMore: FALLBACK_VISIBLE_COUNT };
|
|
452
679
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
+
);
|
|
459
709
|
|
|
460
710
|
// Group events by calendar day once per `events` change (shared with the dom
|
|
461
711
|
// renderer via core's `groupEventsByDay`), rather than scanning the whole list
|
|
@@ -471,10 +721,6 @@ function DateRowsInner<T>({
|
|
|
471
721
|
return map;
|
|
472
722
|
}, [events, sortedMonthView]);
|
|
473
723
|
|
|
474
|
-
// Draw the day-cell grid only for an events calendar; the events-free date
|
|
475
|
-
// picker reads cleaner without it (matching the dom renderer).
|
|
476
|
-
const showGrid = multiWeek || events.length > 0;
|
|
477
|
-
|
|
478
724
|
// Lay out each week row's spanning bars once per data change, not per render.
|
|
479
725
|
const weekLayouts = useMemo(
|
|
480
726
|
() =>
|
|
@@ -493,6 +739,45 @@ function DateRowsInner<T>({
|
|
|
493
739
|
// pointer listeners read, so neither has to be rebuilt as the hover day moves
|
|
494
740
|
// (rebuilding the gesture mid-drag would cancel it).
|
|
495
741
|
const [drag, setDrag] = useState<MonthDrag<T> | null>(null);
|
|
742
|
+
const createRange = useMemo(
|
|
743
|
+
() =>
|
|
744
|
+
createContentEnabled && drag?.kind === "create"
|
|
745
|
+
? monthCreateRange(drag.anchor, drag.hover)
|
|
746
|
+
: null,
|
|
747
|
+
[createContentEnabled, drag],
|
|
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]);
|
|
496
781
|
const dragRef = useRef<MonthDrag<T> | null>(null);
|
|
497
782
|
const interactionWindow = useRef(windowKey);
|
|
498
783
|
interactionWindow.current = windowKey;
|
|
@@ -575,8 +860,26 @@ function DateRowsInner<T>({
|
|
|
575
860
|
(x: number, y: number): { day: Date; event: CalendarEvent<T> | null } | null => {
|
|
576
861
|
const { width, height } = gridSize;
|
|
577
862
|
if (width <= 0 || height <= 0 || weeks.length === 0) return null;
|
|
578
|
-
|
|
579
|
-
|
|
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
|
+
}
|
|
580
883
|
const cols = weeks[row].length;
|
|
581
884
|
const col = Math.min(cols - 1, Math.max(0, Math.floor(x / (width / cols))));
|
|
582
885
|
const day = weeks[row][col];
|
|
@@ -585,10 +888,12 @@ function DateRowsInner<T>({
|
|
|
585
888
|
if (!isDateSelectable(day, { minDate, maxDate, isDateDisabled })) return null;
|
|
586
889
|
// Which lane row the point lands on, mirroring the bar overlay's geometry.
|
|
587
890
|
const rowLayout = weekLayouts[row] ?? EMPTY_LAYOUT;
|
|
588
|
-
const
|
|
589
|
-
const
|
|
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);
|
|
590
895
|
const segment =
|
|
591
|
-
lane >= 0 && lane < visibleLanes
|
|
896
|
+
insideBar && lane >= 0 && lane < visibleLanes + (extraLane[col] ? 1 : 0)
|
|
592
897
|
? rowLayout.segments.find((s) => s.lane === lane && s.startCol <= col && s.endCol >= col)
|
|
593
898
|
: undefined;
|
|
594
899
|
return { day, event: segment?.event ?? null };
|
|
@@ -597,9 +902,13 @@ function DateRowsInner<T>({
|
|
|
597
902
|
gridSize,
|
|
598
903
|
weeks,
|
|
599
904
|
weekLayouts,
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
905
|
+
rowLanes,
|
|
906
|
+
multiWeek,
|
|
907
|
+
rowHeight,
|
|
908
|
+
cellGeometry.weekMarginTop,
|
|
909
|
+
laneChipHeight,
|
|
910
|
+
laneTop,
|
|
911
|
+
cellLaneHeight,
|
|
603
912
|
showAdjacentMonths,
|
|
604
913
|
date,
|
|
605
914
|
minDate,
|
|
@@ -800,7 +1109,7 @@ function DateRowsInner<T>({
|
|
|
800
1109
|
day: Date,
|
|
801
1110
|
dayCol: number,
|
|
802
1111
|
rowLayout: MonthWeekEvents<T>,
|
|
803
|
-
|
|
1112
|
+
dayLanes: number,
|
|
804
1113
|
) => {
|
|
805
1114
|
const isCurrentMonth = multiWeek || isSameMonth(day, date);
|
|
806
1115
|
|
|
@@ -810,7 +1119,7 @@ function DateRowsInner<T>({
|
|
|
810
1119
|
<View
|
|
811
1120
|
key={day.toISOString()}
|
|
812
1121
|
{...slot("day", {
|
|
813
|
-
base: [styles.dayCell, { gap: chipGap }],
|
|
1122
|
+
base: [styles.dayCell, styles.dayCellPadding, { gap: chipGap }],
|
|
814
1123
|
themed: [
|
|
815
1124
|
showGrid && {
|
|
816
1125
|
borderTopWidth: StyleSheet.hairlineWidth,
|
|
@@ -827,7 +1136,7 @@ function DateRowsInner<T>({
|
|
|
827
1136
|
}
|
|
828
1137
|
|
|
829
1138
|
const dayEvents = eventsByDay.get(startOfDay(day).toISOString()) ?? [];
|
|
830
|
-
const isToday = getIsToday(day);
|
|
1139
|
+
const isToday = getIsToday(day, today);
|
|
831
1140
|
// Highlight the chosen `activeDate` when supplied, else the real today.
|
|
832
1141
|
const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : isToday;
|
|
833
1142
|
// Selection band wins over the weekend tint; the today badge shows unless the
|
|
@@ -840,7 +1149,13 @@ function DateRowsInner<T>({
|
|
|
840
1149
|
// Events past the visible lanes (this day's segments the row can't show)
|
|
841
1150
|
// collapse into "+N more"; the popover still lists the whole day.
|
|
842
1151
|
const hiddenEvents = rowLayout.segments
|
|
843
|
-
.filter(
|
|
1152
|
+
.filter(
|
|
1153
|
+
(s) =>
|
|
1154
|
+
s.startCol <= dayCol &&
|
|
1155
|
+
s.endCol >= dayCol &&
|
|
1156
|
+
s.lane >= dayLanes &&
|
|
1157
|
+
s.event !== draftEvent,
|
|
1158
|
+
)
|
|
844
1159
|
.map((s) => s.event);
|
|
845
1160
|
const hiddenCount = hiddenEvents.length;
|
|
846
1161
|
|
|
@@ -851,6 +1166,13 @@ function DateRowsInner<T>({
|
|
|
851
1166
|
const hasBand =
|
|
852
1167
|
rangeBandKind({ isInRange, isRangeStart, isRangeEnd }, fillCellOnSelection) !== "none";
|
|
853
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;
|
|
854
1176
|
// Tint the days a drag is currently over: every day of a create sweep, or the
|
|
855
1177
|
// one an event would land on.
|
|
856
1178
|
const isDragPreview =
|
|
@@ -898,17 +1220,49 @@ function DateRowsInner<T>({
|
|
|
898
1220
|
labels,
|
|
899
1221
|
});
|
|
900
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
|
+
|
|
901
1262
|
const daySlot = slot("day", {
|
|
902
|
-
|
|
903
|
-
// the date badge in the top-right. The picker (no grid) stays centered
|
|
904
|
-
// so the selection range band lines up with the centered badge.
|
|
905
|
-
base: [styles.dayCell, { gap: chipGap }, showGrid && styles.dayCellEvents],
|
|
1263
|
+
base: dayCellBase,
|
|
906
1264
|
themed: [
|
|
907
|
-
|
|
908
|
-
borderTopWidth: StyleSheet.hairlineWidth,
|
|
909
|
-
borderRightWidth: StyleSheet.hairlineWidth,
|
|
910
|
-
borderColor: theme.colors.gridLine,
|
|
911
|
-
},
|
|
1265
|
+
dayCellLines,
|
|
912
1266
|
highlightWeekends && isWeekend(day) && { backgroundColor: theme.colors.weekendBackground },
|
|
913
1267
|
// The drag preview sits on top of the weekend tint: the span being swept
|
|
914
1268
|
// out, or the day an event is about to land on.
|
|
@@ -921,9 +1275,13 @@ function DateRowsInner<T>({
|
|
|
921
1275
|
<TouchableOpacity
|
|
922
1276
|
key={day.toISOString()}
|
|
923
1277
|
{...daySlot}
|
|
924
|
-
//
|
|
925
|
-
|
|
926
|
-
|
|
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
|
+
}
|
|
927
1285
|
// In the picker, don't dim the whole cell on press: the tap should show on
|
|
928
1286
|
// the badge (the circle) only, not the cell background. `onPressIn/Out` drive
|
|
929
1287
|
// the badge's own opacity below. The events calendar keeps the default
|
|
@@ -999,59 +1357,33 @@ function DateRowsInner<T>({
|
|
|
999
1357
|
})}
|
|
1000
1358
|
/>
|
|
1001
1359
|
) : null}
|
|
1002
|
-
{
|
|
1003
|
-
renderCustomDateForMonth(day)
|
|
1004
|
-
) : (
|
|
1360
|
+
{multiWeek ? (
|
|
1005
1361
|
<View
|
|
1006
|
-
{
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
isFilledBadge && {
|
|
1016
|
-
backgroundColor: isHighlighted
|
|
1017
|
-
? theme.colors.todayBackground
|
|
1018
|
-
: theme.colors.selectedBackground,
|
|
1019
|
-
borderRadius: theme.todayBadgeRadius,
|
|
1020
|
-
},
|
|
1021
|
-
isHovered &&
|
|
1022
|
-
!isFilledBadge && {
|
|
1023
|
-
backgroundColor: theme.colors.hoverBackground,
|
|
1024
|
-
borderRadius: theme.todayBadgeRadius,
|
|
1025
|
-
},
|
|
1026
|
-
theme.containers.dayBadge,
|
|
1027
|
-
],
|
|
1028
|
-
})}
|
|
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
|
+
}
|
|
1029
1371
|
>
|
|
1030
|
-
|
|
1031
|
-
{...slot<TextStyle>("dayBadgeText", {
|
|
1032
|
-
themed: [theme.text.dateCell, { color: dateColor }],
|
|
1033
|
-
})}
|
|
1034
|
-
allowFontScaling={false}
|
|
1035
|
-
>
|
|
1036
|
-
{format(day, "d")}
|
|
1037
|
-
</Text>
|
|
1372
|
+
{dateElement}
|
|
1038
1373
|
</View>
|
|
1374
|
+
) : (
|
|
1375
|
+
dateElement
|
|
1039
1376
|
)}
|
|
1040
1377
|
{/* Reserve one row per visible lane so the overlay bars have space and
|
|
1041
1378
|
"+more" sits below them; the bars themselves render in the row overlay
|
|
1042
1379
|
(they span cells). */}
|
|
1043
|
-
{
|
|
1044
|
-
|
|
1045
|
-
key={`lane-${i}`}
|
|
1046
|
-
|
|
1047
|
-
/>
|
|
1048
|
-
))}
|
|
1380
|
+
{!multiWeek &&
|
|
1381
|
+
Array.from({ length: dayLanes }, (_, i) => (
|
|
1382
|
+
<View key={`lane-${i}`} style={{ height: laneChipHeight, pointerEvents: "none" }} />
|
|
1383
|
+
))}
|
|
1049
1384
|
{hiddenCount > 0 ? (
|
|
1050
1385
|
<Text
|
|
1051
|
-
{...
|
|
1052
|
-
base: [styles.moreLabel, chipHeight != null && { height: chipHeight }],
|
|
1053
|
-
themed: [theme.text.more, { color: theme.colors.textMuted }],
|
|
1054
|
-
})}
|
|
1386
|
+
{...moreSlot}
|
|
1055
1387
|
onPress={
|
|
1056
1388
|
onPressMore
|
|
1057
1389
|
? () => onPressMore(dayEvents, day)
|
|
@@ -1060,6 +1392,7 @@ function DateRowsInner<T>({
|
|
|
1060
1392
|
accessibilityRole="button"
|
|
1061
1393
|
accessibilityLabel={`${labels.moreEvents(hiddenCount)}, ${format(day, "d MMMM", { locale })}`}
|
|
1062
1394
|
allowFontScaling={false}
|
|
1395
|
+
numberOfLines={1}
|
|
1063
1396
|
>
|
|
1064
1397
|
{moreLabel.replace("{moreCount}", String(hiddenCount))}
|
|
1065
1398
|
</Text>
|
|
@@ -1078,6 +1411,50 @@ function DateRowsInner<T>({
|
|
|
1078
1411
|
return (
|
|
1079
1412
|
<CalendarLabelsContext.Provider value={labels}>
|
|
1080
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
|
+
)}
|
|
1081
1458
|
{showTitle ? (
|
|
1082
1459
|
<Text
|
|
1083
1460
|
{...slot<TextStyle>("title", {
|
|
@@ -1159,7 +1536,7 @@ function DateRowsInner<T>({
|
|
|
1159
1536
|
</Pressable>
|
|
1160
1537
|
</Modal>
|
|
1161
1538
|
) : null}
|
|
1162
|
-
<DateRowsViewport scrollable={multiWeek}>
|
|
1539
|
+
<DateRowsViewport scrollable={multiWeek} onHeight={setViewportHeight}>
|
|
1163
1540
|
<MonthGridSurface gesture={dragGesture}>
|
|
1164
1541
|
<View
|
|
1165
1542
|
ref={gridRef}
|
|
@@ -1167,8 +1544,10 @@ function DateRowsInner<T>({
|
|
|
1167
1544
|
accessibilityLabel={multiWeek ? title : undefined}
|
|
1168
1545
|
{...slot("grid", {
|
|
1169
1546
|
base: [
|
|
1170
|
-
styles.container,
|
|
1171
|
-
multiWeek
|
|
1547
|
+
!multiWeekRowHeight && styles.container,
|
|
1548
|
+
multiWeek && {
|
|
1549
|
+
minHeight: minimumRowHeight * weeks.length + (gridProbe ? gridInnerSpacing : 0),
|
|
1550
|
+
},
|
|
1172
1551
|
],
|
|
1173
1552
|
})}
|
|
1174
1553
|
onLayout={handleLayout}
|
|
@@ -1189,9 +1568,9 @@ function DateRowsInner<T>({
|
|
|
1189
1568
|
// event is one bar across its columns, stacked into lanes; the bars render
|
|
1190
1569
|
// in an overlay so they can span cells, and the cells reserve the lane rows
|
|
1191
1570
|
// so "+more" sits below them. `visibleLanes` mirrors the per-day cap.
|
|
1192
|
-
const rowLayout =
|
|
1193
|
-
const visibleLanes = monthVisibleCount(rowLayout.laneCount, capacity);
|
|
1571
|
+
const rowLayout = rowLayouts[weekIndex] ?? EMPTY_LAYOUT;
|
|
1194
1572
|
const cols = week.length;
|
|
1573
|
+
const { visibleLanes, extraLane } = rowLanes(rowLayout, cols);
|
|
1195
1574
|
// With adjacent months hidden, clamp bars to the current-month columns so
|
|
1196
1575
|
// none draw over the blank leading/trailing cells.
|
|
1197
1576
|
let firstVisCol = 0;
|
|
@@ -1204,12 +1583,49 @@ function DateRowsInner<T>({
|
|
|
1204
1583
|
cols - 1 - [...week].reverse().findIndex((d) => isSameMonth(d, date));
|
|
1205
1584
|
}
|
|
1206
1585
|
}
|
|
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));
|
|
1207
1592
|
return (
|
|
1208
1593
|
<View
|
|
1209
|
-
{...slot("week", {
|
|
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
|
+
})}
|
|
1210
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
|
+
}
|
|
1211
1625
|
>
|
|
1212
|
-
{week.map((day, dayCol) =>
|
|
1626
|
+
{week.map((day, dayCol) =>
|
|
1627
|
+
renderDay(day, dayCol, rowLayout, visibleLanes + (extraLane[dayCol] ? 1 : 0)),
|
|
1628
|
+
)}
|
|
1213
1629
|
{showGrid ? (
|
|
1214
1630
|
<View
|
|
1215
1631
|
style={[
|
|
@@ -1219,8 +1635,8 @@ function DateRowsInner<T>({
|
|
|
1219
1635
|
: { pointerEvents: "box-none" },
|
|
1220
1636
|
]}
|
|
1221
1637
|
>
|
|
1222
|
-
{rowLayout
|
|
1223
|
-
.filter((seg) => seg.
|
|
1638
|
+
{monthVisibleBars(rowLayout, visibleLanes, extraLane)
|
|
1639
|
+
.filter((seg) => seg.event !== draftEvent)
|
|
1224
1640
|
.map((seg) => {
|
|
1225
1641
|
const startCol = Math.max(seg.startCol, firstVisCol);
|
|
1226
1642
|
const endCol = Math.min(seg.endCol, lastVisCol);
|
|
@@ -1230,14 +1646,14 @@ function DateRowsInner<T>({
|
|
|
1230
1646
|
const isDragged = drag?.kind === "move" && drag.event === seg.event;
|
|
1231
1647
|
return (
|
|
1232
1648
|
<View
|
|
1233
|
-
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}`}
|
|
1234
1650
|
style={[
|
|
1235
1651
|
{
|
|
1236
1652
|
position: "absolute",
|
|
1237
1653
|
left: pct((startCol / cols) * 100),
|
|
1238
1654
|
width: pct(((endCol - startCol + 1) / cols) * 100),
|
|
1239
|
-
top:
|
|
1240
|
-
height:
|
|
1655
|
+
top: barTop + seg.lane * cellLaneHeight,
|
|
1656
|
+
height: laneChipHeight,
|
|
1241
1657
|
paddingHorizontal: CHIP_INSET_H,
|
|
1242
1658
|
// Let a sweep in progress reach the cells underneath.
|
|
1243
1659
|
opacity: isDragged ? DRAGGED_BAR_OPACITY : 1,
|
|
@@ -1270,6 +1686,40 @@ function DateRowsInner<T>({
|
|
|
1270
1686
|
</View>
|
|
1271
1687
|
);
|
|
1272
1688
|
})}
|
|
1689
|
+
{RenderCreateGhost &&
|
|
1690
|
+
createRange &&
|
|
1691
|
+
draftStart >= 0 &&
|
|
1692
|
+
draftEnd >= draftStart &&
|
|
1693
|
+
draftHeight > 0 ? (
|
|
1694
|
+
<View
|
|
1695
|
+
testID="month-create-ghost"
|
|
1696
|
+
{...slot("createGhost", {
|
|
1697
|
+
base: {
|
|
1698
|
+
position: "absolute",
|
|
1699
|
+
left: pct((draftStart / cols) * 100),
|
|
1700
|
+
right: pct(((cols - 1 - draftEnd) / cols) * 100),
|
|
1701
|
+
top: draftTop,
|
|
1702
|
+
height: draftHeight,
|
|
1703
|
+
marginHorizontal: CHIP_INSET_H,
|
|
1704
|
+
overflow: "hidden",
|
|
1705
|
+
zIndex: 1,
|
|
1706
|
+
},
|
|
1707
|
+
themed: {
|
|
1708
|
+
backgroundColor: theme.colors.rangeBackground,
|
|
1709
|
+
borderColor: theme.colors.selectedBackground,
|
|
1710
|
+
borderWidth: 1,
|
|
1711
|
+
borderRadius: 4,
|
|
1712
|
+
},
|
|
1713
|
+
})}
|
|
1714
|
+
{...webPreviewProps}
|
|
1715
|
+
pointerEvents="none"
|
|
1716
|
+
accessible={false}
|
|
1717
|
+
accessibilityElementsHidden
|
|
1718
|
+
importantForAccessibility="no-hide-descendants"
|
|
1719
|
+
>
|
|
1720
|
+
<RenderCreateGhost start={createRange.start} end={createRange.end} />
|
|
1721
|
+
</View>
|
|
1722
|
+
) : null}
|
|
1273
1723
|
</View>
|
|
1274
1724
|
) : null}
|
|
1275
1725
|
</View>
|
|
@@ -1283,15 +1733,35 @@ function DateRowsInner<T>({
|
|
|
1283
1733
|
);
|
|
1284
1734
|
}
|
|
1285
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
|
+
|
|
1286
1749
|
function DateRowsViewport({
|
|
1287
1750
|
scrollable,
|
|
1751
|
+
onHeight,
|
|
1288
1752
|
children,
|
|
1289
1753
|
}: {
|
|
1290
1754
|
scrollable: boolean;
|
|
1755
|
+
onHeight: (height: number) => void;
|
|
1291
1756
|
children: ReactElement;
|
|
1292
1757
|
}): ReactElement {
|
|
1293
1758
|
return scrollable ? (
|
|
1294
|
-
<ScrollView
|
|
1759
|
+
<ScrollView
|
|
1760
|
+
testID="multiweek-viewport"
|
|
1761
|
+
style={styles.multiWeekViewport}
|
|
1762
|
+
contentContainerStyle={{ flexGrow: 1 }}
|
|
1763
|
+
onLayout={(event) => onHeight(event.nativeEvent.layout.height)}
|
|
1764
|
+
>
|
|
1295
1765
|
{children}
|
|
1296
1766
|
</ScrollView>
|
|
1297
1767
|
) : (
|
|
@@ -1337,6 +1807,10 @@ export const MonthView = memo(MonthViewInner) as typeof MonthViewInner;
|
|
|
1337
1807
|
export const DateRows = memo(DateRowsInner) as typeof DateRowsInner;
|
|
1338
1808
|
|
|
1339
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" },
|
|
1340
1814
|
root: {
|
|
1341
1815
|
flex: 1,
|
|
1342
1816
|
},
|
|
@@ -1357,6 +1831,8 @@ const styles = StyleSheet.create({
|
|
|
1357
1831
|
container: {
|
|
1358
1832
|
flex: 1,
|
|
1359
1833
|
},
|
|
1834
|
+
// A classic scrollbar must not change the column widths that determine the row heights.
|
|
1835
|
+
multiWeekViewport: { flex: 1, ...(isWeb && { scrollbarGutter: "stable" }) },
|
|
1360
1836
|
// react-native-web needs registered styles to expand the child rules for box-none.
|
|
1361
1837
|
childrenOnlyPointerEvents: { pointerEvents: "box-none" },
|
|
1362
1838
|
noPointerEvents: { pointerEvents: "none" },
|
|
@@ -1364,13 +1840,16 @@ const styles = StyleSheet.create({
|
|
|
1364
1840
|
flex: 1,
|
|
1365
1841
|
flexDirection: "row",
|
|
1366
1842
|
},
|
|
1843
|
+
// A multi-week row at a set height: no `flex`, which would override the height.
|
|
1844
|
+
weekRowFixed: {
|
|
1845
|
+
flexDirection: "row",
|
|
1846
|
+
},
|
|
1367
1847
|
dayCell: {
|
|
1368
1848
|
flex: 1,
|
|
1369
1849
|
alignItems: "center",
|
|
1370
|
-
paddingTop: 4,
|
|
1371
|
-
gap: 2,
|
|
1372
1850
|
overflow: "hidden",
|
|
1373
1851
|
},
|
|
1852
|
+
dayCellPadding: { paddingTop: DAY_CELL_PADDING_TOP },
|
|
1374
1853
|
dayCellEvents: {
|
|
1375
1854
|
alignItems: "stretch",
|
|
1376
1855
|
},
|
|
@@ -1393,7 +1872,7 @@ const styles = StyleSheet.create({
|
|
|
1393
1872
|
marginHorizontal: 4,
|
|
1394
1873
|
},
|
|
1395
1874
|
moreLabel: {
|
|
1396
|
-
marginTop:
|
|
1875
|
+
marginTop: MORE_LABEL_MARGIN_TOP,
|
|
1397
1876
|
marginHorizontal: 4,
|
|
1398
1877
|
},
|
|
1399
1878
|
// The built-in "+N more" popover card.
|