@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.
@@ -1,5 +1,14 @@
1
- import type { ComponentType, ReactElement, ReactNode } from "react";
2
- import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
1
+ import {
2
+ type ComponentType,
3
+ type ReactElement,
4
+ type ReactNode,
5
+ useCallback,
6
+ useEffect,
7
+ useLayoutEffect,
8
+ useMemo,
9
+ useRef,
10
+ useState,
11
+ } from "react";
3
12
  import {
4
13
  type AccessibilityActionEvent,
5
14
  type GestureResponderEvent,
@@ -81,12 +81,11 @@ import type {
81
81
  } from "../types";
82
82
  import {
83
83
  getIsToday,
84
+ nowInTimeZone,
84
85
  getViewDays,
85
86
  isSameCalendarDay,
86
87
  isWeekend,
87
88
  viewDayCount,
88
- } from "@super-calendar/core";
89
- import {
90
89
  backgroundBandsForDay,
91
90
  cellRangeFromDrag,
92
91
  clampMoveStartMinutes,
@@ -97,15 +96,16 @@ import {
97
96
  resolveDraggedBounds,
98
97
  movedClockSpan,
99
98
  snapDeltaMinutes,
99
+ formatHour,
100
+ layoutDayEvents,
101
+ type PositionedEvent,
102
+ type CalendarHandle,
103
+ type CalendarLabels,
104
+ type EventAccessibilityLabeler,
105
+ resolveCalendarLabels,
106
+ type WeekdayFormat,
107
+ weekdayFormatToken,
100
108
  } from "@super-calendar/core";
101
- import { formatHour, layoutDayEvents, type PositionedEvent } from "@super-calendar/core";
102
- import type {
103
- CalendarHandle,
104
- CalendarLabels,
105
- EventAccessibilityLabeler,
106
- } from "@super-calendar/core";
107
- import { resolveCalendarLabels } from "@super-calendar/core";
108
- import { type WeekdayFormat, weekdayFormatToken } from "@super-calendar/core";
109
109
  import {
110
110
  type ResolvedSlot,
111
111
  SlotStylesProvider,
@@ -481,10 +481,14 @@ function AnimatedEventBoxInner<T>({
481
481
  // Raised to DRAG_EVENT_Z while a gesture is active so the dragged event floats
482
482
  // above all the others, then back to 0 when it settles.
483
483
  const dragZ = useSharedValue(0);
484
- // 1 while a move gesture is running. Only gates the spill preview: the box's own
485
- // clip is geometric, so it can't disagree with the box during the frames between
486
- // release and the committed re-render.
484
+ // 1 while a move gesture is running. Gates the spill preview and floats the box
485
+ // across its day column; the box's own clip is geometric, so it can't disagree
486
+ // with the box during the frames between release and the committed re-render.
487
487
  const moving = useSharedValue(0);
488
+ // 1 while a resize pan runs after a long press already picked the event up. The
489
+ // move gesture wraps the handles, so a hold on one starts a move, and the resize
490
+ // stands aside until the finger lifts instead of committing as well.
491
+ const resizeYielded = useSharedValue(0);
488
492
  // Edge auto-advance: which side the drag has pushed past the visible columns
489
493
  // (-1 left / 0 none / +1 right).
490
494
  const edgeDir = useSharedValue(0);
@@ -520,6 +524,9 @@ function AnimatedEventBoxInner<T>({
520
524
  }),
521
525
  [startHours, ownsStart],
522
526
  );
527
+ // How far into its day column the box sits, mirrored the same way: an overlap
528
+ // group reflows when the consumer updates `events` mid-drag.
529
+ const columnInsetSV = useDerivedValue(() => left - dayLeftPx, [left, dayLeftPx]);
523
530
 
524
531
  // Where a move in progress lands beyond its plain row offset, in hours: a start
525
532
  // in the hour a spring-forward change skips moves on past it (`top`), and the
@@ -596,14 +603,21 @@ function AnimatedEventBoxInner<T>({
596
603
  // drag commits.
597
604
  // Hidden while lifted: the floating ghost stands in for the box until the
598
605
  // drop commits (and, for a multi-day move, while the preview draws it).
606
+ // A picked-up event floats across its whole day column, like the multi-day
607
+ // preview and the spill, instead of keeping its slice of an overlap group. It
608
+ // keeps floating while a dropped move holds its offset, so the box doesn't
609
+ // flash back to its old slice before the committed layout lands.
610
+ const floating = moving.value || moveOffset.value !== 0 || moveOffsetX.value !== 0;
599
611
  return {
612
+ left: floating ? dayLeftPx : left,
613
+ width: floating ? dayWidth : width,
600
614
  top,
601
615
  height: visibleBoxHeight.value,
602
616
  transform: [{ translateX: moveOffsetX.value }],
603
617
  zIndex: dragZ.value,
604
618
  opacity: hiddenForMove || lifted.value ? 0 : 1,
605
619
  };
606
- }, [startHours, minHour, hiddenForMove]);
620
+ }, [startHours, minHour, hiddenForMove, left, width, dayLeftPx, dayWidth]);
607
621
 
608
622
  // Pixel height of the part of a move that runs past midnight, or 0 when nothing
609
623
  // spills. Measured against the end of the day, not `maxHour`: a narrowed window
@@ -781,7 +795,7 @@ function AnimatedEventBoxInner<T>({
781
795
  // the same gesture keeps tracking after the page changes.
782
796
  if (!lifted.value) {
783
797
  lifted.value = 1;
784
- edgePaging.ghostW.value = width;
798
+ edgePaging.ghostW.value = dayWidth;
785
799
  edgePaging.ghostH.value = boxHeight.value;
786
800
  edgePaging.ghostX.value = liveAbsX.value - grabX.value - edgePaging.pagerLeft.value;
787
801
  edgePaging.ghostY.value = liveAbsY.value - grabY.value - edgePaging.pagerTop.value;
@@ -797,7 +811,7 @@ function AnimatedEventBoxInner<T>({
797
811
  disarmEdge,
798
812
  edgePaging,
799
813
  lifted,
800
- width,
814
+ dayWidth,
801
815
  boxHeight,
802
816
  liveAbsX,
803
817
  liveAbsY,
@@ -816,8 +830,9 @@ function AnimatedEventBoxInner<T>({
816
830
  edgeDir.value = 0;
817
831
  lifted.value = 0;
818
832
  // Where in the box the finger grabbed, and the live finger position, so
819
- // the ghost can be seeded and tracked in window space (see armEdge).
820
- grabX.value = event.x;
833
+ // the ghost can be seeded and tracked in window space (see armEdge). The
834
+ // grab is measured from the day column, where the floating box now starts.
835
+ grabX.value = event.x + columnInsetSV.value;
821
836
  grabY.value = event.y;
822
837
  liveAbsX.value = event.absoluteX;
823
838
  liveAbsY.value = event.absoluteY;
@@ -931,6 +946,7 @@ function AnimatedEventBoxInner<T>({
931
946
  }, [
932
947
  canMove,
933
948
  snapMinutes,
949
+ columnInsetSV,
934
950
  cellHeight,
935
951
  moveOffset,
936
952
  moveOffsetX,
@@ -983,18 +999,25 @@ function AnimatedEventBoxInner<T>({
983
999
  // A plain tap on a resize handle is a press on the event. The two handles cover
984
1000
  // almost all of a box at the minimum height, so without this a 5- to 30-minute
985
1001
  // event has next to no tappable surface. A drag from a handle still resizes:
986
- // the pan wins the race as soon as the finger moves.
1002
+ // the pan wins the race as soon as the finger moves. A long press on a handle
1003
+ // picks the event up for a move instead, as it does anywhere on the box.
987
1004
  const resizeGesture = useMemo(() => {
988
1005
  const pan = Gesture.Pan()
989
1006
  .enabled(resizable)
990
1007
  .onStart(() => {
1008
+ if (moving.value) {
1009
+ resizeYielded.value = 1;
1010
+ return;
1011
+ }
991
1012
  dragZ.value = DRAG_EVENT_Z;
992
1013
  runOnJS(notifyDragStart)();
993
1014
  })
994
1015
  .onUpdate((event) => {
1016
+ if (resizeYielded.value) return;
995
1017
  resizeDelta.value = event.translationY;
996
1018
  })
997
1019
  .onEnd((event) => {
1020
+ if (resizeYielded.value) return;
998
1021
  const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
999
1022
  if (delta === 0) {
1000
1023
  resizeDelta.value = 0;
@@ -1004,7 +1027,9 @@ function AnimatedEventBoxInner<T>({
1004
1027
  runOnJS(commitDrag)(0, delta);
1005
1028
  })
1006
1029
  .onFinalize(() => {
1007
- dragZ.value = 0;
1030
+ // A yielded resize leaves the moving box raised.
1031
+ if (!resizeYielded.value) dragZ.value = 0;
1032
+ resizeYielded.value = 0;
1008
1033
  });
1009
1034
  const tap = Gesture.Tap()
1010
1035
  .runOnJS(true)
@@ -1022,6 +1047,8 @@ function AnimatedEventBoxInner<T>({
1022
1047
  resizable,
1023
1048
  snapMinutes,
1024
1049
  cellHeight,
1050
+ moving,
1051
+ resizeYielded,
1025
1052
  resizeDelta,
1026
1053
  dragZ,
1027
1054
  commitDrag,
@@ -1037,13 +1064,19 @@ function AnimatedEventBoxInner<T>({
1037
1064
  const pan = Gesture.Pan()
1038
1065
  .enabled(resizableFromStart)
1039
1066
  .onStart(() => {
1067
+ if (moving.value) {
1068
+ resizeYielded.value = 1;
1069
+ return;
1070
+ }
1040
1071
  dragZ.value = DRAG_EVENT_Z;
1041
1072
  runOnJS(notifyDragStart)();
1042
1073
  })
1043
1074
  .onUpdate((event) => {
1075
+ if (resizeYielded.value) return;
1044
1076
  resizeStartDelta.value = event.translationY;
1045
1077
  })
1046
1078
  .onEnd((event) => {
1079
+ if (resizeYielded.value) return;
1047
1080
  const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
1048
1081
  if (delta === 0) {
1049
1082
  resizeStartDelta.value = 0;
@@ -1053,7 +1086,9 @@ function AnimatedEventBoxInner<T>({
1053
1086
  runOnJS(commitDrag)(delta, 0);
1054
1087
  })
1055
1088
  .onFinalize(() => {
1056
- dragZ.value = 0;
1089
+ // A yielded resize leaves the moving box raised.
1090
+ if (!resizeYielded.value) dragZ.value = 0;
1091
+ resizeYielded.value = 0;
1057
1092
  });
1058
1093
  const tap = Gesture.Tap()
1059
1094
  .runOnJS(true)
@@ -1071,6 +1106,8 @@ function AnimatedEventBoxInner<T>({
1071
1106
  resizableFromStart,
1072
1107
  snapMinutes,
1073
1108
  cellHeight,
1109
+ moving,
1110
+ resizeYielded,
1074
1111
  resizeStartDelta,
1075
1112
  dragZ,
1076
1113
  commitDrag,
@@ -1770,6 +1807,9 @@ function TimetablePageInner<T>({
1770
1807
  const hoursRange = useMemo(() => hourRange(minHour, maxHour), [minHour, maxHour]);
1771
1808
 
1772
1809
  const now = useNow(showNowIndicator && isActive, { now: nowProp, timeZone: nowTimeZone });
1810
+ // The day the header marks as today: the indicator's clock while it runs, so
1811
+ // the two can't disagree.
1812
+ const today = showNowIndicator && isActive ? now : nowInTimeZone(nowProp, nowTimeZone);
1773
1813
  // "Today" follows the (possibly zone-shifted or overridden) now, so the line
1774
1814
  // lands in the column the events are displayed in.
1775
1815
  const nowDayIndex = days.findIndex((day) => isSameCalendarDay(day, now));
@@ -2178,6 +2218,7 @@ function TimetablePageInner<T>({
2178
2218
  dayWidth={dayWidth}
2179
2219
  weekdayFormat={weekdayFormat}
2180
2220
  todayLabel={todayLabel}
2221
+ today={today}
2181
2222
  locale={locale}
2182
2223
  activeDate={activeDate}
2183
2224
  onPressDateHeader={onPressDateHeader}
@@ -2480,9 +2521,15 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
2480
2521
  weekEndsOn?: WeekStartsOn;
2481
2522
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
2482
2523
  hiddenDays?: number[];
2483
- /** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
2524
+ /**
2525
+ * Fixed "now" instant for the indicator (doesn't tick) and for the day
2526
+ * highlighted as today. Defaults to the device clock.
2527
+ */
2484
2528
  now?: Date;
2485
- /** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
2529
+ /**
2530
+ * Shift the now indicator and the day highlighted as today into this IANA zone
2531
+ * (pair with `eventsInTimeZone`).
2532
+ */
2486
2533
  timeZone?: string;
2487
2534
  date: Date;
2488
2535
  events: CalendarEvent<T>[];
@@ -3503,6 +3550,8 @@ function TimeGridInner<T>(
3503
3550
  // `columnsWidth` resizes the mounted pages when the grid is re-measured.
3504
3551
  // `showDragHandle` refreshes grips without requiring an event-data change, and
3505
3552
  // `renderCreateGhost` swaps the preview content of mounted pages.
3553
+ // `now` and `timeZone` move the today highlight and the now line.
3554
+ const nowTime = now?.getTime();
3506
3555
  const listExtraData = useMemo(
3507
3556
  () => ({
3508
3557
  events,
@@ -3514,6 +3563,8 @@ function TimeGridInner<T>(
3514
3563
  dragStepMinutes,
3515
3564
  minHour,
3516
3565
  maxHour,
3566
+ nowTime,
3567
+ timeZone,
3517
3568
  }),
3518
3569
  [
3519
3570
  events,
@@ -3525,6 +3576,8 @@ function TimeGridInner<T>(
3525
3576
  dragStepMinutes,
3526
3577
  minHour,
3527
3578
  maxHour,
3579
+ nowTime,
3580
+ timeZone,
3528
3581
  ],
3529
3582
  );
3530
3583
 
@@ -3713,6 +3766,7 @@ type DayHeaderRowProps = {
3713
3766
  dayWidth: number;
3714
3767
  weekdayFormat?: WeekdayFormat;
3715
3768
  todayLabel: string;
3769
+ today: Date;
3716
3770
  locale?: Locale;
3717
3771
  activeDate?: Date;
3718
3772
  onPressDateHeader?: (date: Date) => void;
@@ -3726,6 +3780,7 @@ const DayHeaderRow = ({
3726
3780
  dayWidth,
3727
3781
  weekdayFormat,
3728
3782
  todayLabel,
3783
+ today,
3729
3784
  locale,
3730
3785
  activeDate,
3731
3786
  onPressDateHeader,
@@ -3741,6 +3796,7 @@ const DayHeaderRow = ({
3741
3796
  width={dayWidth}
3742
3797
  weekdayFormat={weekdayFormat}
3743
3798
  todayLabel={todayLabel}
3799
+ today={today}
3744
3800
  locale={locale}
3745
3801
  activeDate={activeDate}
3746
3802
  onPressDateHeader={onPressDateHeader}
@@ -3756,6 +3812,7 @@ type DayHeaderProps = {
3756
3812
  width: number;
3757
3813
  weekdayFormat?: WeekdayFormat;
3758
3814
  todayLabel: string;
3815
+ today: Date;
3759
3816
  locale?: Locale;
3760
3817
  activeDate?: Date;
3761
3818
  onPressDateHeader?: (date: Date) => void;
@@ -3766,13 +3823,14 @@ const DayHeader = ({
3766
3823
  width,
3767
3824
  weekdayFormat = "short",
3768
3825
  todayLabel,
3826
+ today,
3769
3827
  locale,
3770
3828
  activeDate,
3771
3829
  onPressDateHeader,
3772
3830
  }: DayHeaderProps) => {
3773
3831
  const theme = useCalendarTheme();
3774
3832
  const slot = useSlots<TimeGridSlot>();
3775
- const isToday = getIsToday(day);
3833
+ const isToday = getIsToday(day, today);
3776
3834
  // Highlight the chosen `activeDate` when supplied, else the real today.
3777
3835
  const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : isToday;
3778
3836
 
@@ -23,6 +23,7 @@ import {
23
23
  monthCreateRange,
24
24
  daySelectionState,
25
25
  getIsToday,
26
+ nowInTimeZone,
26
27
  filterHiddenDays,
27
28
  getWeekDays,
28
29
  getYearMonths,
@@ -32,8 +33,6 @@ import {
32
33
  isSameCalendarDay,
33
34
  rangeBandKind,
34
35
  weekdayFormatToken,
35
- } from "@super-calendar/core";
36
- import {
37
36
  type CalendarLabels,
38
37
  dayAccessibilityLabel,
39
38
  resolveCalendarLabels,
@@ -72,6 +71,13 @@ export type YearViewProps<T = unknown> = SlotStyleProps<YearViewSlot> & {
72
71
  /** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
73
72
  hiddenDays?: number[];
74
73
  locale?: Locale;
74
+ /**
75
+ * The instant whose calendar day is highlighted as today. Defaults to the
76
+ * device clock, and is read in `timeZone` when one is set.
77
+ */
78
+ now?: Date;
79
+ /** Highlight today as it is in this IANA time zone (default: the device's). */
80
+ timeZone?: string;
75
81
  /** Translations for the screen-reader words; omitted keys use English. */
76
82
  labels?: Partial<CalendarLabels>;
77
83
  /** Highlight this date instead of the real "today". */
@@ -125,6 +131,8 @@ function YearViewInner<T>({
125
131
  weekStartsOn,
126
132
  hiddenDays,
127
133
  locale,
134
+ now,
135
+ timeZone,
128
136
  labels: labelsProp,
129
137
  activeDate,
130
138
  selectedRange,
@@ -152,6 +160,7 @@ function YearViewInner<T>({
152
160
  setColumns(Math.max(2, Math.min(4, Math.floor(width / minMonthWidth))));
153
161
  };
154
162
 
163
+ const today = nowInTimeZone(now, timeZone);
155
164
  const months = useMemo(() => getYearMonths(date), [date]);
156
165
  // Each mini month's week rows, built once per year rather than per render, so
157
166
  // the drag hit-test (and the pan it is built into) keeps a stable identity.
@@ -332,7 +341,7 @@ function YearViewInner<T>({
332
341
  if (day.getMonth() !== month.getMonth()) {
333
342
  return <View key={day.toISOString()} style={styles.day} />;
334
343
  }
335
- const isToday = getIsToday(day);
344
+ const isToday = getIsToday(day, today);
336
345
  const isHighlighted = activeDate
337
346
  ? isSameCalendarDay(day, activeDate)
338
347
  : isToday;
package/src/index.tsx CHANGED
@@ -65,6 +65,7 @@ export type {
65
65
  EventAccessibilityLabeler,
66
66
  EventKeyExtractor,
67
67
  ICalendarEvent,
68
+ MonthDateInfo,
68
69
  RecurrenceFrequency,
69
70
  RecurrenceRule,
70
71
  RenderEvent,
@@ -107,7 +108,7 @@ export {
107
108
  useMonthGrid,
108
109
  weekdayFormatToken,
109
110
  } from "@super-calendar/core";
110
- export { expandRecurringEvents } from "@super-calendar/core";
111
+ export { expandRecurringEvents, type ExpandRecurringEventsOptions } from "@super-calendar/core";
111
112
  export { type CalendarLabels, defaultCalendarLabels } from "@super-calendar/core";
112
113
  export {
113
114
  type ICalEvent,
@@ -115,7 +116,15 @@ export {
115
116
  toICalendar,
116
117
  type ToICalendarOptions,
117
118
  } from "@super-calendar/core";
118
- export { eventsInTimeZone, toZonedTime } from "@super-calendar/core";
119
+ export {
120
+ eventsInTimeZone,
121
+ fromZonedRange,
122
+ fromZonedTime,
123
+ nowInTimeZone,
124
+ toZonedTime,
125
+ zonedDragBounds,
126
+ zonedEventSource,
127
+ } from "@super-calendar/core";
119
128
  export {
120
129
  buildMonthWeeks,
121
130
  getViewDays,
package/src/types.ts CHANGED
@@ -67,8 +67,8 @@ export type RenderEventArgs<T = unknown> = {
67
67
  boxHeight?: SharedValue<number>;
68
68
  /**
69
69
  * On the week/day grid, true when this is a clipped segment of a multi-day
70
- * event that started on an earlier day / continues onto a later day. Lets a
71
- * renderer draw "continues" affordances. `undefined` in month mode.
70
+ * timed event. For an all-day bar, these flags refer to the visible date
71
+ * range instead. Lets a renderer draw "continues" affordances.
72
72
  */
73
73
  continuesBefore?: boolean;
74
74
  continuesAfter?: boolean;
@@ -112,3 +112,21 @@ export type RenderEventArgs<T = unknown> = {
112
112
  * (`flex: 1`); the calendar positions and sizes the wrapping box for you.
113
113
  */
114
114
  export type RenderEvent<T = unknown> = ComponentType<RenderEventArgs<T>>;
115
+
116
+ /**
117
+ * The state of a month day cell, passed to `renderCustomDateForMonth` so a custom
118
+ * date badge can style the day the way the built-in badge does.
119
+ */
120
+ export type MonthDateInfo = {
121
+ /**
122
+ * False for a day from the previous or next month, shown with
123
+ * `showAdjacentMonths`. Always true in `MultiWeekView`.
124
+ */
125
+ isCurrentMonth: boolean;
126
+ /** The day is today. */
127
+ isToday: boolean;
128
+ /** The day is in `selectedDates` or is an endpoint of `selectedRange`. */
129
+ isSelected: boolean;
130
+ /** The day fails `minDate`, `maxDate` or `isDateDisabled`. */
131
+ isDisabled: boolean;
132
+ };