Skip to content

Commit fbe2b35

Browse files
committed
fix: Reduce reanimated value
1 parent 7c66e57 commit fbe2b35

28 files changed

+533
-648
lines changed

apps/docs/docs/api/hooks/useBody.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ The `useBody` hook returns an object with the following properties:
3535
- `hours` (`Array<{ slot: number; time: string }>`): Array of hour objects.
3636
- `hourFormat` (string): Format for displaying hours.
3737
- `totalSlots` (number): Total number of time slots.
38-
- `columnWidthAnim` (`SharedValue<number>`): Animated value for column width.
3938
- `numberOfDays` (number): Number of days displayed.
4039
- `hourWidth` (number): Width of the hour column.
4140
- `start` (number): Start time of the calendar (in minutes from midnight).

apps/docs/docs/api/hooks/useCalendar.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ The `useCalendar` hook returns an object with numerous properties and functions.
2929
- `verticalListRef` (RefObject): Reference to the vertical list component.
3030
- `dayBarListRef` (RefObject): Reference to the day bar list component.
3131
- `gridListRef` (RefObject): Reference to the grid list component.
32-
- `columnWidthAnim` (`SharedValue<number>`): Animated value for column width.
3332
- `firstDay` (number): The first day of the week (0 for Sunday, 1 for Monday, etc.).
3433
- `offsetY` (`SharedValue<number>`): Animated value for vertical offset.
3534
- `minuteHeight` (`SharedValue<number>`): Animated value for the height of one minute.

apps/docs/docs/api/hooks/useHeader.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ The `useHeader` hook returns an object with the following properties:
2323

2424
- `dayBarHeight` (number): The height of the day bar in the header.
2525
- `numberOfDays` (number): The number of days displayed in the calendar view.
26-
- `columnWidthAnim` (`Animated.SharedValue<number>`): An animated value representing the width of each day column.
2726
- `calendarLayout` (object): Contains `width` and `height` of the calendar layout.
2827
- `hourWidth` (number): The width of the hour column.
2928
- `minuteHeight` (`Animated.SharedValue<number>`): An animated value representing the height of one minute in the calendar.

