@super-calendar/native 2.5.0 → 2.7.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/dist/{DefaultMonthEvent-BSvuJUFk.d.ts → DefaultMonthEvent-DCPDsnvq.d.ts} +10 -6
- package/dist/{DefaultMonthEvent-zDj9dHEv.d.mts → DefaultMonthEvent-DMOC5aNL.d.mts} +10 -6
- package/dist/{MonthList-Aczb2RSY.js → MonthList-CJs1vq5T.js} +81 -12
- package/dist/{MonthList-zPLklHAY.mjs → MonthList-Dn37Ezj0.mjs} +83 -14
- package/dist/index.d.mts +130 -18
- package/dist/index.d.ts +130 -18
- package/dist/index.js +799 -121
- package/dist/index.mjs +778 -125
- 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 +5 -2
- package/src/components/AllDayLane.tsx +3 -2
- package/src/components/Calendar.tsx +61 -2
- package/src/components/DefaultEvent.tsx +3 -1
- package/src/components/MonthPager.tsx +12 -3
- package/src/components/MonthView.tsx +95 -8
- package/src/components/ResourceTimeline.tsx +270 -29
- package/src/components/TimeGrid.tsx +656 -97
- package/src/components/YearView.tsx +286 -0
- package/src/index.tsx +11 -1
- package/src/types.ts +1 -0
|
@@ -15,7 +15,17 @@ import {
|
|
|
15
15
|
startOfDay,
|
|
16
16
|
startOfWeek,
|
|
17
17
|
} from "date-fns";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
createContext,
|
|
20
|
+
memo,
|
|
21
|
+
type ReactElement,
|
|
22
|
+
useCallback,
|
|
23
|
+
useContext,
|
|
24
|
+
useEffect,
|
|
25
|
+
useMemo,
|
|
26
|
+
useRef,
|
|
27
|
+
useState,
|
|
28
|
+
} from "react";
|
|
19
29
|
import {
|
|
20
30
|
type AccessibilityActionEvent,
|
|
21
31
|
type GestureResponderEvent,
|
|
@@ -44,6 +54,7 @@ import Animated, {
|
|
|
44
54
|
import { useCalendarTheme } from "../theme";
|
|
45
55
|
import type {
|
|
46
56
|
BusinessHours,
|
|
57
|
+
BusinessHoursBand,
|
|
47
58
|
CalendarEvent,
|
|
48
59
|
CalendarMode,
|
|
49
60
|
EventKeyExtractor,
|
|
@@ -59,8 +70,11 @@ import {
|
|
|
59
70
|
viewDayCount,
|
|
60
71
|
} from "@super-calendar/core";
|
|
61
72
|
import {
|
|
73
|
+
backgroundBandsForDay,
|
|
62
74
|
cellRangeFromDrag,
|
|
75
|
+
useNow,
|
|
63
76
|
closedHourBands,
|
|
77
|
+
pageStepDays,
|
|
64
78
|
resolveDraggedBounds,
|
|
65
79
|
snapDeltaMinutes,
|
|
66
80
|
} from "@super-calendar/core";
|
|
@@ -121,6 +135,87 @@ const DRAG_ACTIVATE_PX = 8;
|
|
|
121
135
|
const RESIZE_HANDLE_HEIGHT = 14;
|
|
122
136
|
// Default minutes a drag snaps to when `dragStepMinutes` isn't set.
|
|
123
137
|
const DEFAULT_DRAG_STEP_MINUTES = 15;
|
|
138
|
+
// zIndex applied to an event while it's being dragged/resized so it sits above
|
|
139
|
+
// every other event (RN stacks siblings by order, so without this a dragged box
|
|
140
|
+
// moved over a later event would fall behind it).
|
|
141
|
+
const DRAG_EVENT_Z = 100;
|
|
142
|
+
// How long to hold the dragged event past the visible columns before the view
|
|
143
|
+
// pages one period toward that edge.
|
|
144
|
+
const EDGE_DWELL_MS = 500;
|
|
145
|
+
// How close (px) the dragging finger must get to the pager's left/right edge to
|
|
146
|
+
// count as "past the columns". Detecting by finger position, not by how many
|
|
147
|
+
// columns the drag has crossed, so an event in any column can reach either edge
|
|
148
|
+
// (a column-delta test can't reach the far edge from a near-side column).
|
|
149
|
+
const EDGE_ZONE_PX = 36;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Lets a per-event drag worklet, deep inside the pager, drive a cross-week drag:
|
|
153
|
+
* locate the pager's edges, freeze the swipe scroll while paging (a native
|
|
154
|
+
* programmatic scroll is otherwise deferred until the touch ends, so the view
|
|
155
|
+
* would only advance once the finger lifts), and hand the event off to a floating
|
|
156
|
+
* ghost that survives the source page paging away, then commit on release.
|
|
157
|
+
*/
|
|
158
|
+
type EdgePaging = {
|
|
159
|
+
// Pager frame in window space, so the worklet can find the edges and place the
|
|
160
|
+
// ghost (its top-left is the window origin the finger coords are relative to).
|
|
161
|
+
pagerLeft: SharedValue<number>;
|
|
162
|
+
pagerTop: SharedValue<number>;
|
|
163
|
+
pagerWidth: SharedValue<number>;
|
|
164
|
+
lockScroll: (locked: boolean) => void;
|
|
165
|
+
// The floating "held" copy of the dragged event: pager-local top-left, size, and
|
|
166
|
+
// visibility, driven on the UI thread so it tracks the finger across the page.
|
|
167
|
+
ghostX: SharedValue<number>;
|
|
168
|
+
ghostY: SharedValue<number>;
|
|
169
|
+
ghostW: SharedValue<number>;
|
|
170
|
+
ghostH: SharedValue<number>;
|
|
171
|
+
ghostVisible: SharedValue<number>;
|
|
172
|
+
// Show the ghost for `event`, then drop it at pager-local `ghostLocalX` shifted
|
|
173
|
+
// in time by `minuteDelta` (clearing the ghost either way).
|
|
174
|
+
beginLift: (event: CalendarEvent<unknown>) => void;
|
|
175
|
+
commitLiftedDrop: (ghostLocalX: number, minuteDelta: number) => void;
|
|
176
|
+
};
|
|
177
|
+
const EdgePagingContext = createContext<EdgePaging | null>(null);
|
|
178
|
+
|
|
179
|
+
const noop = () => {};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The floating copy of a dragged event, rendered above the pager so a cross-week
|
|
183
|
+
* drag stays visible after its source page pages away. Position, size, and
|
|
184
|
+
* visibility are driven on the UI thread by the shared values so it tracks the
|
|
185
|
+
* finger without a React re-render.
|
|
186
|
+
*/
|
|
187
|
+
function DragGhost<T>({
|
|
188
|
+
x,
|
|
189
|
+
y,
|
|
190
|
+
w,
|
|
191
|
+
h,
|
|
192
|
+
visible,
|
|
193
|
+
event,
|
|
194
|
+
mode,
|
|
195
|
+
renderEvent,
|
|
196
|
+
}: {
|
|
197
|
+
x: SharedValue<number>;
|
|
198
|
+
y: SharedValue<number>;
|
|
199
|
+
w: SharedValue<number>;
|
|
200
|
+
h: SharedValue<number>;
|
|
201
|
+
visible: SharedValue<number>;
|
|
202
|
+
event: CalendarEvent<T>;
|
|
203
|
+
mode: CalendarMode;
|
|
204
|
+
renderEvent: RenderEvent<T>;
|
|
205
|
+
}): ReactElement {
|
|
206
|
+
const RenderEventComponent = renderEvent;
|
|
207
|
+
const style = useAnimatedStyle(() => ({
|
|
208
|
+
transform: [{ translateX: x.value }, { translateY: y.value }],
|
|
209
|
+
width: w.value,
|
|
210
|
+
height: h.value,
|
|
211
|
+
opacity: visible.value,
|
|
212
|
+
}));
|
|
213
|
+
return (
|
|
214
|
+
<Animated.View style={[styles.eventBox, styles.dragGhost, style]} pointerEvents="none">
|
|
215
|
+
<RenderEventComponent event={event} mode={mode} boxHeight={h} onPress={noop} />
|
|
216
|
+
</Animated.View>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
124
219
|
|
|
125
220
|
/**
|
|
126
221
|
* Called when an event is dragged (moved or resized) to new start/end times.
|
|
@@ -143,21 +238,6 @@ export type EventDragStartHandler<T> = (event: CalendarEvent<T>) => void;
|
|
|
143
238
|
// scroll content by the same amount so the top-most label is never clipped.
|
|
144
239
|
const HOUR_LABEL_TOP_INSET = 12;
|
|
145
240
|
const HOUR_LABEL_NUDGE = 6;
|
|
146
|
-
const NOW_TICK_MS = 60_000;
|
|
147
|
-
|
|
148
|
-
// A `Date` that advances every minute while `enabled`, so the now-indicator
|
|
149
|
-
// tracks the wall clock instead of freezing at mount. Off-screen pages pass
|
|
150
|
-
// `enabled = false` and re-read the time when they become active.
|
|
151
|
-
function useNow(enabled: boolean): Date {
|
|
152
|
-
const [now, setNow] = useState(() => new Date());
|
|
153
|
-
useEffect(() => {
|
|
154
|
-
if (!enabled) return;
|
|
155
|
-
setNow(new Date());
|
|
156
|
-
const id = setInterval(() => setNow(new Date()), NOW_TICK_MS);
|
|
157
|
-
return () => clearInterval(id);
|
|
158
|
-
}, [enabled]);
|
|
159
|
-
return now;
|
|
160
|
-
}
|
|
161
241
|
|
|
162
242
|
type AnimatedEventBoxProps<T> = {
|
|
163
243
|
positioned: PositionedEvent<T>;
|
|
@@ -170,7 +250,14 @@ type AnimatedEventBoxProps<T> = {
|
|
|
170
250
|
dayWidth: number;
|
|
171
251
|
dayIndex: number;
|
|
172
252
|
dayCount: number;
|
|
253
|
+
// Calendar-day offset of each visible column from the first (plain numbers, so
|
|
254
|
+
// the worklet can close over them). Lets a cross-day move map a column delta to
|
|
255
|
+
// the right calendar-day delta when hiddenDays makes the columns non-contiguous.
|
|
256
|
+
dayOrdinals: number[];
|
|
173
257
|
mode: CalendarMode;
|
|
258
|
+
// Calendar days one page spans, for the "move to next/previous page" screen-
|
|
259
|
+
// reader actions (the accessible equivalent of dragging an event to the edge).
|
|
260
|
+
daysPerPage: number;
|
|
174
261
|
renderEvent: RenderEvent<T>;
|
|
175
262
|
snapMinutes: number;
|
|
176
263
|
onPress: (event: CalendarEvent<T>) => void;
|
|
@@ -178,6 +265,9 @@ type AnimatedEventBoxProps<T> = {
|
|
|
178
265
|
onDragEvent?: EventDragHandler<T>;
|
|
179
266
|
onDragStart?: EventDragStartHandler<T>;
|
|
180
267
|
showDragHandle: boolean;
|
|
268
|
+
// Page the view one period (dir -1/+1) when the event is dragged past the
|
|
269
|
+
// visible columns and held there. Absent disables edge auto-advance.
|
|
270
|
+
onEdgeAdvance?: (dir: number) => void;
|
|
181
271
|
};
|
|
182
272
|
|
|
183
273
|
function AnimatedEventBox<T>({
|
|
@@ -189,22 +279,38 @@ function AnimatedEventBox<T>({
|
|
|
189
279
|
dayWidth,
|
|
190
280
|
dayIndex,
|
|
191
281
|
dayCount,
|
|
282
|
+
dayOrdinals,
|
|
192
283
|
mode,
|
|
284
|
+
daysPerPage,
|
|
193
285
|
renderEvent,
|
|
194
286
|
snapMinutes,
|
|
195
287
|
onPress,
|
|
196
288
|
onLongPress,
|
|
197
289
|
onDragEvent,
|
|
198
290
|
onDragStart,
|
|
291
|
+
onEdgeAdvance,
|
|
199
292
|
showDragHandle,
|
|
200
293
|
}: AnimatedEventBoxProps<T>) {
|
|
201
294
|
const RenderEventComponent = renderEvent;
|
|
202
295
|
const theme = useCalendarTheme();
|
|
203
296
|
const slot = useSlots<TimeGridSlot>();
|
|
297
|
+
// Pager geometry + scroll lock, so a cross-week edge drag can find the edges
|
|
298
|
+
// and page the view live under the finger (see EdgePaging). The two edge
|
|
299
|
+
// shared values are pulled out so the move worklet closes over them directly
|
|
300
|
+
// rather than over the whole context object (which also holds a JS callback).
|
|
301
|
+
const edgePaging = useContext(EdgePagingContext);
|
|
302
|
+
const pagerLeftSV = edgePaging?.pagerLeft;
|
|
303
|
+
const pagerTopSV = edgePaging?.pagerTop;
|
|
304
|
+
const pagerWidthSV = edgePaging?.pagerWidth;
|
|
305
|
+
const ghostXSV = edgePaging?.ghostX;
|
|
306
|
+
const ghostYSV = edgePaging?.ghostY;
|
|
307
|
+
const commitLiftedDrop = edgePaging?.commitLiftedDrop;
|
|
204
308
|
// Drag-to-move/resize. Native picks the event up on long-press (so a tap or
|
|
205
309
|
// scroll isn't hijacked); web activates after a small drag threshold, so a
|
|
206
310
|
// plain click still selects and a right-click still opens a context menu.
|
|
207
|
-
|
|
311
|
+
// `draggable: false` locks a single event (keeps taps, blocks move/resize).
|
|
312
|
+
const draggable =
|
|
313
|
+
onDragEvent != null && !positioned.event.disabled && positioned.event.draggable !== false;
|
|
208
314
|
// Only the segment that owns the real end may be resized.
|
|
209
315
|
const resizable = draggable && !positioned.continuesAfter;
|
|
210
316
|
|
|
@@ -213,6 +319,20 @@ function AnimatedEventBox<T>({
|
|
|
213
319
|
const moveOffset = useSharedValue(0);
|
|
214
320
|
const moveOffsetX = useSharedValue(0);
|
|
215
321
|
const resizeDelta = useSharedValue(0);
|
|
322
|
+
// Raised to DRAG_EVENT_Z while a gesture is active so the dragged event floats
|
|
323
|
+
// above all the others, then back to 0 when it settles.
|
|
324
|
+
const dragZ = useSharedValue(0);
|
|
325
|
+
// Edge auto-advance: which side the drag has pushed past the visible columns
|
|
326
|
+
// (-1 left / 0 none / +1 right).
|
|
327
|
+
const edgeDir = useSharedValue(0);
|
|
328
|
+
// 1 once the event has been lifted into the floating ghost (cross-week drag),
|
|
329
|
+
// plus where in the box it was grabbed and the live finger position, so the
|
|
330
|
+
// ghost can be seeded from the JS dwell timer and track the finger after.
|
|
331
|
+
const lifted = useSharedValue(0);
|
|
332
|
+
const grabX = useSharedValue(0);
|
|
333
|
+
const grabY = useSharedValue(0);
|
|
334
|
+
const liveAbsX = useSharedValue(0);
|
|
335
|
+
const liveAbsY = useSharedValue(0);
|
|
216
336
|
|
|
217
337
|
// Pull the geometry out as primitives so the worklets below close over plain
|
|
218
338
|
// numbers, not `positioned` itself. Referencing `positioned.*` inside a
|
|
@@ -236,6 +356,7 @@ function AnimatedEventBox<T>({
|
|
|
236
356
|
top: (startHours - minHour) * cellHeight.value + moveOffset.value,
|
|
237
357
|
height: boxHeight.value,
|
|
238
358
|
transform: [{ translateX: moveOffsetX.value }],
|
|
359
|
+
zIndex: dragZ.value,
|
|
239
360
|
}),
|
|
240
361
|
[startHours, durationHours, minHour],
|
|
241
362
|
);
|
|
@@ -297,17 +418,112 @@ function AnimatedEventBox<T>({
|
|
|
297
418
|
latest.current.onDragStart?.(latest.current.event);
|
|
298
419
|
}, []);
|
|
299
420
|
|
|
421
|
+
// Edge auto-advance dwell. Dragging the event past the visible columns and
|
|
422
|
+
// holding there pages the view one period and carries the event onto it: same
|
|
423
|
+
// weekday, keeping whatever time the vertical drag has reached. It fires once
|
|
424
|
+
// per drag (the box unmounts as the page changes), matching "hold at the edge
|
|
425
|
+
// to move to the next/previous week"; the tested commit path does the move.
|
|
426
|
+
const dwellTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
427
|
+
const disarmEdge = useCallback(() => {
|
|
428
|
+
if (dwellTimer.current) {
|
|
429
|
+
clearTimeout(dwellTimer.current);
|
|
430
|
+
dwellTimer.current = null;
|
|
431
|
+
}
|
|
432
|
+
}, []);
|
|
433
|
+
// Cancel a pending dwell and hand the pager's swipe scroll back. Runs on every
|
|
434
|
+
// gesture end so a lock taken by an edge-page is always released.
|
|
435
|
+
const releaseEdge = useCallback(() => {
|
|
436
|
+
disarmEdge();
|
|
437
|
+
edgePaging?.lockScroll(false);
|
|
438
|
+
}, [disarmEdge, edgePaging]);
|
|
439
|
+
const armEdge = useCallback(
|
|
440
|
+
(dir: number) => {
|
|
441
|
+
disarmEdge();
|
|
442
|
+
dwellTimer.current = setTimeout(() => {
|
|
443
|
+
dwellTimer.current = null;
|
|
444
|
+
if (!edgePaging) return;
|
|
445
|
+
// Freeze the pager's own swipe before paging: on native a programmatic
|
|
446
|
+
// scroll is deferred while the touch is tracked, so without this the view
|
|
447
|
+
// wouldn't advance until the finger lifts.
|
|
448
|
+
edgePaging.lockScroll(true);
|
|
449
|
+
// First edge fire: lift the event into the floating ghost. It must NOT
|
|
450
|
+
// commit here — committing relocates the event off this page, which
|
|
451
|
+
// unmounts the dragging box and kills the gesture. Instead the ghost
|
|
452
|
+
// (seeded at the current finger position) carries the event across the
|
|
453
|
+
// page, and the drop commits on release. The source box stays mounted, so
|
|
454
|
+
// the same gesture keeps tracking after the page changes.
|
|
455
|
+
if (!lifted.value) {
|
|
456
|
+
lifted.value = 1;
|
|
457
|
+
edgePaging.ghostW.value = width;
|
|
458
|
+
edgePaging.ghostH.value = boxHeight.value;
|
|
459
|
+
edgePaging.ghostX.value = liveAbsX.value - grabX.value - edgePaging.pagerLeft.value;
|
|
460
|
+
edgePaging.ghostY.value = liveAbsY.value - grabY.value - edgePaging.pagerTop.value;
|
|
461
|
+
edgePaging.ghostVisible.value = 1;
|
|
462
|
+
edgePaging.beginLift(latest.current.event as CalendarEvent<unknown>);
|
|
463
|
+
}
|
|
464
|
+
onEdgeAdvance?.(dir);
|
|
465
|
+
}, EDGE_DWELL_MS);
|
|
466
|
+
},
|
|
467
|
+
[
|
|
468
|
+
disarmEdge,
|
|
469
|
+
edgePaging,
|
|
470
|
+
lifted,
|
|
471
|
+
width,
|
|
472
|
+
boxHeight,
|
|
473
|
+
liveAbsX,
|
|
474
|
+
liveAbsY,
|
|
475
|
+
grabX,
|
|
476
|
+
grabY,
|
|
477
|
+
onEdgeAdvance,
|
|
478
|
+
],
|
|
479
|
+
);
|
|
480
|
+
|
|
300
481
|
const moveGesture = useMemo(() => {
|
|
301
482
|
const pan = Gesture.Pan()
|
|
302
483
|
.enabled(draggable)
|
|
303
|
-
.onStart(() => {
|
|
484
|
+
.onStart((event) => {
|
|
485
|
+
dragZ.value = DRAG_EVENT_Z;
|
|
486
|
+
edgeDir.value = 0;
|
|
487
|
+
lifted.value = 0;
|
|
488
|
+
// Where in the box the finger grabbed, and the live finger position, so
|
|
489
|
+
// the ghost can be seeded and tracked in window space (see armEdge).
|
|
490
|
+
grabX.value = event.x;
|
|
491
|
+
grabY.value = event.y;
|
|
492
|
+
liveAbsX.value = event.absoluteX;
|
|
493
|
+
liveAbsY.value = event.absoluteY;
|
|
304
494
|
runOnJS(notifyDragStart)();
|
|
305
495
|
})
|
|
306
496
|
.onUpdate((event) => {
|
|
307
|
-
|
|
308
|
-
|
|
497
|
+
liveAbsX.value = event.absoluteX;
|
|
498
|
+
liveAbsY.value = event.absoluteY;
|
|
499
|
+
// Once lifted, the box itself has paged off-screen; the ghost (a sibling of
|
|
500
|
+
// the pager) tracks the finger in pager-local space instead.
|
|
501
|
+
if (lifted.value && pagerLeftSV && pagerTopSV && ghostXSV && ghostYSV) {
|
|
502
|
+
ghostXSV.value = event.absoluteX - grabX.value - pagerLeftSV.value;
|
|
503
|
+
ghostYSV.value = event.absoluteY - grabY.value - pagerTopSV.value;
|
|
504
|
+
} else {
|
|
505
|
+
moveOffset.value = event.translationY;
|
|
506
|
+
moveOffsetX.value = event.translationX;
|
|
507
|
+
}
|
|
508
|
+
// Dragging the finger to the pager's left/right edge arms an edge dwell
|
|
509
|
+
// that pages the view. Measured by absolute finger position (not by how
|
|
510
|
+
// many columns the drag crossed), so an event in any column can reach
|
|
511
|
+
// either edge. `onEdgeAdvance` is only wired when paging is available.
|
|
512
|
+
if (onEdgeAdvance && pagerLeftSV && pagerWidthSV) {
|
|
513
|
+
const fx = event.absoluteX - pagerLeftSV.value;
|
|
514
|
+
const dir = fx > pagerWidthSV.value - EDGE_ZONE_PX ? 1 : fx < EDGE_ZONE_PX ? -1 : 0;
|
|
515
|
+
if (dir !== edgeDir.value) {
|
|
516
|
+
edgeDir.value = dir;
|
|
517
|
+
if (dir === 0) runOnJS(disarmEdge)();
|
|
518
|
+
else runOnJS(armEdge)(dir);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
309
521
|
})
|
|
310
522
|
.onEnd((event) => {
|
|
523
|
+
// A cross-week drag is committed in onFinalize (which fires whether the
|
|
524
|
+
// gesture ends cleanly or is cancelled as the page moves under it), so the
|
|
525
|
+
// drop lands even when onEnd doesn't fire on device. Nothing to do here.
|
|
526
|
+
if (lifted.value) return;
|
|
311
527
|
const minuteDelta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
|
|
312
528
|
// Map the horizontal drag to whole day columns, clamped so the event
|
|
313
529
|
// can't leave the visible range.
|
|
@@ -323,10 +539,27 @@ function AnimatedEventBox<T>({
|
|
|
323
539
|
// original before the committed re-render lands.
|
|
324
540
|
moveOffset.value = (minuteDelta / MINUTES_PER_HOUR) * cellHeight.value;
|
|
325
541
|
moveOffsetX.value = dayDelta * dayWidth;
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
|
|
542
|
+
// Map the column shift to a calendar-day shift: with hiddenDays the
|
|
543
|
+
// columns aren't contiguous days, so a one-column move can span several
|
|
544
|
+
// calendar days. Fold that into the minute delta; shiftMinutes carries it
|
|
545
|
+
// into the date, so both edges move together and the duration is preserved.
|
|
546
|
+
const calendarDayDelta = dayOrdinals[targetDay] - dayOrdinals[dayIndex];
|
|
547
|
+
const totalDelta = minuteDelta + calendarDayDelta * MINUTES_PER_DAY;
|
|
329
548
|
runOnJS(commitDrag)(totalDelta, totalDelta);
|
|
549
|
+
})
|
|
550
|
+
.onFinalize(() => {
|
|
551
|
+
dragZ.value = 0;
|
|
552
|
+
// Commit the cross-week drop here: onFinalize fires on every gesture end,
|
|
553
|
+
// including the cancel RNGH reports when the source page moves under the
|
|
554
|
+
// touch, so committing from the last finger position (ghost column + the
|
|
555
|
+
// vertical drag) guarantees the drop lands instead of silently vanishing.
|
|
556
|
+
if (lifted.value && ghostXSV && ghostYSV && commitLiftedDrop) {
|
|
557
|
+
runOnJS(commitLiftedDrop)(ghostXSV.value, ghostYSV.value);
|
|
558
|
+
moveOffset.value = 0;
|
|
559
|
+
moveOffsetX.value = 0;
|
|
560
|
+
lifted.value = 0;
|
|
561
|
+
}
|
|
562
|
+
runOnJS(releaseEdge)();
|
|
330
563
|
});
|
|
331
564
|
// Native: long-press to pick up. Web: activate past a small drag in either
|
|
332
565
|
// axis so clicks/right-clicks pass through but horizontal drags still move.
|
|
@@ -341,11 +574,29 @@ function AnimatedEventBox<T>({
|
|
|
341
574
|
cellHeight,
|
|
342
575
|
moveOffset,
|
|
343
576
|
moveOffsetX,
|
|
577
|
+
dragZ,
|
|
578
|
+
edgeDir,
|
|
579
|
+
lifted,
|
|
580
|
+
grabX,
|
|
581
|
+
grabY,
|
|
582
|
+
liveAbsX,
|
|
583
|
+
liveAbsY,
|
|
584
|
+
pagerLeftSV,
|
|
585
|
+
pagerTopSV,
|
|
586
|
+
pagerWidthSV,
|
|
587
|
+
ghostXSV,
|
|
588
|
+
ghostYSV,
|
|
589
|
+
commitLiftedDrop,
|
|
344
590
|
dayWidth,
|
|
345
591
|
dayIndex,
|
|
346
592
|
dayCount,
|
|
593
|
+
dayOrdinals,
|
|
347
594
|
commitDrag,
|
|
348
595
|
notifyDragStart,
|
|
596
|
+
onEdgeAdvance,
|
|
597
|
+
armEdge,
|
|
598
|
+
disarmEdge,
|
|
599
|
+
releaseEdge,
|
|
349
600
|
]);
|
|
350
601
|
|
|
351
602
|
const resizeGesture = useMemo(
|
|
@@ -353,6 +604,7 @@ function AnimatedEventBox<T>({
|
|
|
353
604
|
Gesture.Pan()
|
|
354
605
|
.enabled(resizable)
|
|
355
606
|
.onStart(() => {
|
|
607
|
+
dragZ.value = DRAG_EVENT_Z;
|
|
356
608
|
runOnJS(notifyDragStart)();
|
|
357
609
|
})
|
|
358
610
|
.onUpdate((event) => {
|
|
@@ -366,8 +618,11 @@ function AnimatedEventBox<T>({
|
|
|
366
618
|
}
|
|
367
619
|
resizeDelta.value = (delta / MINUTES_PER_HOUR) * cellHeight.value;
|
|
368
620
|
runOnJS(commitDrag)(0, delta);
|
|
621
|
+
})
|
|
622
|
+
.onFinalize(() => {
|
|
623
|
+
dragZ.value = 0;
|
|
369
624
|
}),
|
|
370
|
-
[resizable, snapMinutes, cellHeight, resizeDelta, commitDrag, notifyDragStart],
|
|
625
|
+
[resizable, snapMinutes, cellHeight, resizeDelta, dragZ, commitDrag, notifyDragStart],
|
|
371
626
|
);
|
|
372
627
|
|
|
373
628
|
const handlePress = () => onPress(positioned.event);
|
|
@@ -380,6 +635,13 @@ function AnimatedEventBox<T>({
|
|
|
380
635
|
// discrete screen-reader actions (VoiceOver/TalkBack invoke them from the
|
|
381
636
|
// actions menu). Steps are one `snapMinutes` unit, matching a drag snap.
|
|
382
637
|
const unit = (n: number) => `${n} minute${n === 1 ? "" : "s"}`;
|
|
638
|
+
// Label the whole-page move by what a page means in this mode.
|
|
639
|
+
const pageUnit =
|
|
640
|
+
mode === "week"
|
|
641
|
+
? "week"
|
|
642
|
+
: daysPerPage === 1
|
|
643
|
+
? "day"
|
|
644
|
+
: `${daysPerPage} day${daysPerPage === 1 ? "" : "s"}`;
|
|
383
645
|
const accessibilityActions = draggable
|
|
384
646
|
? [
|
|
385
647
|
{ name: "move-later", label: `Move ${unit(snapMinutes)} later` },
|
|
@@ -390,6 +652,8 @@ function AnimatedEventBox<T>({
|
|
|
390
652
|
{ name: "shrink", label: `Shorten by ${unit(snapMinutes)}` },
|
|
391
653
|
]
|
|
392
654
|
: []),
|
|
655
|
+
{ name: "move-next-page", label: `Move to next ${pageUnit}` },
|
|
656
|
+
{ name: "move-previous-page", label: `Move to previous ${pageUnit}` },
|
|
393
657
|
]
|
|
394
658
|
: undefined;
|
|
395
659
|
const handleAccessibilityAction = draggable
|
|
@@ -407,6 +671,12 @@ function AnimatedEventBox<T>({
|
|
|
407
671
|
case "shrink":
|
|
408
672
|
commitDrag(0, -snapMinutes);
|
|
409
673
|
break;
|
|
674
|
+
case "move-next-page":
|
|
675
|
+
commitDrag(daysPerPage * MINUTES_PER_DAY, daysPerPage * MINUTES_PER_DAY);
|
|
676
|
+
break;
|
|
677
|
+
case "move-previous-page":
|
|
678
|
+
commitDrag(-daysPerPage * MINUTES_PER_DAY, -daysPerPage * MINUTES_PER_DAY);
|
|
679
|
+
break;
|
|
410
680
|
}
|
|
411
681
|
}
|
|
412
682
|
: undefined;
|
|
@@ -563,7 +833,12 @@ type ShadeBandProps = {
|
|
|
563
833
|
minHour: number;
|
|
564
834
|
left: number;
|
|
565
835
|
width: number;
|
|
566
|
-
|
|
836
|
+
/** Themed fill. Omit when a render override owns the band's look. */
|
|
837
|
+
color?: string;
|
|
838
|
+
/** Which slot/testID the band belongs to (closed hours vs background events). */
|
|
839
|
+
slotName?: "businessHours" | "backgroundEvent";
|
|
840
|
+
testID?: string;
|
|
841
|
+
children?: React.ReactNode;
|
|
567
842
|
};
|
|
568
843
|
|
|
569
844
|
// A muted band over a closed hour-range of one day column (driven by the live
|
|
@@ -576,6 +851,9 @@ const ShadeBand = ({
|
|
|
576
851
|
left,
|
|
577
852
|
width,
|
|
578
853
|
color,
|
|
854
|
+
slotName = "businessHours",
|
|
855
|
+
testID = "business-hours-shade",
|
|
856
|
+
children,
|
|
579
857
|
}: ShadeBandProps) => {
|
|
580
858
|
const slot = useSlots<TimeGridSlot>();
|
|
581
859
|
const animatedStyle = useAnimatedStyle(
|
|
@@ -585,22 +863,30 @@ const ShadeBand = ({
|
|
|
585
863
|
}),
|
|
586
864
|
[startHour, endHour, minHour],
|
|
587
865
|
);
|
|
588
|
-
const bandSlot = slot(
|
|
866
|
+
const bandSlot = slot(slotName, {
|
|
589
867
|
base: [styles.shadeBand, styles.nonInteractive, { left, width }],
|
|
590
|
-
themed: { backgroundColor: color },
|
|
868
|
+
themed: color === undefined ? undefined : { backgroundColor: color },
|
|
591
869
|
});
|
|
592
870
|
return (
|
|
593
871
|
<Animated.View
|
|
594
|
-
testID=
|
|
872
|
+
testID={testID}
|
|
873
|
+
// Decorative, like the dom bands' aria-hidden: never announced or focused.
|
|
874
|
+
accessibilityElementsHidden
|
|
875
|
+
importantForAccessibility="no-hide-descendants"
|
|
595
876
|
{...bandSlot}
|
|
596
877
|
style={[bandSlot.style, animatedStyle]}
|
|
597
|
-
|
|
878
|
+
>
|
|
879
|
+
{children}
|
|
880
|
+
</Animated.View>
|
|
598
881
|
);
|
|
599
882
|
};
|
|
600
883
|
|
|
601
884
|
type TimetablePageProps<T> = {
|
|
602
885
|
mode: TimeGridMode;
|
|
603
886
|
numberOfDays: number;
|
|
887
|
+
hiddenDays?: number[];
|
|
888
|
+
now?: Date;
|
|
889
|
+
nowTimeZone?: string;
|
|
604
890
|
date: Date;
|
|
605
891
|
events: CalendarEvent<T>[];
|
|
606
892
|
cellHeight: SharedValue<number>;
|
|
@@ -627,11 +913,13 @@ type TimetablePageProps<T> = {
|
|
|
627
913
|
timeslots: number;
|
|
628
914
|
isRTL: boolean;
|
|
629
915
|
showAllDayEventCell: boolean;
|
|
916
|
+
highlightWeekends: boolean;
|
|
630
917
|
showVerticalScrollIndicator: boolean;
|
|
631
918
|
verticalScrollEnabled: boolean;
|
|
632
919
|
hourComponent?: HourRenderer;
|
|
633
920
|
calendarCellStyle?: (date: Date) => StyleProp<ViewStyle>;
|
|
634
921
|
businessHours?: BusinessHours;
|
|
922
|
+
renderBusinessHours?: (band: BusinessHoursBand) => React.ReactNode;
|
|
635
923
|
minHourHeight: number;
|
|
636
924
|
maxHourHeight: number;
|
|
637
925
|
showNowIndicator: boolean;
|
|
@@ -646,6 +934,10 @@ type TimetablePageProps<T> = {
|
|
|
646
934
|
onPressCell?: (date: Date) => void;
|
|
647
935
|
onLongPressCell?: (date: Date) => void;
|
|
648
936
|
onCreateEvent?: (start: Date, end: Date) => void;
|
|
937
|
+
onEdgeAdvance?: (dir: number) => void;
|
|
938
|
+
/** Report this page's hour-grid top (below the all-day lane), while it is the
|
|
939
|
+
* active page, so a cross-week drop can map a ghost's Y to the right time. */
|
|
940
|
+
onGridTop?: (y: number) => void;
|
|
649
941
|
};
|
|
650
942
|
|
|
651
943
|
// A single date's grid: the pinch-zoomable, vertically-scrolling time column.
|
|
@@ -654,6 +946,9 @@ type TimetablePageProps<T> = {
|
|
|
654
946
|
function TimetablePageInner<T>({
|
|
655
947
|
mode,
|
|
656
948
|
numberOfDays,
|
|
949
|
+
hiddenDays,
|
|
950
|
+
now: nowProp,
|
|
951
|
+
nowTimeZone,
|
|
657
952
|
date,
|
|
658
953
|
events,
|
|
659
954
|
cellHeight,
|
|
@@ -673,6 +968,7 @@ function TimetablePageInner<T>({
|
|
|
673
968
|
timeslots,
|
|
674
969
|
isRTL,
|
|
675
970
|
showAllDayEventCell,
|
|
971
|
+
highlightWeekends,
|
|
676
972
|
showVerticalScrollIndicator,
|
|
677
973
|
verticalScrollEnabled,
|
|
678
974
|
hourComponent,
|
|
@@ -681,6 +977,7 @@ function TimetablePageInner<T>({
|
|
|
681
977
|
maxHourHeight,
|
|
682
978
|
showNowIndicator,
|
|
683
979
|
businessHours,
|
|
980
|
+
renderBusinessHours,
|
|
684
981
|
renderEvent,
|
|
685
982
|
keyExtractor,
|
|
686
983
|
snapMinutes,
|
|
@@ -692,10 +989,18 @@ function TimetablePageInner<T>({
|
|
|
692
989
|
onPressCell,
|
|
693
990
|
onLongPressCell,
|
|
694
991
|
onCreateEvent,
|
|
992
|
+
onEdgeAdvance,
|
|
993
|
+
onGridTop,
|
|
695
994
|
}: TimetablePageProps<T>) {
|
|
696
995
|
const theme = useCalendarTheme();
|
|
697
996
|
const slot = useSlots<TimeGridSlot>();
|
|
698
997
|
const scrollRef = useAnimatedRef<Animated.ScrollView>();
|
|
998
|
+
// The hour grid sits below the all-day lane; capture its top on layout and
|
|
999
|
+
// report it up while this page is active (the lane height differs per week).
|
|
1000
|
+
const gridTopRef = useRef(0);
|
|
1001
|
+
useEffect(() => {
|
|
1002
|
+
if (isActive) onGridTop?.(gridTopRef.current);
|
|
1003
|
+
}, [isActive, onGridTop]);
|
|
699
1004
|
|
|
700
1005
|
// The visible page tracks the live cellHeight (animates every pinch frame);
|
|
701
1006
|
// off-screen pages track committedCellHeight (settles once per gesture).
|
|
@@ -782,9 +1087,12 @@ function TimetablePageInner<T>({
|
|
|
782
1087
|
);
|
|
783
1088
|
|
|
784
1089
|
const days = useMemo(
|
|
785
|
-
() => getViewDays(mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn),
|
|
786
|
-
[mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn],
|
|
1090
|
+
() => getViewDays(mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays),
|
|
1091
|
+
[mode, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays],
|
|
787
1092
|
);
|
|
1093
|
+
// Calendar days one page spans (7 for week, the column count otherwise), for
|
|
1094
|
+
// the "move to next/previous page" screen-reader actions.
|
|
1095
|
+
const daysPerPage = pageStepDays(mode, date, weekStartsOn, numberOfDays);
|
|
788
1096
|
|
|
789
1097
|
// Plain number for worklets to close over: reading `days.length` inside a
|
|
790
1098
|
// gesture worklet would capture the whole `days` array (of `Date`s), which
|
|
@@ -793,6 +1101,15 @@ function TimetablePageInner<T>({
|
|
|
793
1101
|
const dayWidth = (width - hourColumnWidth) / dayCount;
|
|
794
1102
|
const dayLeft = (dayIndex: number) => hourColumnWidth + dayIndex * dayWidth;
|
|
795
1103
|
|
|
1104
|
+
// Calendar-day offset of each column from the first, as plain numbers a drag
|
|
1105
|
+
// worklet can close over. Identity (0,1,2,…) for contiguous days; with
|
|
1106
|
+
// hiddenDays the gaps widen, so a cross-day move shifts by the right number of
|
|
1107
|
+
// calendar days. Signed correctly for RTL (columns run high→low).
|
|
1108
|
+
const dayOrdinals = useMemo(
|
|
1109
|
+
() => days.map((day) => differenceInCalendarDays(day, days[0])),
|
|
1110
|
+
[days],
|
|
1111
|
+
);
|
|
1112
|
+
|
|
796
1113
|
const dayLayouts = useMemo(() => days.map((day) => layoutDayEvents(events, day)), [days, events]);
|
|
797
1114
|
|
|
798
1115
|
// Map a tap on empty grid space back to the date+time it represents. Reads the
|
|
@@ -823,8 +1140,10 @@ function TimetablePageInner<T>({
|
|
|
823
1140
|
[minHour, maxHour],
|
|
824
1141
|
);
|
|
825
1142
|
|
|
826
|
-
const now = useNow(showNowIndicator && isActive);
|
|
827
|
-
|
|
1143
|
+
const now = useNow(showNowIndicator && isActive, { now: nowProp, timeZone: nowTimeZone });
|
|
1144
|
+
// "Today" follows the (possibly zone-shifted or overridden) now, so the line
|
|
1145
|
+
// lands in the column the events are displayed in.
|
|
1146
|
+
const nowDayIndex = days.findIndex((day) => isSameCalendarDay(day, now));
|
|
828
1147
|
const nowHours = (getHours(now) * MINUTES_PER_HOUR + getMinutes(now)) / MINUTES_PER_HOUR;
|
|
829
1148
|
const nowInWindow = nowHours >= minHour && nowHours <= maxHour;
|
|
830
1149
|
|
|
@@ -1049,6 +1368,12 @@ function TimetablePageInner<T>({
|
|
|
1049
1368
|
scrollEnabled={verticalScrollEnabled}
|
|
1050
1369
|
onScroll={scrollHandler}
|
|
1051
1370
|
scrollEventThrottle={16}
|
|
1371
|
+
onLayout={(event) => {
|
|
1372
|
+
// The scroll view's offset within the page equals the all-day lane
|
|
1373
|
+
// height above it: the hour grid's top. Report it while active.
|
|
1374
|
+
gridTopRef.current = event.nativeEvent.layout.y;
|
|
1375
|
+
if (isActive) onGridTop?.(gridTopRef.current);
|
|
1376
|
+
}}
|
|
1052
1377
|
contentContainerStyle={{ paddingTop: HOUR_LABEL_TOP_INSET }}
|
|
1053
1378
|
contentOffset={{ x: 0, y: initialScrollY }}
|
|
1054
1379
|
>
|
|
@@ -1062,7 +1387,7 @@ function TimetablePageInner<T>({
|
|
|
1062
1387
|
)}
|
|
1063
1388
|
|
|
1064
1389
|
{days.map((day, dayIndex) => {
|
|
1065
|
-
if (!isWeekend(day)) return null;
|
|
1390
|
+
if (!highlightWeekends || !isWeekend(day)) return null;
|
|
1066
1391
|
const shadeSlot = slot("weekendShade", {
|
|
1067
1392
|
base: [
|
|
1068
1393
|
styles.weekendColumn,
|
|
@@ -1074,6 +1399,7 @@ function TimetablePageInner<T>({
|
|
|
1074
1399
|
return (
|
|
1075
1400
|
<Animated.View
|
|
1076
1401
|
key={`weekend-${day.toISOString()}`}
|
|
1402
|
+
testID="weekend-shade"
|
|
1077
1403
|
{...shadeSlot}
|
|
1078
1404
|
style={[shadeSlot.style, fullHeightStyle]}
|
|
1079
1405
|
/>
|
|
@@ -1109,12 +1435,39 @@ function TimetablePageInner<T>({
|
|
|
1109
1435
|
minHour={minHour}
|
|
1110
1436
|
left={dayLeft(dayIndex)}
|
|
1111
1437
|
width={dayWidth}
|
|
1112
|
-
color={theme.colors.outsideHoursBackground}
|
|
1113
|
-
|
|
1438
|
+
color={renderBusinessHours ? undefined : theme.colors.outsideHoursBackground}
|
|
1439
|
+
>
|
|
1440
|
+
{renderBusinessHours?.({ date: day, start: band.start, end: band.end })}
|
|
1441
|
+
</ShadeBand>
|
|
1114
1442
|
)),
|
|
1115
1443
|
)
|
|
1116
1444
|
: null}
|
|
1117
1445
|
|
|
1446
|
+
{/* Background events: shaded, non-interactive time ranges. */}
|
|
1447
|
+
{days.flatMap((day, dayIndex) =>
|
|
1448
|
+
backgroundBandsForDay(events, day)
|
|
1449
|
+
.map((b) => ({
|
|
1450
|
+
...b,
|
|
1451
|
+
startHours: Math.max(b.startHours, minHour),
|
|
1452
|
+
endHours: Math.min(b.endHours, maxHour),
|
|
1453
|
+
}))
|
|
1454
|
+
.filter((b) => b.endHours > b.startHours)
|
|
1455
|
+
.map((b, bandIndex) => (
|
|
1456
|
+
<ShadeBand
|
|
1457
|
+
key={`bg-${day.toISOString()}-${bandIndex}`}
|
|
1458
|
+
cellHeight={heightSource}
|
|
1459
|
+
startHour={b.startHours}
|
|
1460
|
+
endHour={b.endHours}
|
|
1461
|
+
minHour={minHour}
|
|
1462
|
+
left={dayLeft(dayIndex)}
|
|
1463
|
+
width={dayWidth}
|
|
1464
|
+
color={theme.colors.backgroundEvent}
|
|
1465
|
+
slotName="backgroundEvent"
|
|
1466
|
+
testID="background-event-shade"
|
|
1467
|
+
/>
|
|
1468
|
+
)),
|
|
1469
|
+
)}
|
|
1470
|
+
|
|
1118
1471
|
{days.map((day, dayIndex) => {
|
|
1119
1472
|
const separatorSlot = slot("daySeparator", {
|
|
1120
1473
|
base: [styles.daySeparator, styles.nonInteractive, { left: dayLeft(dayIndex) }],
|
|
@@ -1177,7 +1530,9 @@ function TimetablePageInner<T>({
|
|
|
1177
1530
|
dayWidth={dayWidth}
|
|
1178
1531
|
dayIndex={dayIndex}
|
|
1179
1532
|
dayCount={days.length}
|
|
1533
|
+
dayOrdinals={dayOrdinals}
|
|
1180
1534
|
mode={mode}
|
|
1535
|
+
daysPerPage={daysPerPage}
|
|
1181
1536
|
renderEvent={renderEvent}
|
|
1182
1537
|
snapMinutes={snapMinutes}
|
|
1183
1538
|
showDragHandle={showDragHandle}
|
|
@@ -1185,6 +1540,7 @@ function TimetablePageInner<T>({
|
|
|
1185
1540
|
onLongPress={onLongPressEvent}
|
|
1186
1541
|
onDragEvent={onDragEvent}
|
|
1187
1542
|
onDragStart={onDragStart}
|
|
1543
|
+
onEdgeAdvance={onEdgeAdvance}
|
|
1188
1544
|
/>
|
|
1189
1545
|
);
|
|
1190
1546
|
}),
|
|
@@ -1237,6 +1593,7 @@ export type TimeGridSlot =
|
|
|
1237
1593
|
| "hourLabel"
|
|
1238
1594
|
| "gridLines"
|
|
1239
1595
|
| "businessHours"
|
|
1596
|
+
| "backgroundEvent"
|
|
1240
1597
|
| "weekendShade"
|
|
1241
1598
|
| "daySeparator"
|
|
1242
1599
|
| "event"
|
|
@@ -1254,6 +1611,12 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
|
|
|
1254
1611
|
* precedence over `numberOfDays`. Ignored by other modes.
|
|
1255
1612
|
*/
|
|
1256
1613
|
weekEndsOn?: WeekStartsOn;
|
|
1614
|
+
/** Weekdays (0=Sunday…6=Saturday) hidden from the grid, e.g. `[0, 6]` for weekends off. */
|
|
1615
|
+
hiddenDays?: number[];
|
|
1616
|
+
/** Fixed "now" instant for the indicator (doesn't tick). Defaults to the device clock. */
|
|
1617
|
+
now?: Date;
|
|
1618
|
+
/** Shift the now indicator into this IANA zone (pair with `eventsInTimeZone`). */
|
|
1619
|
+
timeZone?: string;
|
|
1257
1620
|
date: Date;
|
|
1258
1621
|
events: CalendarEvent<T>[];
|
|
1259
1622
|
cellHeight: SharedValue<number>;
|
|
@@ -1278,9 +1641,19 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
|
|
|
1278
1641
|
timeslots?: number;
|
|
1279
1642
|
/** Show the all-day lane above the grid. Default true. */
|
|
1280
1643
|
showAllDayEventCell?: boolean;
|
|
1644
|
+
/** Tint Saturday/Sunday columns with the weekend background. Default true. Set
|
|
1645
|
+
* false to treat weekends like any other day. */
|
|
1646
|
+
highlightWeekends?: boolean;
|
|
1281
1647
|
/** Per-date style merged onto each day column. */
|
|
1282
1648
|
calendarCellStyle?: (date: Date) => StyleProp<ViewStyle>;
|
|
1283
1649
|
businessHours?: BusinessHours;
|
|
1650
|
+
/**
|
|
1651
|
+
* Render a closed-hours band's content yourself (a label, icon, pattern).
|
|
1652
|
+
* The grid keeps positioning the band; when set, the themed tint is dropped
|
|
1653
|
+
* and your output fills the band instead. Decorative only: the
|
|
1654
|
+
* band stays non-interactive and hidden from assistive tech.
|
|
1655
|
+
*/
|
|
1656
|
+
renderBusinessHours?: (band: BusinessHoursBand) => React.ReactNode;
|
|
1284
1657
|
/** Show the ISO week number in the header gutter. Default false. */
|
|
1285
1658
|
showWeekNumber?: boolean;
|
|
1286
1659
|
/** Element rendered between the day header and the grid. */
|
|
@@ -1356,8 +1729,10 @@ function TimeGridInner<T>({
|
|
|
1356
1729
|
hideHours = false,
|
|
1357
1730
|
timeslots = 1,
|
|
1358
1731
|
showAllDayEventCell = true,
|
|
1732
|
+
highlightWeekends = true,
|
|
1359
1733
|
calendarCellStyle,
|
|
1360
1734
|
businessHours,
|
|
1735
|
+
renderBusinessHours,
|
|
1361
1736
|
showWeekNumber = false,
|
|
1362
1737
|
headerComponent,
|
|
1363
1738
|
minHour = 0,
|
|
@@ -1373,6 +1748,9 @@ function TimeGridInner<T>({
|
|
|
1373
1748
|
showVerticalScrollIndicator = true,
|
|
1374
1749
|
verticalScrollEnabled = true,
|
|
1375
1750
|
weekNumberPrefix = "W",
|
|
1751
|
+
hiddenDays,
|
|
1752
|
+
now,
|
|
1753
|
+
timeZone,
|
|
1376
1754
|
hourComponent,
|
|
1377
1755
|
activeDate,
|
|
1378
1756
|
resetPageOnPressCell = false,
|
|
@@ -1407,6 +1785,9 @@ function TimeGridInner<T>({
|
|
|
1407
1785
|
|
|
1408
1786
|
const { width, height } = useWindowDimensions();
|
|
1409
1787
|
const listRef = useRef<LegendListRef>(null);
|
|
1788
|
+
// The pager's own view; measured in the window so an event drag can locate the
|
|
1789
|
+
// horizontal edges (its screen-space left and width) for cross-week paging.
|
|
1790
|
+
const pagerRef = useRef<View>(null);
|
|
1410
1791
|
// The grid's outer view; on web its ref resolves to the DOM node we attach the
|
|
1411
1792
|
// Ctrl/Cmd + scroll zoom listener to.
|
|
1412
1793
|
const containerRef = useRef<View>(null);
|
|
@@ -1437,6 +1818,123 @@ function TimeGridInner<T>({
|
|
|
1437
1818
|
const seedDefaultY =
|
|
1438
1819
|
Math.max(0, scrollOffsetMinutes / MINUTES_PER_HOUR - clampedMinHour) * hourHeight;
|
|
1439
1820
|
const scrollY = useSharedValue(seedDefaultY);
|
|
1821
|
+
// Pager frame in window space (refined on layout) and a swipe-scroll freeze,
|
|
1822
|
+
// shared with the event drag worklets through EdgePagingContext so a cross-week
|
|
1823
|
+
// edge drag can detect the edges and page the view live under a held finger.
|
|
1824
|
+
const pagerLeft = useSharedValue(0);
|
|
1825
|
+
const pagerTop = useSharedValue(0);
|
|
1826
|
+
const pagerWidth = useSharedValue(width);
|
|
1827
|
+
const [edgePagingLock, setEdgePagingLock] = useState(false);
|
|
1828
|
+
// Floating "held" ghost that carries a dragged event across a page change (see
|
|
1829
|
+
// EdgePaging): pager-local top-left, size, visibility, and the event to draw.
|
|
1830
|
+
const ghostX = useSharedValue(0);
|
|
1831
|
+
const ghostY = useSharedValue(0);
|
|
1832
|
+
const ghostW = useSharedValue(0);
|
|
1833
|
+
const ghostH = useSharedValue(0);
|
|
1834
|
+
const ghostVisible = useSharedValue(0);
|
|
1835
|
+
// Pager-local top of the active page's hour grid (the all-day lane above it
|
|
1836
|
+
// varies in height per week), so a cross-week drop maps the ghost's screen
|
|
1837
|
+
// position to the right time on the page it lands on.
|
|
1838
|
+
const gridTop = useSharedValue(0);
|
|
1839
|
+
const [liftedEvent, setLiftedEvent] = useState<CalendarEvent<T> | null>(null);
|
|
1840
|
+
const liftedEventRef = useRef<CalendarEvent<T> | null>(null);
|
|
1841
|
+
// The drop commit needs the live page's columns and handler; keep them in a ref
|
|
1842
|
+
// refreshed each render so the callbacks below stay identity-stable. A changing
|
|
1843
|
+
// context value would re-memo every event's gesture and tear down an in-progress
|
|
1844
|
+
// drag (the gesture must outlive the page change to finish a cross-week drop).
|
|
1845
|
+
const dropRef = useRef({
|
|
1846
|
+
headerDays: [] as Date[],
|
|
1847
|
+
containerWidth,
|
|
1848
|
+
hourColumnWidth,
|
|
1849
|
+
minHour: clampedMinHour,
|
|
1850
|
+
snapMinutes: Math.max(1, dragStepMinutes),
|
|
1851
|
+
onDragEvent,
|
|
1852
|
+
onChangeDate,
|
|
1853
|
+
});
|
|
1854
|
+
const beginLift = useCallback((event: CalendarEvent<unknown>) => {
|
|
1855
|
+
liftedEventRef.current = event as CalendarEvent<T>;
|
|
1856
|
+
setLiftedEvent(event as CalendarEvent<T>);
|
|
1857
|
+
}, []);
|
|
1858
|
+
const clearLift = useCallback(() => {
|
|
1859
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1860
|
+
ghostVisible.value = 0;
|
|
1861
|
+
liftedEventRef.current = null;
|
|
1862
|
+
setLiftedEvent(null);
|
|
1863
|
+
setEdgePagingLock(false);
|
|
1864
|
+
}, [ghostVisible]);
|
|
1865
|
+
const commitLiftedDrop = useCallback(
|
|
1866
|
+
(ghostLocalX: number, ghostLocalY: number) => {
|
|
1867
|
+
const {
|
|
1868
|
+
headerDays: days,
|
|
1869
|
+
containerWidth: cw,
|
|
1870
|
+
hourColumnWidth: hcw,
|
|
1871
|
+
minHour: min,
|
|
1872
|
+
snapMinutes: snap,
|
|
1873
|
+
onDragEvent: onDrag,
|
|
1874
|
+
onChangeDate: onDate,
|
|
1875
|
+
} = dropRef.current;
|
|
1876
|
+
const ev = liftedEventRef.current;
|
|
1877
|
+
const duration = ev ? ev.end.getTime() - ev.start.getTime() : 0;
|
|
1878
|
+
clearLift();
|
|
1879
|
+
if (!ev || !onDrag || days.length === 0) return;
|
|
1880
|
+
// Map the ghost's drawn position on the page it landed on back to a cell:
|
|
1881
|
+
// its left edge picks the day column, its top edge picks the time. Reading
|
|
1882
|
+
// the live grid geometry (the all-day lane pushes the grid down, the grid
|
|
1883
|
+
// scrolls, pinch changes the row height) keeps the drop under the ghost.
|
|
1884
|
+
const dayWidth = (cw - hcw) / days.length;
|
|
1885
|
+
const col = Math.min(
|
|
1886
|
+
Math.max(Math.floor((ghostLocalX - hcw) / dayWidth), 0),
|
|
1887
|
+
days.length - 1,
|
|
1888
|
+
);
|
|
1889
|
+
const hoursFromMin =
|
|
1890
|
+
(ghostLocalY - gridTop.value - HOUR_LABEL_TOP_INSET + scrollY.value) / cellHeight.value;
|
|
1891
|
+
const rawMinutes = (min + hoursFromMin) * MINUTES_PER_HOUR;
|
|
1892
|
+
const minutes = Math.round(rawMinutes / snap) * snap;
|
|
1893
|
+
const start = new Date(days[col]);
|
|
1894
|
+
start.setHours(0, 0, 0, 0);
|
|
1895
|
+
start.setMinutes(minutes);
|
|
1896
|
+
const end = new Date(start.getTime() + duration);
|
|
1897
|
+
// A rejected drop (handler returned false) leaves the event on its original
|
|
1898
|
+
// week, which the drag has paged away from. Page back to it so the reject
|
|
1899
|
+
// reads as a visible snap-back instead of the event seeming to vanish.
|
|
1900
|
+
if (onDrag(ev, start, end) === false) onDate(ev.start);
|
|
1901
|
+
},
|
|
1902
|
+
[clearLift, gridTop, scrollY, cellHeight],
|
|
1903
|
+
);
|
|
1904
|
+
const handleGridTop = useCallback(
|
|
1905
|
+
(y: number) => {
|
|
1906
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
1907
|
+
gridTop.value = y;
|
|
1908
|
+
},
|
|
1909
|
+
[gridTop],
|
|
1910
|
+
);
|
|
1911
|
+
const edgePaging = useMemo<EdgePaging>(
|
|
1912
|
+
() => ({
|
|
1913
|
+
pagerLeft,
|
|
1914
|
+
pagerTop,
|
|
1915
|
+
pagerWidth,
|
|
1916
|
+
lockScroll: setEdgePagingLock,
|
|
1917
|
+
ghostX,
|
|
1918
|
+
ghostY,
|
|
1919
|
+
ghostW,
|
|
1920
|
+
ghostH,
|
|
1921
|
+
ghostVisible,
|
|
1922
|
+
beginLift,
|
|
1923
|
+
commitLiftedDrop,
|
|
1924
|
+
}),
|
|
1925
|
+
[
|
|
1926
|
+
pagerLeft,
|
|
1927
|
+
pagerTop,
|
|
1928
|
+
pagerWidth,
|
|
1929
|
+
ghostX,
|
|
1930
|
+
ghostY,
|
|
1931
|
+
ghostW,
|
|
1932
|
+
ghostH,
|
|
1933
|
+
ghostVisible,
|
|
1934
|
+
beginLift,
|
|
1935
|
+
commitLiftedDrop,
|
|
1936
|
+
],
|
|
1937
|
+
);
|
|
1440
1938
|
// Plain mirror of the last settled vertical offset. A page that mounts after a
|
|
1441
1939
|
// scroll seeds its contentOffset here instead of the default, so it appears at the
|
|
1442
1940
|
// saved time straight away rather than rendering at the default and snapping (the
|
|
@@ -1506,10 +2004,23 @@ function TimeGridInner<T>({
|
|
|
1506
2004
|
numberOfDays,
|
|
1507
2005
|
isRTL,
|
|
1508
2006
|
weekEndsOn,
|
|
2007
|
+
hiddenDays,
|
|
1509
2008
|
),
|
|
1510
|
-
[mode, pageDates, activeIndex, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn],
|
|
2009
|
+
[mode, pageDates, activeIndex, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays],
|
|
1511
2010
|
);
|
|
1512
2011
|
|
|
2012
|
+
// Keep the cross-week drop's page columns + handler current without changing the
|
|
2013
|
+
// identity-stable EdgePaging callbacks (see dropRef).
|
|
2014
|
+
dropRef.current = {
|
|
2015
|
+
headerDays,
|
|
2016
|
+
containerWidth,
|
|
2017
|
+
hourColumnWidth,
|
|
2018
|
+
minHour: clampedMinHour,
|
|
2019
|
+
snapMinutes: Math.max(1, dragStepMinutes),
|
|
2020
|
+
onDragEvent,
|
|
2021
|
+
onChangeDate,
|
|
2022
|
+
};
|
|
2023
|
+
|
|
1513
2024
|
const handleViewableItemsChanged = useCallback(
|
|
1514
2025
|
(info: OnViewableItemsChangedInfo<Date>) => {
|
|
1515
2026
|
// On the web the pager can't be swiped (overflow is hidden); every page change
|
|
@@ -1668,6 +2179,9 @@ function TimeGridInner<T>({
|
|
|
1668
2179
|
<TimetablePage
|
|
1669
2180
|
mode={mode}
|
|
1670
2181
|
numberOfDays={numberOfDays}
|
|
2182
|
+
hiddenDays={hiddenDays}
|
|
2183
|
+
now={now}
|
|
2184
|
+
nowTimeZone={timeZone}
|
|
1671
2185
|
date={item}
|
|
1672
2186
|
width={containerWidth}
|
|
1673
2187
|
events={events}
|
|
@@ -1687,11 +2201,13 @@ function TimeGridInner<T>({
|
|
|
1687
2201
|
timeslots={timeslots}
|
|
1688
2202
|
isRTL={isRTL}
|
|
1689
2203
|
showAllDayEventCell={showAllDayEventCell}
|
|
2204
|
+
highlightWeekends={highlightWeekends}
|
|
1690
2205
|
showVerticalScrollIndicator={showVerticalScrollIndicator}
|
|
1691
2206
|
verticalScrollEnabled={verticalScrollEnabled}
|
|
1692
2207
|
hourComponent={hourComponent}
|
|
1693
2208
|
calendarCellStyle={calendarCellStyle}
|
|
1694
2209
|
businessHours={businessHours}
|
|
2210
|
+
renderBusinessHours={renderBusinessHours}
|
|
1695
2211
|
minHourHeight={minHourHeight}
|
|
1696
2212
|
maxHourHeight={maxHourHeight}
|
|
1697
2213
|
showNowIndicator={showNowIndicator}
|
|
@@ -1706,12 +2222,15 @@ function TimeGridInner<T>({
|
|
|
1706
2222
|
onPressCell={handlePressCell}
|
|
1707
2223
|
onLongPressCell={onLongPressCell}
|
|
1708
2224
|
onCreateEvent={onCreateEvent}
|
|
2225
|
+
onEdgeAdvance={goToPage}
|
|
2226
|
+
onGridTop={handleGridTop}
|
|
1709
2227
|
/>
|
|
1710
2228
|
</View>
|
|
1711
2229
|
),
|
|
1712
2230
|
[
|
|
1713
2231
|
containerWidth,
|
|
1714
2232
|
pageHeight,
|
|
2233
|
+
handleGridTop,
|
|
1715
2234
|
mode,
|
|
1716
2235
|
numberOfDays,
|
|
1717
2236
|
events,
|
|
@@ -1731,6 +2250,7 @@ function TimeGridInner<T>({
|
|
|
1731
2250
|
timeslots,
|
|
1732
2251
|
isRTL,
|
|
1733
2252
|
showAllDayEventCell,
|
|
2253
|
+
highlightWeekends,
|
|
1734
2254
|
showVerticalScrollIndicator,
|
|
1735
2255
|
verticalScrollEnabled,
|
|
1736
2256
|
hourComponent,
|
|
@@ -1750,6 +2270,10 @@ function TimeGridInner<T>({
|
|
|
1750
2270
|
handlePressCell,
|
|
1751
2271
|
onLongPressCell,
|
|
1752
2272
|
onCreateEvent,
|
|
2273
|
+
goToPage,
|
|
2274
|
+
hiddenDays,
|
|
2275
|
+
now,
|
|
2276
|
+
timeZone,
|
|
1753
2277
|
],
|
|
1754
2278
|
);
|
|
1755
2279
|
|
|
@@ -1762,67 +2286,95 @@ function TimeGridInner<T>({
|
|
|
1762
2286
|
|
|
1763
2287
|
return (
|
|
1764
2288
|
<SlotStylesProvider classNames={classNames} styles={styleOverrides}>
|
|
1765
|
-
<
|
|
1766
|
-
{
|
|
1767
|
-
renderHeader(
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
?
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
2289
|
+
<EdgePagingContext.Provider value={edgePaging}>
|
|
2290
|
+
<View ref={containerRef} style={styles.container}>
|
|
2291
|
+
{renderHeader ? (
|
|
2292
|
+
renderHeader(headerDays)
|
|
2293
|
+
) : (
|
|
2294
|
+
<DefaultHeader
|
|
2295
|
+
days={headerDays}
|
|
2296
|
+
mode={mode}
|
|
2297
|
+
width={containerWidth}
|
|
2298
|
+
hourColumnWidth={hourColumnWidth}
|
|
2299
|
+
showWeekNumber={showWeekNumber}
|
|
2300
|
+
weekNumberPrefix={weekNumberPrefix}
|
|
2301
|
+
weekdayFormat={weekdayFormat}
|
|
2302
|
+
locale={locale}
|
|
2303
|
+
activeDate={activeDate}
|
|
2304
|
+
onPressDateHeader={onPressDateHeader}
|
|
2305
|
+
/>
|
|
2306
|
+
)}
|
|
2307
|
+
|
|
2308
|
+
{headerComponent}
|
|
2309
|
+
|
|
2310
|
+
<View
|
|
2311
|
+
ref={pagerRef}
|
|
2312
|
+
style={styles.pager}
|
|
2313
|
+
onLayout={(event) => {
|
|
2314
|
+
setPageHeight(event.nativeEvent.layout.height);
|
|
2315
|
+
setContainerWidth(event.nativeEvent.layout.width);
|
|
2316
|
+
setMeasured(true);
|
|
2317
|
+
// Record the pager's window-space frame for the drag worklets' edge
|
|
2318
|
+
// detection and ghost placement (layout gives parent-relative coords,
|
|
2319
|
+
// not window).
|
|
2320
|
+
pagerRef.current?.measureInWindow((x, y, w) => {
|
|
2321
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
2322
|
+
pagerLeft.value = x;
|
|
2323
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
2324
|
+
pagerTop.value = y;
|
|
2325
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
2326
|
+
pagerWidth.value = w;
|
|
2327
|
+
});
|
|
2328
|
+
}}
|
|
2329
|
+
>
|
|
2330
|
+
<LegendList
|
|
2331
|
+
// Remount only on the seed→measured transition (see `measured`), not on
|
|
2332
|
+
// every height change, so a day↔week header-height difference resizes the
|
|
2333
|
+
// items in place instead of remounting and blanking the page.
|
|
2334
|
+
key={measured ? "grid" : "grid-seed"}
|
|
2335
|
+
ref={listRef}
|
|
2336
|
+
style={isWeb ? [styles.pagerList, styles.webNoScroll] : styles.pagerList}
|
|
2337
|
+
data={pageDates}
|
|
2338
|
+
extraData={listExtraData}
|
|
2339
|
+
horizontal
|
|
2340
|
+
recycleItems={false}
|
|
2341
|
+
keyExtractor={keyExtractorList}
|
|
2342
|
+
getFixedItemSize={getFixedItemSize}
|
|
2343
|
+
// On web LegendList ignores these RN scroll props (it leaks them to the
|
|
2344
|
+
// DOM as unknown attributes), so omit them there and disable horizontal
|
|
2345
|
+
// scroll via `webNoScroll`; paging is driven by the arrow keys instead.
|
|
2346
|
+
// Native: paging makes each swipe hard-stop at the adjacent page, while
|
|
2347
|
+
// `freeSwipe` lets momentum carry across pages and snap to a boundary.
|
|
2348
|
+
{...(isWeb
|
|
2349
|
+
? null
|
|
2350
|
+
: {
|
|
2351
|
+
// Frozen mid-edge-page so the programmatic advance lands under
|
|
2352
|
+
// the held finger instead of waiting for the touch to end.
|
|
2353
|
+
scrollEnabled: swipeEnabled && !edgePagingLock,
|
|
2354
|
+
pagingEnabled: !freeSwipe,
|
|
2355
|
+
snapToIndices: freeSwipe ? snapToIndices : undefined,
|
|
2356
|
+
})}
|
|
2357
|
+
initialScrollIndex={activeIndex}
|
|
2358
|
+
showsHorizontalScrollIndicator={false}
|
|
2359
|
+
viewabilityConfig={PAGE_VIEWABILITY}
|
|
2360
|
+
onViewableItemsChanged={handleViewableItemsChanged}
|
|
2361
|
+
renderItem={renderItem}
|
|
2362
|
+
/>
|
|
2363
|
+
{liftedEvent ? (
|
|
2364
|
+
<DragGhost
|
|
2365
|
+
x={ghostX}
|
|
2366
|
+
y={ghostY}
|
|
2367
|
+
w={ghostW}
|
|
2368
|
+
h={ghostH}
|
|
2369
|
+
visible={ghostVisible}
|
|
2370
|
+
event={liftedEvent}
|
|
2371
|
+
mode={mode}
|
|
2372
|
+
renderEvent={labeledRenderEvent}
|
|
2373
|
+
/>
|
|
2374
|
+
) : null}
|
|
2375
|
+
</View>
|
|
1824
2376
|
</View>
|
|
1825
|
-
</
|
|
2377
|
+
</EdgePagingContext.Provider>
|
|
1826
2378
|
</SlotStylesProvider>
|
|
1827
2379
|
);
|
|
1828
2380
|
}
|
|
@@ -2117,6 +2669,13 @@ const styles = StyleSheet.create({
|
|
|
2117
2669
|
// giving a small gap without touching the slot geometry above.
|
|
2118
2670
|
padding: EVENT_GAP,
|
|
2119
2671
|
},
|
|
2672
|
+
// The cross-week drag ghost: pinned to the pager's top-left, moved into place by
|
|
2673
|
+
// its transform, and floated above every page so it stays visible across a page.
|
|
2674
|
+
dragGhost: {
|
|
2675
|
+
top: 0,
|
|
2676
|
+
left: 0,
|
|
2677
|
+
zIndex: DRAG_EVENT_Z + 1,
|
|
2678
|
+
},
|
|
2120
2679
|
nowIndicator: {
|
|
2121
2680
|
position: "absolute",
|
|
2122
2681
|
height: 2,
|