react-native-resource-calendar 1.0.19 → 1.0.20

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/index.mjs CHANGED
@@ -4,7 +4,6 @@ import { Gesture, GestureDetector } from 'react-native-gesture-handler';
4
4
  import Animated2, { useSharedValue, useAnimatedRef, runOnJS, withSpring, useFrameCallback, scrollTo, useAnimatedScrollHandler, useAnimatedStyle, useAnimatedProps } from 'react-native-reanimated';
5
5
  import { InteractionManager, View, StyleSheet, Text, TouchableOpacity, TextInput, useWindowDimensions, Platform, Dimensions, Image } from 'react-native';
6
6
  import { FlashList } from '@shopify/flash-list';
7
- import * as Haptics from 'expo-haptics';
8
7
  import { toZonedTime } from 'date-fns-tz';
9
8
  import { isSameDay, format, getHours, getMinutes, set, addDays, setSeconds, setMinutes, setHours } from 'date-fns';
10
9
  import { isUndefined } from 'lodash';
@@ -721,6 +720,7 @@ function StaffAvatar({
721
720
  }
722
721
  var EventGridBlocksSkia = ({
723
722
  handleBlockPress,
723
+ handleBlockLongPress,
724
724
  hourHeight,
725
725
  APPOINTMENT_BLOCK_WIDTH
726
726
  }) => {
@@ -762,6 +762,16 @@ var EventGridBlocksSkia = ({
762
762
  },
763
763
  [handleBlockPress, timeLabels]
764
764
  );
765
+ const onSlotLongPress = React19.useCallback(
766
+ (row) => {
767
+ setPressedRow(null);
768
+ const slot = timeLabels[row];
769
+ if (slot) {
770
+ handleBlockLongPress(slot);
771
+ }
772
+ },
773
+ [timeLabels, handleBlockLongPress]
774
+ );
765
775
  const onPressBegin = React19.useCallback((row) => {
766
776
  setPressedRow(row);
767
777
  }, []);
@@ -771,14 +781,31 @@ var EventGridBlocksSkia = ({
771
781
  const longPressGesture = Gesture.LongPress().onBegin((e) => {
772
782
  "worklet";
773
783
  runOnJS(onPressBegin)(Math.floor(e.y / rowHeight));
784
+ }).onTouchesUp(() => {
785
+ "worklet";
786
+ runOnJS(onTouchesUp)();
787
+ }).onEnd((e) => {
788
+ "worklet";
789
+ runOnJS(onSlotLongPress)(Math.floor(e.y / rowHeight));
790
+ }).onFinalize(() => {
791
+ "worklet";
792
+ runOnJS(onTouchesUp)();
793
+ });
794
+ const tapGesture = Gesture.Tap().onBegin((e) => {
795
+ "worklet";
796
+ runOnJS(onPressBegin)(Math.floor(e.y / rowHeight));
774
797
  }).onEnd((e) => {
775
798
  "worklet";
776
799
  runOnJS(onSlotPress)(Math.floor(e.y / rowHeight));
800
+ }).onTouchesUp(() => {
801
+ "worklet";
802
+ runOnJS(onTouchesUp)();
777
803
  }).onFinalize(() => {
778
804
  "worklet";
779
805
  runOnJS(onTouchesUp)();
780
806
  });
781
- return /* @__PURE__ */ React19.createElement(GestureDetector, { gesture: longPressGesture }, /* @__PURE__ */ React19.createElement(View, null, /* @__PURE__ */ React19.createElement(Canvas, { style: { width: APPOINTMENT_BLOCK_WIDTH, height: segmentHeight } }, firstRects.map(({ x, y, width: w, height: h, row }, idx) => /* @__PURE__ */ React19.createElement(React19.Fragment, { key: idx }, /* @__PURE__ */ React19.createElement(
807
+ const composedGesture = Gesture.Race(longPressGesture, tapGesture);
808
+ return /* @__PURE__ */ React19.createElement(GestureDetector, { gesture: composedGesture }, /* @__PURE__ */ React19.createElement(View, null, /* @__PURE__ */ React19.createElement(Canvas, { style: { width: APPOINTMENT_BLOCK_WIDTH, height: segmentHeight } }, firstRects.map(({ x, y, width: w, height: h, row }, idx) => /* @__PURE__ */ React19.createElement(React19.Fragment, { key: idx }, /* @__PURE__ */ React19.createElement(
782
809
  Rect$1,
783
810
  {
784
811
  x,
@@ -1320,9 +1347,11 @@ var CalendarInner = (props) => {
1320
1347
  resources,
1321
1348
  onResourcePress,
1322
1349
  onBlockLongPress,
1350
+ onBlockTap,
1323
1351
  onEventPress,
1324
1352
  onEventLongPress,
1325
1353
  onDisabledBlockPress,
1354
+ enableHapticFeedback = false,
1326
1355
  eventSlots,
1327
1356
  eventStyleOverrides,
1328
1357
  overLappingLayoutMode = "stacked",
@@ -1439,9 +1468,19 @@ var CalendarInner = (props) => {
1439
1468
  const startedX = useSharedValue(0);
1440
1469
  const startedY = useSharedValue(0);
1441
1470
  const touchY = useSharedValue(0);
1442
- const triggerHaptic = useCallback(() => {
1443
- Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
1444
- }, []);
1471
+ const triggerHaptic = useCallback(
1472
+ async (style = "Light") => {
1473
+ try {
1474
+ const Haptics = await import('expo-haptics');
1475
+ const feedbackStyle = Haptics.ImpactFeedbackStyle[style];
1476
+ if (enableHapticFeedback)
1477
+ await Haptics.impactAsync(feedbackStyle);
1478
+ } catch (e) {
1479
+ console.log("Haptics not available, skipping...");
1480
+ }
1481
+ },
1482
+ [enableHapticFeedback]
1483
+ );
1445
1484
  const resourceIds = useMemo(() => {
1446
1485
  const ids = resources?.map((item) => item?.id) || [];
1447
1486
  if (JSON.stringify(prevResourceIdsRef.current) !== JSON.stringify(ids)) {
@@ -1602,7 +1641,7 @@ var CalendarInner = (props) => {
1602
1641
  const increment = APPOINTMENT_BLOCK_WIDTH * Math.sign(autoScrollXSpeed.value);
1603
1642
  const newScrollX = scrollX.value + increment;
1604
1643
  runOnJS(scrollListTo)(newScrollX);
1605
- runOnJS(Haptics.impactAsync)(Haptics.ImpactFeedbackStyle.Medium);
1644
+ runOnJS(triggerHaptic)("Medium");
1606
1645
  }
1607
1646
  });
1608
1647
  useFrameCallback(() => {
@@ -1636,7 +1675,7 @@ var CalendarInner = (props) => {
1636
1675
  const scrollDiff = Math.abs(newScrollY - lastHapticScrollY.value);
1637
1676
  if (scrollDiff >= snapInterval) {
1638
1677
  lastHapticScrollY.value = newScrollY;
1639
- runOnJS(Haptics.impactAsync)(Haptics.ImpactFeedbackStyle.Medium);
1678
+ runOnJS(triggerHaptic)("Medium");
1640
1679
  }
1641
1680
  });
1642
1681
  useEffect(() => {
@@ -1670,7 +1709,7 @@ var CalendarInner = (props) => {
1670
1709
  eventHeight.value = initialHeight;
1671
1710
  setSelectedEvent(event);
1672
1711
  requestAnimationFrame(() => setDragReady(true));
1673
- Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
1712
+ runOnJS(triggerHaptic)("Medium");
1674
1713
  };
1675
1714
  }, []);
1676
1715
  const internalStableOnLongPress = useCallback((e) => {
@@ -1693,12 +1732,18 @@ var CalendarInner = (props) => {
1693
1732
  }
1694
1733
  }
1695
1734
  });
1696
- const handleBlockPress = useCallback((resourceId, time) => {
1697
- Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
1735
+ const handleBlockLongPress = useCallback((resourceId, time) => {
1736
+ runOnJS(triggerHaptic)("Medium");
1698
1737
  const resource = resources.find((r) => r.id === resourceId);
1699
1738
  if (onBlockLongPress)
1700
1739
  onBlockLongPress(resource, new Date(time));
1701
1740
  }, [resources, onBlockLongPress]);
1741
+ const handleBlockPress = useCallback((resourceId, time) => {
1742
+ runOnJS(triggerHaptic)("Medium");
1743
+ const resource = resources.find((r) => r.id === resourceId);
1744
+ if (onBlockTap)
1745
+ onBlockTap(resource, new Date(time));
1746
+ }, [resources, onBlockTap]);
1702
1747
  useEffect(() => {
1703
1748
  const handleOrientationChange = () => {
1704
1749
  if (selectedEvent) {
@@ -1722,7 +1767,8 @@ var CalendarInner = (props) => {
1722
1767
  {
1723
1768
  hourHeight,
1724
1769
  APPOINTMENT_BLOCK_WIDTH,
1725
- handleBlockPress: (time) => handleBlockPress(rid, combineDateAndTime(dayDate ?? dateRef.current, time))
1770
+ handleBlockPress: (time) => handleBlockPress(rid, combineDateAndTime(dayDate ?? dateRef.current, time)),
1771
+ handleBlockLongPress: (time) => handleBlockLongPress(rid, combineDateAndTime(dayDate ?? dateRef.current, time))
1726
1772
  }
1727
1773
  ), /* @__PURE__ */ React19__default.createElement(
1728
1774
  DisabledIntervals_default,