packages/react-native-calendar-kit/src/CalendarBody.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ const CalendarBody: React.FC<CalendarBodyProps> = ({
5757
const {
5858
calendarLayout,
5959
hourWidth,
60-
columnWidthAnim,
6160
numberOfDays,
6261
offsetY,
6362
minuteHeight,
@@ -217,7 +216,6 @@ const CalendarBody: React.FC<CalendarBodyProps> = ({
217216
hours,
218217
hourFormat,
219218
totalSlots,
220-
columnWidthAnim,
221219
numberOfDays,
222220
hourWidth,
223221
start,
@@ -262,7 +260,6 @@ const CalendarBody: React.FC<CalendarBodyProps> = ({
262260
hours,
263261
hourFormat,
264262
totalSlots,
265-
columnWidthAnim,
266263
numberOfDays,
267264
hourWidth,
268265
start,

packages/react-native-calendar-kit/src/CalendarContainer.tsx

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ const CalendarContainer: React.ForwardRefRenderFunction<
130130
minStartDifference,
131131
onLongPressBackground,
132132
resources,
133-
animateColumnWidth = false,
134133
dragToCreateMode = 'duration',
135134
allowHorizontalSwipe = !IS_WEB,
136135
enableResourceScroll = false,
@@ -242,7 +241,6 @@ const CalendarContainer: React.ForwardRefRenderFunction<
242241
const verticalListRef = useAnimatedRef<Animated.ScrollView>();
243242
const dayBarListRef = useAnimatedRef<Animated.ScrollView>();
244243
const gridListRef = useAnimatedRef<Animated.ScrollView>();
245-
const isTriggerMomentum = useRef(false);
246244
const scrollVisibleHeight = useRef(0);
247245
const triggerDateChanged = useRef<number | undefined>(undefined);
248246
const visibleDateRef = useRef<VisibleDateProviderRef>(null);
@@ -294,7 +292,6 @@ const CalendarContainer: React.ForwardRefRenderFunction<
294292
visibleDateUnix,
295293
]);
296294

297-
const columnWidthAnim = useSharedValue(columnWidth);
298295
const offsetY = useSharedValue(0);
299296
const offsetX = useSharedValue(
300297
isResourceMode && enableResourceScroll ? 0 : initialOffset
@@ -740,21 +737,6 @@ const CalendarContainer: React.ForwardRefRenderFunction<
740737
}
741738
}, [enableResourceScroll, initialOffset, isResourceMode, offsetX]);
742739

743-
const prevMode = useRef(isSingleDay);
744-
useEffect(() => {
745-
if (!animateColumnWidth) {
746-
columnWidthAnim.value = columnWidth;
747-
return;
748-
}
749-
750-
if (prevMode.current !== isSingleDay) {
751-
prevMode.current = isSingleDay;
752-
columnWidthAnim.value = columnWidth;
753-
} else {
754-
columnWidthAnim.value = withTiming(columnWidth);
755-
}
756-
}, [columnWidthAnim, columnWidth, isSingleDay, animateColumnWidth]);
757-
758740
const snapToInterval =
759741
numberOfDays > 1 && scrollByDay && !isResourceMode
760742
? columnWidth
@@ -770,7 +752,6 @@ const CalendarContainer: React.ForwardRefRenderFunction<
770752
verticalListRef,
771753
dayBarListRef,
772754
gridListRef,
773-
columnWidthAnim,
774755
firstDay,
775756
offsetY,
776757
minuteHeight,
@@ -789,7 +770,6 @@ const CalendarContainer: React.ForwardRefRenderFunction<
789770
timeInterval,
790771
scrollVisibleHeight,
791772
offsetX,
792-
isTriggerMomentum,
793773
showWeekNumber,
794774
calendarGridWidth,
795775
columnWidth,
@@ -828,7 +808,6 @@ const CalendarContainer: React.ForwardRefRenderFunction<
828808
verticalListRef,
829809
dayBarListRef,
830810
gridListRef,
831-
columnWidthAnim,
832811
firstDay,
833812
offsetY,
834813
minuteHeight,

packages/react-native-calendar-kit/src/CalendarHeader.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const CalendarHeader: React.FC<CalendarHeaderProps> = ({
4848
const {
4949
calendarLayout,
5050
numberOfDays,
51-
columnWidthAnim,
5251
minuteHeight,
5352
hourWidth,
5453
dayBarListRef,
@@ -159,7 +158,6 @@ const CalendarHeader: React.FC<CalendarHeaderProps> = ({
159158
() => ({
160159
dayBarHeight,
161160
numberOfDays,
162-
columnWidthAnim,
163161
calendarLayout,
164162
hourWidth,
165163
minuteHeight,
@@ -184,7 +182,6 @@ const CalendarHeader: React.FC<CalendarHeaderProps> = ({
184182
[
185183
dayBarHeight,
186184
numberOfDays,
187-
columnWidthAnim,
188185
calendarLayout,
189186
hourWidth,
190187
minuteHeight,

packages/react-native-calendar-kit/src/components/DraggableEvent.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const DraggableEvent: FC<DraggableEventProps> = ({
5757
};
5858
}, [])
5959
);
60-
const { minuteHeight, columnWidthAnim, start, numberOfDays } = useBody();
60+
const { minuteHeight, columnWidth, start, numberOfDays } = useBody();
6161
const {
6262
dragStartUnix,
6363
dragSelectedStartUnix,
@@ -70,10 +70,9 @@ export const DraggableEvent: FC<DraggableEventProps> = ({
7070
const totalResources =
7171
resources && resources.length > 1 ? resources.length : 1;
7272

73-
const eventWidth = useDerivedValue(
74-
() => columnWidthAnim.value / totalResources,
75-
[totalResources]
76-
);
73+
const eventWidth = columnWidth / totalResources;
74+
75+
const eventWidthAnim = useDerivedValue(() => eventWidth, [eventWidth]);
7776

7877
const resourceIndex = useMemo(() => {
7978
if (!resources) {
@@ -84,10 +83,10 @@ export const DraggableEvent: FC<DraggableEventProps> = ({
8483
(resource) => resource.id === selectedEvent?.resourceId
8584
);
8685
}, [resources, selectedEvent?.resourceId]);
87-
const left = useDerivedValue(() => {
86+
const left = useMemo(() => {
8887
const diffDays = visibleDates[startUnix]?.diffDays ?? 1;
89-
return (diffDays - 1) * columnWidthAnim.value;
90-
}, [visibleDates, startUnix]);
88+
return (diffDays - 1) * columnWidth;
89+
}, [visibleDates, startUnix, columnWidth]);
9190

9291
const top = useDerivedValue(() => {
9392
if (index > 0) {
@@ -104,16 +103,13 @@ export const DraggableEvent: FC<DraggableEventProps> = ({
104103
const eventHeight = useDerivedValue(
105104
() => dragSelectedDuration.value * minuteHeight.value
106105
);
106+
const startX = resourceIndex !== -1 ? resourceIndex * eventWidth : 0;
107107

108108
const isDragging = useDerivedValue(() => dragStartUnix.value !== -1);
109-
110109
const animView = useAnimatedStyle(() => {
111-
const startX = resourceIndex !== -1 ? resourceIndex * eventWidth.value : 0;
112110
return {
113111
top: top.value,
114112
height: eventHeight.value,
115-
width: eventWidth.value,
116-
left: startX + left.value,
117113
opacity:
118114
isDragging.value || dragSelectedStartMinutes.value === -1 ? 0 : 1,
119115
};
@@ -159,7 +155,12 @@ export const DraggableEvent: FC<DraggableEventProps> = ({
159155
});
160156

161157
return (
162-
<Animated.View style={[styles.container, animView]}>
158+
<Animated.View
159+
style={[
160+
styles.container,
161+
{ width: eventWidth, left: startX + left },
162+
animView,
163+
]}>
163164
{selectedEvent && (
164165
<View
165166
style={[
@@ -178,7 +179,7 @@ export const DraggableEvent: FC<DraggableEventProps> = ({
178179
]}>
179180
{renderEvent ? (
180181
renderEvent(selectedEvent, {
181-
width: eventWidth,
182+
width: eventWidthAnim,
182183
height: eventHeight,
183184
})
184185
) : (

packages/react-native-calendar-kit/src/components/DraggingEvent.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const DraggingEvent: FC<DraggingEventProps> = ({
5050

5151
const {
5252
minuteHeight,
53-
columnWidthAnim,
53+
columnWidth,
5454
start,
5555
hourWidth,
5656
visibleDateUnixAnim,
@@ -106,20 +106,17 @@ export const DraggingEvent: FC<DraggingEventProps> = ({
106106
}
107107
return clampValues(currentIndex - startIndex, 0, columns - 1);
108108
};
109-
const eventWidth = useDerivedValue(
110-
() =>
111-
columnWidthAnim.value /
112-
(enableResourceScroll ? resourcePerPage : totalResources),
113-
[totalResources, enableResourceScroll, resourcePerPage]
114-
);
109+
const eventWidth =
110+
columnWidth / (enableResourceScroll ? resourcePerPage : totalResources);
111+
const eventWidthAnim = useDerivedValue(() => eventWidth, [eventWidth]);
115112

116113
const resourceIndex = useDerivedValue(() => {
117114
if (totalResources === 1) {
118115
return 0;
119116
}
120117

121118
const xWithoutHourWidth = dragX.value - hourWidth;
122-
const columnIndex = Math.floor(xWithoutHourWidth / eventWidth.value);
119+
const columnIndex = Math.floor(xWithoutHourWidth / eventWidth);
123120
return clampValues(columnIndex, 0, totalResources - 1);
124121
}, [totalResources, hourWidth]);
125122

@@ -140,13 +137,12 @@ export const DraggingEvent: FC<DraggingEventProps> = ({
140137
});
141138

142139
const animView = useAnimatedStyle(() => {
143-
const startX = resourceIndex.value * eventWidth.value;
140+
const startX = resourceIndex.value * eventWidth;
144141
const dIndex = enableResourceScroll ? 0 : internalDayIndex.value;
145142
return {
146143
top: (dragStartMinutes.value - start) * minuteHeight.value,
147144
height: dragDuration.value * minuteHeight.value,
148-
width: eventWidth.value,
149-
left: startX + hourWidth + eventWidth.value * dIndex - 1,
145+
left: startX + hourWidth + eventWidth * dIndex - 1,
150146
};
151147
}, [totalResources, hourWidth]);
152148

@@ -193,7 +189,7 @@ export const DraggingEvent: FC<DraggingEventProps> = ({
193189
};
194190

195191
return (
196-
<Animated.View style={[styles.container, animView]}>
192+
<Animated.View style={[styles.container, { width: eventWidth }, animView]}>
197193
<View
198194
style={[
199195
StyleSheet.absoluteFill,
@@ -207,7 +203,7 @@ export const DraggingEvent: FC<DraggingEventProps> = ({
207203
]}>
208204
{renderEvent
209205
? renderEvent(draggingEvent, {
210-
width: eventWidth,
206+
width: eventWidthAnim,
211207
height: eventHeight,
212208
})
213209
: !!draggingEvent?.title && (

0 commit comments

Comments
 (0)