@super-calendar/native 2.18.0 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -4
- package/dist/{DefaultMonthEvent-B7xVeY7Q.d.ts → DefaultMonthEvent-DzgQFuVp.d.mts} +25 -7
- package/dist/{DefaultMonthEvent-hGk7wSrr.d.mts → DefaultMonthEvent-joYl8Tu2.d.ts} +25 -7
- package/dist/{MonthList-DdQxRhUy.mjs → MonthList-BGl1gTDr.mjs} +545 -100
- package/dist/{MonthList-C_NTufaK.js → MonthList-DeO-x5VW.js} +543 -98
- package/dist/index.d.mts +51 -4
- package/dist/index.d.ts +51 -4
- package/dist/index.js +107 -39
- package/dist/index.mjs +107 -39
- 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 +1 -2
- package/src/components/Calendar.tsx +21 -4
- package/src/components/MonthCellProbe.tsx +201 -0
- package/src/components/MonthList.tsx +4 -2
- package/src/components/MonthPager.tsx +4 -3
- package/src/components/MonthView.tsx +532 -138
- package/src/components/ResourceTimeline.tsx +11 -2
- package/src/components/TimeGrid.tsx +176 -62
- package/src/components/YearView.tsx +0 -2
- package/src/index.tsx +2 -0
- package/src/types.ts +18 -0
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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,
|
|
@@ -86,8 +86,6 @@ import {
|
|
|
86
86
|
isSameCalendarDay,
|
|
87
87
|
isWeekend,
|
|
88
88
|
viewDayCount,
|
|
89
|
-
} from "@super-calendar/core";
|
|
90
|
-
import {
|
|
91
89
|
backgroundBandsForDay,
|
|
92
90
|
cellRangeFromDrag,
|
|
93
91
|
clampMoveStartMinutes,
|
|
@@ -98,15 +96,16 @@ import {
|
|
|
98
96
|
resolveDraggedBounds,
|
|
99
97
|
movedClockSpan,
|
|
100
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,
|
|
101
108
|
} from "@super-calendar/core";
|
|
102
|
-
import { formatHour, layoutDayEvents, type PositionedEvent } from "@super-calendar/core";
|
|
103
|
-
import type {
|
|
104
|
-
CalendarHandle,
|
|
105
|
-
CalendarLabels,
|
|
106
|
-
EventAccessibilityLabeler,
|
|
107
|
-
} from "@super-calendar/core";
|
|
108
|
-
import { resolveCalendarLabels } from "@super-calendar/core";
|
|
109
|
-
import { type WeekdayFormat, weekdayFormatToken } from "@super-calendar/core";
|
|
110
109
|
import {
|
|
111
110
|
type ResolvedSlot,
|
|
112
111
|
SlotStylesProvider,
|
|
@@ -486,9 +485,10 @@ function AnimatedEventBoxInner<T>({
|
|
|
486
485
|
// across its day column; the box's own clip is geometric, so it can't disagree
|
|
487
486
|
// with the box during the frames between release and the committed re-render.
|
|
488
487
|
const moving = useSharedValue(0);
|
|
489
|
-
// 1 while a
|
|
490
|
-
// handles, so a hold on one
|
|
491
|
-
|
|
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);
|
|
492
492
|
// Edge auto-advance: which side the drag has pushed past the visible columns
|
|
493
493
|
// (-1 left / 0 none / +1 right).
|
|
494
494
|
const edgeDir = useSharedValue(0);
|
|
@@ -606,10 +606,8 @@ function AnimatedEventBoxInner<T>({
|
|
|
606
606
|
// A picked-up event floats across its whole day column, like the multi-day
|
|
607
607
|
// preview and the spill, instead of keeping its slice of an overlap group. It
|
|
608
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
|
-
|
|
611
|
-
const floating =
|
|
612
|
-
!onHandle.value && (moving.value || moveOffset.value !== 0 || moveOffsetX.value !== 0);
|
|
609
|
+
// flash back to its old slice before the committed layout lands.
|
|
610
|
+
const floating = moving.value || moveOffset.value !== 0 || moveOffsetX.value !== 0;
|
|
613
611
|
return {
|
|
614
612
|
left: floating ? dayLeftPx : left,
|
|
615
613
|
width: floating ? dayWidth : width,
|
|
@@ -1001,21 +999,25 @@ function AnimatedEventBoxInner<T>({
|
|
|
1001
999
|
// A plain tap on a resize handle is a press on the event. The two handles cover
|
|
1002
1000
|
// almost all of a box at the minimum height, so without this a 5- to 30-minute
|
|
1003
1001
|
// event has next to no tappable surface. A drag from a handle still resizes:
|
|
1004
|
-
// 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.
|
|
1005
1004
|
const resizeGesture = useMemo(() => {
|
|
1006
1005
|
const pan = Gesture.Pan()
|
|
1007
1006
|
.enabled(resizable)
|
|
1008
|
-
.onBegin(() => {
|
|
1009
|
-
onHandle.value = 1;
|
|
1010
|
-
})
|
|
1011
1007
|
.onStart(() => {
|
|
1008
|
+
if (moving.value) {
|
|
1009
|
+
resizeYielded.value = 1;
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
1012
|
dragZ.value = DRAG_EVENT_Z;
|
|
1013
1013
|
runOnJS(notifyDragStart)();
|
|
1014
1014
|
})
|
|
1015
1015
|
.onUpdate((event) => {
|
|
1016
|
+
if (resizeYielded.value) return;
|
|
1016
1017
|
resizeDelta.value = event.translationY;
|
|
1017
1018
|
})
|
|
1018
1019
|
.onEnd((event) => {
|
|
1020
|
+
if (resizeYielded.value) return;
|
|
1019
1021
|
const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
|
|
1020
1022
|
if (delta === 0) {
|
|
1021
1023
|
resizeDelta.value = 0;
|
|
@@ -1025,8 +1027,9 @@ function AnimatedEventBoxInner<T>({
|
|
|
1025
1027
|
runOnJS(commitDrag)(0, delta);
|
|
1026
1028
|
})
|
|
1027
1029
|
.onFinalize(() => {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
+
// A yielded resize leaves the moving box raised.
|
|
1031
|
+
if (!resizeYielded.value) dragZ.value = 0;
|
|
1032
|
+
resizeYielded.value = 0;
|
|
1030
1033
|
});
|
|
1031
1034
|
const tap = Gesture.Tap()
|
|
1032
1035
|
.runOnJS(true)
|
|
@@ -1044,7 +1047,8 @@ function AnimatedEventBoxInner<T>({
|
|
|
1044
1047
|
resizable,
|
|
1045
1048
|
snapMinutes,
|
|
1046
1049
|
cellHeight,
|
|
1047
|
-
|
|
1050
|
+
moving,
|
|
1051
|
+
resizeYielded,
|
|
1048
1052
|
resizeDelta,
|
|
1049
1053
|
dragZ,
|
|
1050
1054
|
commitDrag,
|
|
@@ -1059,17 +1063,20 @@ function AnimatedEventBoxInner<T>({
|
|
|
1059
1063
|
const resizeStartGesture = useMemo(() => {
|
|
1060
1064
|
const pan = Gesture.Pan()
|
|
1061
1065
|
.enabled(resizableFromStart)
|
|
1062
|
-
.onBegin(() => {
|
|
1063
|
-
onHandle.value = 1;
|
|
1064
|
-
})
|
|
1065
1066
|
.onStart(() => {
|
|
1067
|
+
if (moving.value) {
|
|
1068
|
+
resizeYielded.value = 1;
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1066
1071
|
dragZ.value = DRAG_EVENT_Z;
|
|
1067
1072
|
runOnJS(notifyDragStart)();
|
|
1068
1073
|
})
|
|
1069
1074
|
.onUpdate((event) => {
|
|
1075
|
+
if (resizeYielded.value) return;
|
|
1070
1076
|
resizeStartDelta.value = event.translationY;
|
|
1071
1077
|
})
|
|
1072
1078
|
.onEnd((event) => {
|
|
1079
|
+
if (resizeYielded.value) return;
|
|
1073
1080
|
const delta = snapDeltaMinutes(event.translationY, cellHeight.value, snapMinutes);
|
|
1074
1081
|
if (delta === 0) {
|
|
1075
1082
|
resizeStartDelta.value = 0;
|
|
@@ -1079,8 +1086,9 @@ function AnimatedEventBoxInner<T>({
|
|
|
1079
1086
|
runOnJS(commitDrag)(delta, 0);
|
|
1080
1087
|
})
|
|
1081
1088
|
.onFinalize(() => {
|
|
1082
|
-
|
|
1083
|
-
|
|
1089
|
+
// A yielded resize leaves the moving box raised.
|
|
1090
|
+
if (!resizeYielded.value) dragZ.value = 0;
|
|
1091
|
+
resizeYielded.value = 0;
|
|
1084
1092
|
});
|
|
1085
1093
|
const tap = Gesture.Tap()
|
|
1086
1094
|
.runOnJS(true)
|
|
@@ -1098,7 +1106,8 @@ function AnimatedEventBoxInner<T>({
|
|
|
1098
1106
|
resizableFromStart,
|
|
1099
1107
|
snapMinutes,
|
|
1100
1108
|
cellHeight,
|
|
1101
|
-
|
|
1109
|
+
moving,
|
|
1110
|
+
resizeYielded,
|
|
1102
1111
|
resizeStartDelta,
|
|
1103
1112
|
dragZ,
|
|
1104
1113
|
commitDrag,
|
|
@@ -1256,12 +1265,15 @@ type HourLabelProps = {
|
|
|
1256
1265
|
label: string;
|
|
1257
1266
|
ampm: boolean;
|
|
1258
1267
|
hourComponent?: HourRenderer;
|
|
1268
|
+
/** Leave the label out, because the now label sits on top of it. */
|
|
1269
|
+
hidden?: boolean;
|
|
1259
1270
|
};
|
|
1260
1271
|
|
|
1261
1272
|
// The hour-axis label: the consumer's `hourComponent`, or the themed text.
|
|
1262
|
-
const HourLabel = ({ hour, width, label, ampm, hourComponent }: HourLabelProps) => {
|
|
1273
|
+
const HourLabel = ({ hour, width, label, ampm, hourComponent, hidden }: HourLabelProps) => {
|
|
1263
1274
|
const theme = useCalendarTheme();
|
|
1264
1275
|
const slot = useSlots<TimeGridSlot>();
|
|
1276
|
+
if (hidden) return null;
|
|
1265
1277
|
return hourComponent ? (
|
|
1266
1278
|
<View style={{ width }}>{hourComponent(hour, ampm)}</View>
|
|
1267
1279
|
) : (
|
|
@@ -1312,6 +1324,12 @@ const HourLines = memo(function HourLines({ hours, timeslots }: HourLinesProps)
|
|
|
1312
1324
|
);
|
|
1313
1325
|
});
|
|
1314
1326
|
|
|
1327
|
+
function getNowPosition(time: Date, days: Date[], minHour: number, maxHour: number) {
|
|
1328
|
+
const hours = getHours(time) + getMinutes(time) / MINUTES_PER_HOUR;
|
|
1329
|
+
const dayIndex = days.findIndex((day) => isSameCalendarDay(day, time));
|
|
1330
|
+
return dayIndex >= 0 && hours >= minHour && hours <= maxHour ? { time, hours, dayIndex } : null;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1315
1333
|
type HourGutterProps = {
|
|
1316
1334
|
width: number;
|
|
1317
1335
|
minHour: number;
|
|
@@ -1334,8 +1352,14 @@ type HourGutterProps = {
|
|
|
1334
1352
|
weekNumber: string | null;
|
|
1335
1353
|
ampm: boolean;
|
|
1336
1354
|
hourComponent?: HourRenderer;
|
|
1355
|
+
/** Draws the current time in the hour column, level with the now line. */
|
|
1356
|
+
renderNowLabel?: (now: Date) => React.ReactNode;
|
|
1357
|
+
nowPosition: ReturnType<typeof getNowPosition>;
|
|
1337
1358
|
};
|
|
1338
1359
|
|
|
1360
|
+
// How close, in hours, an hour label may sit to the now label before it is left out.
|
|
1361
|
+
const NOW_LABEL_CLEARANCE_HOURS = 0.25;
|
|
1362
|
+
|
|
1339
1363
|
// The hour-axis column beside the pager. It is part of the grid's one vertical
|
|
1340
1364
|
// scroll content, so it scrolls and zooms with the pages and holds still while
|
|
1341
1365
|
// they swipe. Its "all-day" cell rides the scroll offset to stay pinned at the
|
|
@@ -1355,15 +1379,24 @@ const HourGutterInner = ({
|
|
|
1355
1379
|
weekNumber,
|
|
1356
1380
|
ampm,
|
|
1357
1381
|
hourComponent,
|
|
1382
|
+
renderNowLabel,
|
|
1383
|
+
nowPosition,
|
|
1358
1384
|
}: HourGutterProps) => {
|
|
1359
1385
|
const theme = useCalendarTheme();
|
|
1360
1386
|
const slot = useSlots<TimeGridSlot>();
|
|
1361
1387
|
const hours = useMemo(() => hourRange(minHour, maxHour), [minHour, maxHour]);
|
|
1388
|
+
const label = nowPosition && renderNowLabel?.(nowPosition.time);
|
|
1389
|
+
const labelHours = label == null || typeof label === "boolean" ? undefined : nowPosition?.hours;
|
|
1362
1390
|
// Height and offset are separate styles: a style that returns a transform is
|
|
1363
1391
|
// re-applied every time it runs, so keeping the offset apart means a swipe
|
|
1364
1392
|
// (which only moves the band's height) sends nothing to the view.
|
|
1365
1393
|
const laneCellHeightStyle = useAnimatedStyle(() => ({ height: laneHeight.value }));
|
|
1366
|
-
|
|
1394
|
+
// Pinned to the viewport top only for real offsets. During the iOS top bounce the offset goes
|
|
1395
|
+
// negative, which lifted the pinned header and all-day band out of view while the hours slid
|
|
1396
|
+
// down; clamped at 0 they ride down with the hours instead, like a sticky header.
|
|
1397
|
+
const pinStyle = useAnimatedStyle(() => ({
|
|
1398
|
+
transform: [{ translateY: Math.max(0, scrollY.value) }],
|
|
1399
|
+
}));
|
|
1367
1400
|
const rowsStyle = useAnimatedStyle(
|
|
1368
1401
|
() => ({
|
|
1369
1402
|
top: headerHeight + laneHeight.value + HOUR_LABEL_TOP_INSET,
|
|
@@ -1430,10 +1463,25 @@ const HourGutterInner = ({
|
|
|
1430
1463
|
label={formatHour(hour, { ampm })}
|
|
1431
1464
|
ampm={ampm}
|
|
1432
1465
|
hourComponent={hourComponent}
|
|
1466
|
+
hidden={
|
|
1467
|
+
labelHours != null && Math.abs(hour - labelHours) < NOW_LABEL_CLEARANCE_HOURS
|
|
1468
|
+
}
|
|
1433
1469
|
/>
|
|
1434
1470
|
</View>
|
|
1435
1471
|
</View>
|
|
1436
1472
|
))}
|
|
1473
|
+
{labelHours != null ? (
|
|
1474
|
+
// A percentage of the rows' height, so it follows the zoom without a worklet.
|
|
1475
|
+
<View
|
|
1476
|
+
style={[
|
|
1477
|
+
styles.nowLabel,
|
|
1478
|
+
styles.nonInteractive,
|
|
1479
|
+
{ width, top: `${((labelHours - minHour) / (maxHour - minHour)) * 100}%` },
|
|
1480
|
+
]}
|
|
1481
|
+
>
|
|
1482
|
+
{label}
|
|
1483
|
+
</View>
|
|
1484
|
+
) : null}
|
|
1437
1485
|
</Animated.View>
|
|
1438
1486
|
</View>
|
|
1439
1487
|
);
|
|
@@ -1797,15 +1845,10 @@ function TimetablePageInner<T>({
|
|
|
1797
1845
|
|
|
1798
1846
|
const hoursRange = useMemo(() => hourRange(minHour, maxHour), [minHour, maxHour]);
|
|
1799
1847
|
|
|
1800
|
-
const
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
const
|
|
1804
|
-
// "Today" follows the (possibly zone-shifted or overridden) now, so the line
|
|
1805
|
-
// lands in the column the events are displayed in.
|
|
1806
|
-
const nowDayIndex = days.findIndex((day) => isSameCalendarDay(day, now));
|
|
1807
|
-
const nowHours = (getHours(now) * MINUTES_PER_HOUR + getMinutes(now)) / MINUTES_PER_HOUR;
|
|
1808
|
-
const nowInWindow = nowHours >= minHour && nowHours <= maxHour;
|
|
1848
|
+
const tickOnPage = showNowIndicator && isActive && nowProp == null;
|
|
1849
|
+
const pageClock = useNow(tickOnPage, { now: nowProp, timeZone: nowTimeZone });
|
|
1850
|
+
const today = tickOnPage ? pageClock : nowInTimeZone(nowProp, nowTimeZone);
|
|
1851
|
+
const nowPosition = showNowIndicator ? getNowPosition(today, days, minHour, maxHour) : null;
|
|
1809
1852
|
|
|
1810
1853
|
const fullHeightStyle = useAnimatedStyle(
|
|
1811
1854
|
() => ({ height: (maxHour - minHour) * heightSource.value }),
|
|
@@ -1833,7 +1876,12 @@ function TimetablePageInner<T>({
|
|
|
1833
1876
|
height: Math.max(LANE_BAND_FLOOR, laneHeight.value),
|
|
1834
1877
|
borderBottomWidth: laneHeight.value >= LANE_BAND_FLOOR ? StyleSheet.hairlineWidth : 0,
|
|
1835
1878
|
}));
|
|
1836
|
-
|
|
1879
|
+
// Pinned to the viewport top only for real offsets. During the iOS top bounce the offset goes
|
|
1880
|
+
// negative, which lifted the pinned header and all-day band out of view while the hours slid
|
|
1881
|
+
// down; clamped at 0 they ride down with the hours instead, like a sticky header.
|
|
1882
|
+
const pinStyle = useAnimatedStyle(() => ({
|
|
1883
|
+
transform: [{ translateY: Math.max(0, scrollY.value) }],
|
|
1884
|
+
}));
|
|
1837
1885
|
const reportLaneLayout = useCallback(
|
|
1838
1886
|
(event: LayoutChangeEvent) => {
|
|
1839
1887
|
onLaneLayout(pageIndex, event.nativeEvent.layout.height);
|
|
@@ -2432,12 +2480,12 @@ function TimetablePageInner<T>({
|
|
|
2432
2480
|
/>
|
|
2433
2481
|
) : null}
|
|
2434
2482
|
|
|
2435
|
-
{
|
|
2483
|
+
{nowPosition ? (
|
|
2436
2484
|
<NowIndicator
|
|
2437
2485
|
cellHeight={heightSource}
|
|
2438
|
-
nowHours={
|
|
2486
|
+
nowHours={nowPosition.hours}
|
|
2439
2487
|
minHour={minHour}
|
|
2440
|
-
left={dayLeft(
|
|
2488
|
+
left={dayLeft(nowPosition.dayIndex)}
|
|
2441
2489
|
width={dayWidth}
|
|
2442
2490
|
color={theme.colors.nowIndicator}
|
|
2443
2491
|
/>
|
|
@@ -2653,6 +2701,36 @@ export type TimeGridProps<T> = SlotStyleProps<TimeGridSlot> & {
|
|
|
2653
2701
|
onChangeDate: (date: Date) => void;
|
|
2654
2702
|
/** Optional header above the grid (e.g. weekday labels). Rendered full-width. */
|
|
2655
2703
|
renderHeader?: (days: Date[]) => React.ReactNode;
|
|
2704
|
+
/**
|
|
2705
|
+
* Draw a label in the hour column when the current-time line is visible.
|
|
2706
|
+
* A custom label replaces hour labels less than 15 minutes away.
|
|
2707
|
+
*/
|
|
2708
|
+
renderNowLabel?: (now: Date) => React.ReactNode;
|
|
2709
|
+
/**
|
|
2710
|
+
* Extra scrollable space below the last hour, inside the vertical scroll view,
|
|
2711
|
+
* so the end of the day can scroll clear of something floating over the grid
|
|
2712
|
+
* (a tab bar, a button). Default 0.
|
|
2713
|
+
*/
|
|
2714
|
+
contentPaddingBottom?: number;
|
|
2715
|
+
/**
|
|
2716
|
+
* The vertical scroll view's scroll events, on the JS thread. Use it to react
|
|
2717
|
+
* to the hours scrolling, such as collapsing a toolbar.
|
|
2718
|
+
*/
|
|
2719
|
+
onVerticalScroll?: (event: VerticalScrollEvent) => void;
|
|
2720
|
+
/**
|
|
2721
|
+
* Overscroll on the hours: iOS `bounces`, Android `overScrollMode`. Set
|
|
2722
|
+
* `false` to stop the grid at its ends. Default true.
|
|
2723
|
+
*/
|
|
2724
|
+
verticalBounces?: boolean;
|
|
2725
|
+
};
|
|
2726
|
+
|
|
2727
|
+
/** The scroll event `onVerticalScroll` receives, shaped like React Native's scroll event. */
|
|
2728
|
+
export type VerticalScrollEvent = {
|
|
2729
|
+
nativeEvent: {
|
|
2730
|
+
contentOffset: { x: number; y: number };
|
|
2731
|
+
contentSize: { width: number; height: number };
|
|
2732
|
+
layoutMeasurement: { width: number; height: number };
|
|
2733
|
+
};
|
|
2656
2734
|
};
|
|
2657
2735
|
|
|
2658
2736
|
function TimeGridInner<T>(
|
|
@@ -2700,7 +2778,7 @@ function TimeGridInner<T>(
|
|
|
2700
2778
|
verticalScrollEnabled = true,
|
|
2701
2779
|
weekNumberPrefix = "W",
|
|
2702
2780
|
hiddenDays,
|
|
2703
|
-
now,
|
|
2781
|
+
now: nowProp,
|
|
2704
2782
|
timeZone,
|
|
2705
2783
|
hourComponent,
|
|
2706
2784
|
activeDate,
|
|
@@ -2721,6 +2799,10 @@ function TimeGridInner<T>(
|
|
|
2721
2799
|
onPressDateHeader,
|
|
2722
2800
|
onChangeDate,
|
|
2723
2801
|
renderHeader,
|
|
2802
|
+
renderNowLabel,
|
|
2803
|
+
contentPaddingBottom = 0,
|
|
2804
|
+
onVerticalScroll,
|
|
2805
|
+
verticalBounces = true,
|
|
2724
2806
|
classNames,
|
|
2725
2807
|
styles: styleOverrides,
|
|
2726
2808
|
}: TimeGridProps<T>,
|
|
@@ -2731,6 +2813,10 @@ function TimeGridInner<T>(
|
|
|
2731
2813
|
const clampedMaxHour = Math.max(clampedMinHour + 1, Math.min(maxHour, HOURS_PER_DAY));
|
|
2732
2814
|
// Collapse the hour gutter to zero when hours are hidden.
|
|
2733
2815
|
const hourColumnWidth = hideHours ? 0 : hourColumnWidthProp;
|
|
2816
|
+
// A custom gutter label and its line must tick on the same minute, including after paging.
|
|
2817
|
+
const hasNowLabel = showNowIndicator && renderNowLabel != null && hourColumnWidth > 0;
|
|
2818
|
+
const labelClock = useNow(hasNowLabel, { now: nowProp });
|
|
2819
|
+
const now = nowProp ?? (hasNowLabel ? labelClock : undefined);
|
|
2734
2820
|
const labels = useMemo(() => resolveCalendarLabels(labelsProp), [labelsProp]);
|
|
2735
2821
|
const todayLabel = labels.today;
|
|
2736
2822
|
// The built-in day header pages with the columns (rendered inside each page). A
|
|
@@ -2802,12 +2888,27 @@ function TimeGridInner<T>(
|
|
|
2802
2888
|
// scrolls with the content, so a finger's window position maps into the grid
|
|
2803
2889
|
// through it.
|
|
2804
2890
|
const scrollY = useSharedValue(seedDefaultY);
|
|
2805
|
-
const scrollHandler = useAnimatedScrollHandler(
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2891
|
+
const scrollHandler = useAnimatedScrollHandler(
|
|
2892
|
+
{
|
|
2893
|
+
onScroll: (event) => {
|
|
2894
|
+
// eslint-disable-next-line react-hooks/immutability -- Reanimated shared value: assigning .value is the intended mutation API
|
|
2895
|
+
scrollY.value = event.contentOffset.y;
|
|
2896
|
+
if (onVerticalScroll) {
|
|
2897
|
+
runOnJS(onVerticalScroll)({
|
|
2898
|
+
nativeEvent: {
|
|
2899
|
+
contentOffset: { x: event.contentOffset.x, y: event.contentOffset.y },
|
|
2900
|
+
contentSize: { width: event.contentSize.width, height: event.contentSize.height },
|
|
2901
|
+
layoutMeasurement: {
|
|
2902
|
+
width: event.layoutMeasurement.width,
|
|
2903
|
+
height: event.layoutMeasurement.height,
|
|
2904
|
+
},
|
|
2905
|
+
},
|
|
2906
|
+
});
|
|
2907
|
+
}
|
|
2908
|
+
},
|
|
2809
2909
|
},
|
|
2810
|
-
|
|
2910
|
+
[onVerticalScroll],
|
|
2911
|
+
);
|
|
2811
2912
|
// The scroll view's `contentOffset` holds the mount offset; a later
|
|
2812
2913
|
// `scrollOffsetMinutes` is scrolled to by the effect further down.
|
|
2813
2914
|
const [mountOffsetY] = useState(seedDefaultY);
|
|
@@ -3145,20 +3246,17 @@ function TimeGridInner<T>(
|
|
|
3145
3246
|
|
|
3146
3247
|
// Header days track the active page (page-aligned), so they always match the
|
|
3147
3248
|
// columns below and a swipe never flashes another day's label.
|
|
3249
|
+
const activePageDate = pageDates[activeIndex] ?? date;
|
|
3148
3250
|
const headerDays = useMemo(
|
|
3149
3251
|
() =>
|
|
3150
|
-
getViewDays(
|
|
3151
|
-
|
|
3152
|
-
pageDates[activeIndex] ?? date,
|
|
3153
|
-
weekStartsOn,
|
|
3154
|
-
numberOfDays,
|
|
3155
|
-
isRTL,
|
|
3156
|
-
weekEndsOn,
|
|
3157
|
-
hiddenDays,
|
|
3158
|
-
),
|
|
3159
|
-
[mode, pageDates, activeIndex, date, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays],
|
|
3252
|
+
getViewDays(mode, activePageDate, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays),
|
|
3253
|
+
[mode, activePageDate, weekStartsOn, numberOfDays, isRTL, weekEndsOn, hiddenDays],
|
|
3160
3254
|
);
|
|
3161
3255
|
|
|
3256
|
+
const gutterNow = hasNowLabel
|
|
3257
|
+
? getNowPosition(nowInTimeZone(now, timeZone), headerDays, clampedMinHour, clampedMaxHour)
|
|
3258
|
+
: null;
|
|
3259
|
+
|
|
3162
3260
|
// Keep the cross-week drop's page columns + handler current without changing the
|
|
3163
3261
|
// identity-stable EdgePaging callbacks (see dropRef).
|
|
3164
3262
|
dropRef.current = {
|
|
@@ -3541,7 +3639,7 @@ function TimeGridInner<T>(
|
|
|
3541
3639
|
// `columnsWidth` resizes the mounted pages when the grid is re-measured.
|
|
3542
3640
|
// `showDragHandle` refreshes grips without requiring an event-data change, and
|
|
3543
3641
|
// `renderCreateGhost` swaps the preview content of mounted pages.
|
|
3544
|
-
//
|
|
3642
|
+
// Refresh mounted pages when the clock, visible days, or indicator setting changes.
|
|
3545
3643
|
const nowTime = now?.getTime();
|
|
3546
3644
|
const listExtraData = useMemo(
|
|
3547
3645
|
() => ({
|
|
@@ -3554,6 +3652,8 @@ function TimeGridInner<T>(
|
|
|
3554
3652
|
dragStepMinutes,
|
|
3555
3653
|
minHour,
|
|
3556
3654
|
maxHour,
|
|
3655
|
+
headerDays,
|
|
3656
|
+
showNowIndicator,
|
|
3557
3657
|
nowTime,
|
|
3558
3658
|
timeZone,
|
|
3559
3659
|
}),
|
|
@@ -3567,6 +3667,8 @@ function TimeGridInner<T>(
|
|
|
3567
3667
|
dragStepMinutes,
|
|
3568
3668
|
minHour,
|
|
3569
3669
|
maxHour,
|
|
3670
|
+
headerDays,
|
|
3671
|
+
showNowIndicator,
|
|
3570
3672
|
nowTime,
|
|
3571
3673
|
timeZone,
|
|
3572
3674
|
],
|
|
@@ -3607,6 +3709,11 @@ function TimeGridInner<T>(
|
|
|
3607
3709
|
scrollEventThrottle={16}
|
|
3608
3710
|
refreshControl={verticalScrollEnabled ? refreshControl : undefined}
|
|
3609
3711
|
contentOffset={{ x: 0, y: mountOffsetY }}
|
|
3712
|
+
contentContainerStyle={
|
|
3713
|
+
contentPaddingBottom > 0 ? { paddingBottom: contentPaddingBottom } : undefined
|
|
3714
|
+
}
|
|
3715
|
+
bounces={verticalBounces}
|
|
3716
|
+
overScrollMode={verticalBounces ? undefined : "never"}
|
|
3610
3717
|
>
|
|
3611
3718
|
<Animated.View testID="time-grid-hours" style={[styles.gridRow, gridHeightStyle]}>
|
|
3612
3719
|
{hourColumnWidth > 0 ? (
|
|
@@ -3624,6 +3731,8 @@ function TimeGridInner<T>(
|
|
|
3624
3731
|
weekNumber={weekNumber}
|
|
3625
3732
|
ampm={ampm}
|
|
3626
3733
|
hourComponent={hourComponent}
|
|
3734
|
+
renderNowLabel={renderNowLabel}
|
|
3735
|
+
nowPosition={gutterNow}
|
|
3627
3736
|
/>
|
|
3628
3737
|
) : null}
|
|
3629
3738
|
<View
|
|
@@ -4016,6 +4125,11 @@ const styles = StyleSheet.create({
|
|
|
4016
4125
|
textAlign: "right",
|
|
4017
4126
|
paddingRight: 6,
|
|
4018
4127
|
},
|
|
4128
|
+
nowLabel: {
|
|
4129
|
+
position: "absolute",
|
|
4130
|
+
left: 0,
|
|
4131
|
+
marginTop: -HOUR_LABEL_NUDGE,
|
|
4132
|
+
},
|
|
4019
4133
|
gutterRows: {
|
|
4020
4134
|
position: "absolute",
|
|
4021
4135
|
left: 0,
|
package/src/index.tsx
CHANGED
|
@@ -35,6 +35,7 @@ export {
|
|
|
35
35
|
type EventDragHandler,
|
|
36
36
|
type EventDragStartHandler,
|
|
37
37
|
type HourRenderer,
|
|
38
|
+
type VerticalScrollEvent,
|
|
38
39
|
DEFAULT_HOUR_HEIGHT,
|
|
39
40
|
} from "./components/TimeGrid";
|
|
40
41
|
export { DefaultEvent } from "./components/DefaultEvent";
|
|
@@ -65,6 +66,7 @@ export type {
|
|
|
65
66
|
EventAccessibilityLabeler,
|
|
66
67
|
EventKeyExtractor,
|
|
67
68
|
ICalendarEvent,
|
|
69
|
+
MonthDateInfo,
|
|
68
70
|
RecurrenceFrequency,
|
|
69
71
|
RecurrenceRule,
|
|
70
72
|
RenderEvent,
|
package/src/types.ts
CHANGED
|
@@ -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
|
+
};
|