@estuary-solutions/rn-core-ui 0.0.3
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/LICENSE +20 -0
- package/README.md +743 -0
- package/dist/Accordion/Accordion.d.ts +5 -0
- package/dist/Accordion/Accordion.d.ts.map +1 -0
- package/dist/Accordion/Accordion.js +19 -0
- package/dist/Accordion/AccordionContext.d.ts +7 -0
- package/dist/Accordion/AccordionContext.d.ts.map +1 -0
- package/dist/Accordion/AccordionContext.js +3 -0
- package/dist/Accordion/AccordionGroup.d.ts +7 -0
- package/dist/Accordion/AccordionGroup.d.ts.map +1 -0
- package/dist/Accordion/AccordionGroup.js +32 -0
- package/dist/Accordion/AccordionItem.d.ts +5 -0
- package/dist/Accordion/AccordionItem.d.ts.map +1 -0
- package/dist/Accordion/AccordionItem.js +12 -0
- package/dist/Accordion/AccordionTree.d.ts +6 -0
- package/dist/Accordion/AccordionTree.d.ts.map +1 -0
- package/dist/Accordion/AccordionTree.js +4 -0
- package/dist/Accordion/AccordionTreeInternal.d.ts +5 -0
- package/dist/Accordion/AccordionTreeInternal.d.ts.map +1 -0
- package/dist/Accordion/AccordionTreeInternal.js +36 -0
- package/dist/Accordion/AccordionTreeWithGroup.d.ts +8 -0
- package/dist/Accordion/AccordionTreeWithGroup.d.ts.map +1 -0
- package/dist/Accordion/AccordionTreeWithGroup.js +11 -0
- package/dist/Accordion/index.d.ts +5 -0
- package/dist/Accordion/index.d.ts.map +1 -0
- package/dist/Accordion/index.js +4 -0
- package/dist/Accordion/types/AccordionTypes.d.ts +65 -0
- package/dist/Accordion/types/AccordionTypes.d.ts.map +1 -0
- package/dist/Accordion/types/AccordionTypes.js +1 -0
- package/dist/Avatars/Avatar.d.ts +20 -0
- package/dist/Avatars/Avatar.d.ts.map +1 -0
- package/dist/Avatars/Avatar.js +63 -0
- package/dist/Badges/Badge.d.ts +25 -0
- package/dist/Badges/Badge.d.ts.map +1 -0
- package/dist/Badges/Badge.js +75 -0
- package/dist/Breadcrumbs/Breadcrumb.d.ts +13 -0
- package/dist/Breadcrumbs/Breadcrumb.d.ts.map +1 -0
- package/dist/Breadcrumbs/Breadcrumb.js +63 -0
- package/dist/Button/Button.d.ts +7 -0
- package/dist/Button/Button.d.ts.map +1 -0
- package/dist/Button/Button.js +62 -0
- package/dist/Button/ButtonGradient.d.ts +5 -0
- package/dist/Button/ButtonGradient.d.ts.map +1 -0
- package/dist/Button/ButtonGradient.js +61 -0
- package/dist/Button/index.d.ts +4 -0
- package/dist/Button/index.d.ts.map +1 -0
- package/dist/Button/index.js +3 -0
- package/dist/Button/types/ButtonGradientTypes.d.ts +80 -0
- package/dist/Button/types/ButtonGradientTypes.d.ts.map +1 -0
- package/dist/Button/types/ButtonGradientTypes.js +1 -0
- package/dist/Button/types/ButtonTypes.d.ts +65 -0
- package/dist/Button/types/ButtonTypes.d.ts.map +1 -0
- package/dist/Button/types/ButtonTypes.js +1 -0
- package/dist/Buttons/Button.d.ts +23 -0
- package/dist/Buttons/Button.d.ts.map +1 -0
- package/dist/Buttons/Button.js +66 -0
- package/dist/Cards/Card.d.ts +22 -0
- package/dist/Cards/Card.d.ts.map +1 -0
- package/dist/Cards/Card.js +26 -0
- package/dist/Cards/CardActionArea.d.ts +13 -0
- package/dist/Cards/CardActionArea.d.ts.map +1 -0
- package/dist/Cards/CardActionArea.js +30 -0
- package/dist/Cards/CardActions.d.ts +14 -0
- package/dist/Cards/CardActions.d.ts.map +1 -0
- package/dist/Cards/CardActions.js +41 -0
- package/dist/Cards/CardContent.d.ts +13 -0
- package/dist/Cards/CardContent.d.ts.map +1 -0
- package/dist/Cards/CardContent.js +19 -0
- package/dist/Cards/CardHeader.d.ts +16 -0
- package/dist/Cards/CardHeader.d.ts.map +1 -0
- package/dist/Cards/CardHeader.js +61 -0
- package/dist/Cards/CardMedia.d.ts +23 -0
- package/dist/Cards/CardMedia.d.ts.map +1 -0
- package/dist/Cards/CardMedia.js +16 -0
- package/dist/Cards/Paper.d.ts +13 -0
- package/dist/Cards/Paper.d.ts.map +1 -0
- package/dist/Cards/Paper.js +42 -0
- package/dist/DraggableFlatList/CellDecorators.d.ts +21 -0
- package/dist/DraggableFlatList/CellDecorators.d.ts.map +1 -0
- package/dist/DraggableFlatList/CellDecorators.js +66 -0
- package/dist/DraggableFlatList/CellRendererComponent.d.ts +20 -0
- package/dist/DraggableFlatList/CellRendererComponent.d.ts.map +1 -0
- package/dist/DraggableFlatList/CellRendererComponent.js +146 -0
- package/dist/DraggableFlatList/DraggableFlatList.d.ts +9 -0
- package/dist/DraggableFlatList/DraggableFlatList.d.ts.map +1 -0
- package/dist/DraggableFlatList/DraggableFlatList.js +282 -0
- package/dist/DraggableFlatList/DraggableFlatList.web.d.ts +4 -0
- package/dist/DraggableFlatList/DraggableFlatList.web.d.ts.map +1 -0
- package/dist/DraggableFlatList/DraggableFlatList.web.js +248 -0
- package/dist/DraggableFlatList/NestableDraggableFlatList.d.ts +9 -0
- package/dist/DraggableFlatList/NestableDraggableFlatList.d.ts.map +1 -0
- package/dist/DraggableFlatList/NestableDraggableFlatList.js +66 -0
- package/dist/DraggableFlatList/NestableScrollContainer.d.ts +5 -0
- package/dist/DraggableFlatList/NestableScrollContainer.d.ts.map +1 -0
- package/dist/DraggableFlatList/NestableScrollContainer.js +28 -0
- package/dist/DraggableFlatList/PlaceholderItem.d.ts +8 -0
- package/dist/DraggableFlatList/PlaceholderItem.d.ts.map +1 -0
- package/dist/DraggableFlatList/PlaceholderItem.js +44 -0
- package/dist/DraggableFlatList/RowItem.d.ts +13 -0
- package/dist/DraggableFlatList/RowItem.d.ts.map +1 -0
- package/dist/DraggableFlatList/RowItem.js +45 -0
- package/dist/DraggableFlatList/ScrollOffsetListener.d.ts +8 -0
- package/dist/DraggableFlatList/ScrollOffsetListener.d.ts.map +1 -0
- package/dist/DraggableFlatList/ScrollOffsetListener.js +13 -0
- package/dist/Flex/Flex.d.ts +12 -0
- package/dist/Flex/Flex.d.ts.map +1 -0
- package/dist/Flex/Flex.js +28 -0
- package/dist/Flex/Flex.types.d.ts +10 -0
- package/dist/Flex/Flex.types.d.ts.map +1 -0
- package/dist/Flex/Flex.types.js +1 -0
- package/dist/Flex/index.d.ts +4 -0
- package/dist/Flex/index.d.ts.map +1 -0
- package/dist/Flex/index.js +3 -0
- package/dist/LICENSE +20 -0
- package/dist/README.md +743 -0
- package/dist/SvgIcon/SvgIcon.d.ts +9 -0
- package/dist/SvgIcon/SvgIcon.d.ts.map +1 -0
- package/dist/SvgIcon/SvgIcon.js +39 -0
- package/dist/SvgIcon/components/IconAlertCircle.d.ts +4 -0
- package/dist/SvgIcon/components/IconAlertCircle.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconAlertCircle.js +6 -0
- package/dist/SvgIcon/components/IconAngleLeft.d.ts +4 -0
- package/dist/SvgIcon/components/IconAngleLeft.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconAngleLeft.js +6 -0
- package/dist/SvgIcon/components/IconAngleRight.d.ts +4 -0
- package/dist/SvgIcon/components/IconAngleRight.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconAngleRight.js +6 -0
- package/dist/SvgIcon/components/IconCheckBox.d.ts +4 -0
- package/dist/SvgIcon/components/IconCheckBox.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconCheckBox.js +6 -0
- package/dist/SvgIcon/components/IconCheckBoxOutlineBlank.d.ts +4 -0
- package/dist/SvgIcon/components/IconCheckBoxOutlineBlank.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconCheckBoxOutlineBlank.js +6 -0
- package/dist/SvgIcon/components/IconCheckBoxWithBg.d.ts +4 -0
- package/dist/SvgIcon/components/IconCheckBoxWithBg.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconCheckBoxWithBg.js +6 -0
- package/dist/SvgIcon/components/IconChevronDown.d.ts +4 -0
- package/dist/SvgIcon/components/IconChevronDown.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconChevronDown.js +6 -0
- package/dist/SvgIcon/components/IconChevronUp.d.ts +4 -0
- package/dist/SvgIcon/components/IconChevronUp.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconChevronUp.js +6 -0
- package/dist/SvgIcon/components/IconHome.d.ts +4 -0
- package/dist/SvgIcon/components/IconHome.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconHome.js +6 -0
- package/dist/SvgIcon/components/IconPerson.d.ts +4 -0
- package/dist/SvgIcon/components/IconPerson.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconPerson.js +6 -0
- package/dist/SvgIcon/components/IconPlayCircle.d.ts +4 -0
- package/dist/SvgIcon/components/IconPlayCircle.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconPlayCircle.js +9 -0
- package/dist/SvgIcon/components/IconPlus.d.ts +4 -0
- package/dist/SvgIcon/components/IconPlus.d.ts.map +1 -0
- package/dist/SvgIcon/components/IconPlus.js +6 -0
- package/dist/SvgIcon/components/index.d.ts +13 -0
- package/dist/SvgIcon/components/index.d.ts.map +1 -0
- package/dist/SvgIcon/components/index.js +12 -0
- package/dist/SvgIcon/types/SvgIconTypes.d.ts +46 -0
- package/dist/SvgIcon/types/SvgIconTypes.d.ts.map +1 -0
- package/dist/SvgIcon/types/SvgIconTypes.js +1 -0
- package/dist/TextFields/TextField.d.ts +34 -0
- package/dist/TextFields/TextField.d.ts.map +1 -0
- package/dist/TextFields/TextField.js +400 -0
- package/dist/TextFields/index.d.ts +2 -0
- package/dist/TextFields/index.d.ts.map +1 -0
- package/dist/TextFields/index.js +1 -0
- package/dist/Texts/Text.d.ts +21 -0
- package/dist/Texts/Text.d.ts.map +1 -0
- package/dist/Texts/Text.js +49 -0
- package/dist/constants/DraggableFlatList/constants.d.ts +28 -0
- package/dist/constants/DraggableFlatList/constants.d.ts.map +1 -0
- package/dist/constants/DraggableFlatList/constants.js +25 -0
- package/dist/constants/DraggableFlatList/types.d.ts +65 -0
- package/dist/constants/DraggableFlatList/types.d.ts.map +1 -0
- package/dist/constants/DraggableFlatList/types.js +1 -0
- package/dist/constants/DraggableFlatList/types.web.d.ts +7 -0
- package/dist/constants/DraggableFlatList/types.web.d.ts.map +1 -0
- package/dist/constants/DraggableFlatList/types.web.js +1 -0
- package/dist/constants/consts.d.ts +16 -0
- package/dist/constants/consts.d.ts.map +1 -0
- package/dist/constants/consts.js +15 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +2 -0
- package/dist/constants/types.d.ts +22 -0
- package/dist/constants/types.d.ts.map +1 -0
- package/dist/constants/types.js +21 -0
- package/dist/context/DraggableFlatList/animatedValueContext.d.ts +29 -0
- package/dist/context/DraggableFlatList/animatedValueContext.d.ts.map +1 -0
- package/dist/context/DraggableFlatList/animatedValueContext.js +154 -0
- package/dist/context/DraggableFlatList/cellContext.d.ts +10 -0
- package/dist/context/DraggableFlatList/cellContext.d.ts.map +1 -0
- package/dist/context/DraggableFlatList/cellContext.js +18 -0
- package/dist/context/DraggableFlatList/draggableFlatListContext.d.ts +13 -0
- package/dist/context/DraggableFlatList/draggableFlatListContext.d.ts.map +1 -0
- package/dist/context/DraggableFlatList/draggableFlatListContext.js +19 -0
- package/dist/context/DraggableFlatList/nestableScrollContainerContext.d.ts +23 -0
- package/dist/context/DraggableFlatList/nestableScrollContainerContext.d.ts.map +1 -0
- package/dist/context/DraggableFlatList/nestableScrollContainerContext.js +36 -0
- package/dist/context/DraggableFlatList/propsContext.d.ts +9 -0
- package/dist/context/DraggableFlatList/propsContext.d.ts.map +1 -0
- package/dist/context/DraggableFlatList/propsContext.js +25 -0
- package/dist/context/DraggableFlatList/refContext.d.ts +20 -0
- package/dist/context/DraggableFlatList/refContext.d.ts.map +1 -0
- package/dist/context/DraggableFlatList/refContext.js +55 -0
- package/dist/hooks/DraggableFlatList/useAutoScroll.d.ts +2 -0
- package/dist/hooks/DraggableFlatList/useAutoScroll.d.ts.map +1 -0
- package/dist/hooks/DraggableFlatList/useAutoScroll.js +77 -0
- package/dist/hooks/DraggableFlatList/useCellTranslate.d.ts +9 -0
- package/dist/hooks/DraggableFlatList/useCellTranslate.d.ts.map +1 -0
- package/dist/hooks/DraggableFlatList/useCellTranslate.js +72 -0
- package/dist/hooks/DraggableFlatList/useNestedAutoScroll.d.ts +12 -0
- package/dist/hooks/DraggableFlatList/useNestedAutoScroll.d.ts.map +1 -0
- package/dist/hooks/DraggableFlatList/useNestedAutoScroll.js +77 -0
- package/dist/hooks/DraggableFlatList/useOnCellActiveAnimation.d.ts +15 -0
- package/dist/hooks/DraggableFlatList/useOnCellActiveAnimation.d.ts.map +1 -0
- package/dist/hooks/DraggableFlatList/useOnCellActiveAnimation.js +29 -0
- package/dist/hooks/DraggableFlatList/useStableCallback.d.ts +2 -0
- package/dist/hooks/DraggableFlatList/useStableCallback.d.ts.map +1 -0
- package/dist/hooks/DraggableFlatList/useStableCallback.js +11 -0
- package/dist/hooks/useTheme.d.ts +17 -0
- package/dist/hooks/useTheme.d.ts.map +1 -0
- package/dist/hooks/useTheme.js +12 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/themes/colors.d.ts +9 -0
- package/dist/themes/colors.d.ts.map +1 -0
- package/dist/themes/colors.js +201 -0
- package/dist/themes/elevationOverlay.d.ts +2 -0
- package/dist/themes/elevationOverlay.d.ts.map +1 -0
- package/dist/themes/elevationOverlay.js +12 -0
- package/dist/themes/fontSize.d.ts +23 -0
- package/dist/themes/fontSize.d.ts.map +1 -0
- package/dist/themes/fontSize.js +22 -0
- package/dist/themes/index.d.ts +5 -0
- package/dist/themes/index.d.ts.map +1 -0
- package/dist/themes/index.js +4 -0
- package/dist/themes/types/colorTypes.d.ts +665 -0
- package/dist/themes/types/colorTypes.d.ts.map +1 -0
- package/dist/themes/types/colorTypes.js +1 -0
- package/dist/utils/DraggableFlatList/typedMemo.d.ts +2 -0
- package/dist/utils/DraggableFlatList/typedMemo.d.ts.map +1 -0
- package/dist/utils/DraggableFlatList/typedMemo.js +2 -0
- package/dist/utils/cleanTagHTML.d.ts +22 -0
- package/dist/utils/cleanTagHTML.d.ts.map +1 -0
- package/dist/utils/cleanTagHTML.js +36 -0
- package/dist/utils/colors/color.d.ts +2 -0
- package/dist/utils/colors/color.d.ts.map +1 -0
- package/dist/utils/colors/color.js +6 -0
- package/dist/utils/colors/elevation.d.ts +7 -0
- package/dist/utils/colors/elevation.d.ts.map +1 -0
- package/dist/utils/colors/elevation.js +29 -0
- package/dist/utils/colors/index.d.ts +9 -0
- package/dist/utils/colors/index.d.ts.map +1 -0
- package/dist/utils/colors/index.js +7 -0
- package/dist/utils/converter.d.ts +47 -0
- package/dist/utils/converter.d.ts.map +1 -0
- package/dist/utils/converter.js +54 -0
- package/dist/utils/debounce.d.ts +36 -0
- package/dist/utils/debounce.d.ts.map +1 -0
- package/dist/utils/debounce.js +54 -0
- package/dist/utils/filters.d.ts +3 -0
- package/dist/utils/filters.d.ts.map +1 -0
- package/dist/utils/filters.js +10 -0
- package/dist/utils/fixedDistance.d.ts +16 -0
- package/dist/utils/fixedDistance.d.ts.map +1 -0
- package/dist/utils/fixedDistance.js +17 -0
- package/dist/utils/formatMoney.d.ts +30 -0
- package/dist/utils/formatMoney.d.ts.map +1 -0
- package/dist/utils/formatMoney.js +33 -0
- package/dist/utils/getOS.d.ts +6 -0
- package/dist/utils/getOS.d.ts.map +1 -0
- package/dist/utils/getOS.js +6 -0
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +12 -0
- package/dist/utils/limitedString.d.ts +15 -0
- package/dist/utils/limitedString.d.ts.map +1 -0
- package/dist/utils/limitedString.js +19 -0
- package/dist/utils/resolutions.d.ts +65 -0
- package/dist/utils/resolutions.d.ts.map +1 -0
- package/dist/utils/resolutions.js +79 -0
- package/dist/utils/scale.d.ts +141 -0
- package/dist/utils/scale.d.ts.map +1 -0
- package/dist/utils/scale.js +141 -0
- package/documents/build.js +102 -0
- package/documents/buildFromRoot.js +49 -0
- package/documents/buildFromSample.js +40 -0
- package/documents/buildV2.js +98 -0
- package/documents/copyPackageToExample.js +31 -0
- package/example/RNCoreUISample/.eslintrc.js +10 -0
- package/example/RNCoreUISample/.prettierrc.js +7 -0
- package/example/RNCoreUISample/App.js +26 -0
- package/example/RNCoreUISample/README.md +104 -0
- package/example/RNCoreUISample/android/app/debug.keystore +0 -0
- package/example/RNCoreUISample/babel.config.js +29 -0
- package/example/RNCoreUISample/documents/storybook/manager.js +5 -0
- package/example/RNCoreUISample/fix_node_modules.js +12 -0
- package/example/RNCoreUISample/index.js +20 -0
- package/example/RNCoreUISample/jest.config.js +3 -0
- package/example/RNCoreUISample/metro.config.js +30 -0
- package/package.json +101 -0
- package/src/constants/DraggableFlatList/draggable.d.ts +12 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import React from "react";
|
|
14
|
+
import { InteractionManager, } from "react-native";
|
|
15
|
+
import { FlatList, Gesture, GestureDetector, } from "react-native-gesture-handler";
|
|
16
|
+
import Animated, { runOnJS, useAnimatedReaction, useAnimatedScrollHandler, useSharedValue, withSpring, } from "react-native-reanimated";
|
|
17
|
+
import CellRendererComponent from "./CellRendererComponent";
|
|
18
|
+
import PlaceholderItem from "./PlaceholderItem";
|
|
19
|
+
import RowItem from "./RowItem";
|
|
20
|
+
import ScrollOffsetListener from "./ScrollOffsetListener";
|
|
21
|
+
import { typedMemo } from "../utils/DraggableFlatList/typedMemo";
|
|
22
|
+
import { useStableCallback } from "../hooks/DraggableFlatList/useStableCallback";
|
|
23
|
+
import { useAutoScroll } from "../hooks/DraggableFlatList/useAutoScroll";
|
|
24
|
+
import DraggableFlatListProvider from "../context/DraggableFlatList/draggableFlatListContext";
|
|
25
|
+
import { DEFAULT_PROPS } from "../constants/DraggableFlatList/constants";
|
|
26
|
+
import PropsProvider from "../context/DraggableFlatList/propsContext";
|
|
27
|
+
import AnimatedValueProvider, { useAnimatedValues, } from "../context/DraggableFlatList/animatedValueContext";
|
|
28
|
+
import RefProvider, { useRefs } from "../context/DraggableFlatList/refContext";
|
|
29
|
+
import { WEB } from "../utils";
|
|
30
|
+
// Web version import
|
|
31
|
+
let DraggableFlatListWeb = null;
|
|
32
|
+
if (WEB) {
|
|
33
|
+
try {
|
|
34
|
+
DraggableFlatListWeb = require("./DraggableFlatList.web").default;
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
// Web version not available or failed to load
|
|
38
|
+
console.warn("Web version of DraggableFlatList not available:", e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);
|
|
42
|
+
function DraggableFlatListInner(props) {
|
|
43
|
+
const { cellDataRef, containerRef, flatlistRef, keyToIndexRef, propsRef, animationConfigRef, } = useRefs();
|
|
44
|
+
const { activeCellOffset, activeCellSize, activeIndexAnim, containerSize, scrollOffset, scrollViewSize, spacerIndexAnim, horizontalAnim, placeholderOffset, touchTranslate, autoScrollDistance, panGestureState, isTouchActiveNative, viewableIndexMin, viewableIndexMax, disabled, } = useAnimatedValues();
|
|
45
|
+
const reset = useStableCallback(() => {
|
|
46
|
+
activeIndexAnim.value = -1;
|
|
47
|
+
spacerIndexAnim.value = -1;
|
|
48
|
+
touchTranslate.value = 0;
|
|
49
|
+
activeCellSize.value = -1;
|
|
50
|
+
activeCellOffset.value = -1;
|
|
51
|
+
setActiveKey(null);
|
|
52
|
+
});
|
|
53
|
+
const { dragHitSlop = DEFAULT_PROPS.dragHitSlop, scrollEnabled = DEFAULT_PROPS.scrollEnabled, activationDistance: activationDistanceProp = DEFAULT_PROPS.activationDistance, } = props;
|
|
54
|
+
let [activeKey, setActiveKey] = React.useState(null);
|
|
55
|
+
const [layoutAnimationDisabled, setLayoutAnimationDisabled] = React.useState(!propsRef.current.enableLayoutAnimationExperimental);
|
|
56
|
+
const keyExtractor = useStableCallback((item, index) => {
|
|
57
|
+
if (!props.keyExtractor) {
|
|
58
|
+
throw new Error("You must provide a keyExtractor to DraggableFlatList");
|
|
59
|
+
}
|
|
60
|
+
return props.keyExtractor(item, index);
|
|
61
|
+
});
|
|
62
|
+
const dataRef = React.useRef(props.data);
|
|
63
|
+
const dataHasChanged = dataRef.current.map(keyExtractor).join("") !==
|
|
64
|
+
props.data.map(keyExtractor).join("");
|
|
65
|
+
dataRef.current = props.data;
|
|
66
|
+
if (dataHasChanged) {
|
|
67
|
+
// When data changes make sure `activeKey` is nulled out in the same render pass
|
|
68
|
+
activeKey = null;
|
|
69
|
+
InteractionManager.runAfterInteractions(() => {
|
|
70
|
+
reset();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
React.useEffect(() => {
|
|
74
|
+
if (!propsRef.current.enableLayoutAnimationExperimental)
|
|
75
|
+
return;
|
|
76
|
+
if (activeKey) {
|
|
77
|
+
setLayoutAnimationDisabled(true);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// setTimeout result of trial-and-error to determine how long to wait before
|
|
81
|
+
// re-enabling layout animations so that a drag reorder does not trigger it.
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
setLayoutAnimationDisabled(false);
|
|
84
|
+
}, 100);
|
|
85
|
+
}
|
|
86
|
+
}, [activeKey]);
|
|
87
|
+
React.useLayoutEffect(() => {
|
|
88
|
+
props.data.forEach((d, i) => {
|
|
89
|
+
const key = keyExtractor(d, i);
|
|
90
|
+
keyToIndexRef.current.set(key, i);
|
|
91
|
+
});
|
|
92
|
+
}, [props.data, keyExtractor, keyToIndexRef]);
|
|
93
|
+
const drag = useStableCallback((activeKey) => {
|
|
94
|
+
if (disabled.value)
|
|
95
|
+
return;
|
|
96
|
+
const index = keyToIndexRef.current.get(activeKey);
|
|
97
|
+
const cellData = cellDataRef.current.get(activeKey);
|
|
98
|
+
if (cellData) {
|
|
99
|
+
activeCellOffset.value = cellData.measurements.offset;
|
|
100
|
+
activeCellSize.value = cellData.measurements.size;
|
|
101
|
+
}
|
|
102
|
+
const { onDragBegin } = propsRef.current;
|
|
103
|
+
if (index !== undefined) {
|
|
104
|
+
spacerIndexAnim.value = index;
|
|
105
|
+
activeIndexAnim.value = index;
|
|
106
|
+
setActiveKey(activeKey);
|
|
107
|
+
onDragBegin === null || onDragBegin === void 0 ? void 0 : onDragBegin(index);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const onContainerLayout = ({ nativeEvent: { layout }, }) => {
|
|
111
|
+
var _a;
|
|
112
|
+
const { width, height } = layout;
|
|
113
|
+
containerSize.value = props.horizontal ? width : height;
|
|
114
|
+
(_a = props.onContainerLayout) === null || _a === void 0 ? void 0 : _a.call(props, { layout, containerRef });
|
|
115
|
+
};
|
|
116
|
+
const onListContentSizeChange = (w, h) => {
|
|
117
|
+
var _a;
|
|
118
|
+
scrollViewSize.value = props.horizontal ? w : h;
|
|
119
|
+
(_a = props.onContentSizeChange) === null || _a === void 0 ? void 0 : _a.call(props, w, h);
|
|
120
|
+
};
|
|
121
|
+
const onContainerTouchStart = () => {
|
|
122
|
+
if (!disabled.value) {
|
|
123
|
+
isTouchActiveNative.value = true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
};
|
|
127
|
+
const onContainerTouchEnd = () => {
|
|
128
|
+
isTouchActiveNative.value = false;
|
|
129
|
+
};
|
|
130
|
+
const extraData = React.useMemo(() => ({
|
|
131
|
+
activeKey,
|
|
132
|
+
extraData: props.extraData,
|
|
133
|
+
}), [activeKey, props.extraData]);
|
|
134
|
+
const renderItem = React.useCallback(({ item, index }) => {
|
|
135
|
+
const key = keyExtractor(item, index);
|
|
136
|
+
if (index !== keyToIndexRef.current.get(key)) {
|
|
137
|
+
keyToIndexRef.current.set(key, index);
|
|
138
|
+
}
|
|
139
|
+
return (_jsx(RowItem, { item: item, itemKey: key, renderItem: props.renderItem, drag: drag, extraData: props.extraData }));
|
|
140
|
+
}, [props.renderItem, props.extraData, drag, keyExtractor]);
|
|
141
|
+
const onRelease = useStableCallback((index) => {
|
|
142
|
+
var _a;
|
|
143
|
+
(_a = props.onRelease) === null || _a === void 0 ? void 0 : _a.call(props, index);
|
|
144
|
+
});
|
|
145
|
+
const onDragEnd = useStableCallback(({ from, to }) => {
|
|
146
|
+
const { onDragEnd, data } = props;
|
|
147
|
+
const newData = [...data];
|
|
148
|
+
if (from !== to) {
|
|
149
|
+
newData.splice(from, 1);
|
|
150
|
+
newData.splice(to, 0, data[from]);
|
|
151
|
+
}
|
|
152
|
+
onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd({ from, to, data: newData });
|
|
153
|
+
setActiveKey(null);
|
|
154
|
+
});
|
|
155
|
+
const onPlaceholderIndexChange = useStableCallback((index) => {
|
|
156
|
+
var _a;
|
|
157
|
+
(_a = props.onPlaceholderIndexChange) === null || _a === void 0 ? void 0 : _a.call(props, index);
|
|
158
|
+
});
|
|
159
|
+
// Handle case where user ends drag without moving their finger.
|
|
160
|
+
useAnimatedReaction(() => {
|
|
161
|
+
return isTouchActiveNative.value;
|
|
162
|
+
}, (cur, prev) => {
|
|
163
|
+
if (cur !== prev && !cur) {
|
|
164
|
+
const hasMoved = !!touchTranslate.value;
|
|
165
|
+
if (!hasMoved && activeIndexAnim.value >= 0 && !disabled.value) {
|
|
166
|
+
runOnJS(onRelease)(activeIndexAnim.value);
|
|
167
|
+
runOnJS(onDragEnd)({
|
|
168
|
+
from: activeIndexAnim.value,
|
|
169
|
+
to: spacerIndexAnim.value,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}, [isTouchActiveNative, onDragEnd, onRelease]);
|
|
174
|
+
useAnimatedReaction(() => {
|
|
175
|
+
return spacerIndexAnim.value;
|
|
176
|
+
}, (cur, prev) => {
|
|
177
|
+
if (prev !== null && cur !== prev && cur >= 0 && prev >= 0) {
|
|
178
|
+
runOnJS(onPlaceholderIndexChange)(cur);
|
|
179
|
+
}
|
|
180
|
+
}, [spacerIndexAnim]);
|
|
181
|
+
const gestureDisabled = useSharedValue(false);
|
|
182
|
+
const panGesture = Gesture.Pan()
|
|
183
|
+
.onBegin((evt) => {
|
|
184
|
+
gestureDisabled.value = disabled.value;
|
|
185
|
+
if (gestureDisabled.value)
|
|
186
|
+
return;
|
|
187
|
+
panGestureState.value = evt.state;
|
|
188
|
+
})
|
|
189
|
+
.onUpdate((evt) => {
|
|
190
|
+
if (gestureDisabled.value)
|
|
191
|
+
return;
|
|
192
|
+
panGestureState.value = evt.state;
|
|
193
|
+
const translation = horizontalAnim.value
|
|
194
|
+
? evt.translationX
|
|
195
|
+
: evt.translationY;
|
|
196
|
+
touchTranslate.value = translation;
|
|
197
|
+
})
|
|
198
|
+
.onEnd((evt) => {
|
|
199
|
+
if (gestureDisabled.value)
|
|
200
|
+
return;
|
|
201
|
+
// Set touch val to current translate val
|
|
202
|
+
isTouchActiveNative.value = false;
|
|
203
|
+
const translation = horizontalAnim.value
|
|
204
|
+
? evt.translationX
|
|
205
|
+
: evt.translationY;
|
|
206
|
+
touchTranslate.value = translation + autoScrollDistance.value;
|
|
207
|
+
panGestureState.value = evt.state;
|
|
208
|
+
// Only call onDragEnd if actually dragging a cell
|
|
209
|
+
if (activeIndexAnim.value === -1 || disabled.value)
|
|
210
|
+
return;
|
|
211
|
+
disabled.value = true;
|
|
212
|
+
runOnJS(onRelease)(activeIndexAnim.value);
|
|
213
|
+
const springTo = placeholderOffset.value - activeCellOffset.value;
|
|
214
|
+
touchTranslate.value = withSpring(springTo, animationConfigRef.value, () => {
|
|
215
|
+
runOnJS(onDragEnd)({
|
|
216
|
+
from: activeIndexAnim.value,
|
|
217
|
+
to: spacerIndexAnim.value,
|
|
218
|
+
});
|
|
219
|
+
disabled.value = false;
|
|
220
|
+
});
|
|
221
|
+
})
|
|
222
|
+
.onTouchesDown(() => {
|
|
223
|
+
runOnJS(onContainerTouchStart)();
|
|
224
|
+
})
|
|
225
|
+
.onTouchesUp(() => {
|
|
226
|
+
// Turning this into a worklet causes timing issues. We want it to run
|
|
227
|
+
// just after the finger lifts.
|
|
228
|
+
runOnJS(onContainerTouchEnd)();
|
|
229
|
+
});
|
|
230
|
+
if (dragHitSlop)
|
|
231
|
+
panGesture.hitSlop(dragHitSlop);
|
|
232
|
+
if (activationDistanceProp) {
|
|
233
|
+
const activeOffset = [
|
|
234
|
+
-activationDistanceProp,
|
|
235
|
+
activationDistanceProp,
|
|
236
|
+
];
|
|
237
|
+
if (props.horizontal) {
|
|
238
|
+
panGesture.activeOffsetX(activeOffset);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
panGesture.activeOffsetY(activeOffset);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const onScroll = useStableCallback((scrollOffset) => {
|
|
245
|
+
var _a;
|
|
246
|
+
(_a = props.onScrollOffsetChange) === null || _a === void 0 ? void 0 : _a.call(props, scrollOffset);
|
|
247
|
+
});
|
|
248
|
+
const scrollHandler = useAnimatedScrollHandler({
|
|
249
|
+
onScroll: (evt) => {
|
|
250
|
+
scrollOffset.value = horizontalAnim.value
|
|
251
|
+
? evt.contentOffset.x
|
|
252
|
+
: evt.contentOffset.y;
|
|
253
|
+
runOnJS(onScroll)(scrollOffset.value);
|
|
254
|
+
},
|
|
255
|
+
}, [horizontalAnim]);
|
|
256
|
+
useAutoScroll();
|
|
257
|
+
const onViewableItemsChanged = useStableCallback((info) => {
|
|
258
|
+
var _a;
|
|
259
|
+
const viewableIndices = info.viewableItems
|
|
260
|
+
.filter((item) => item.isViewable)
|
|
261
|
+
.map((item) => item.index)
|
|
262
|
+
.filter((index) => typeof index === "number");
|
|
263
|
+
const min = Math.min(...viewableIndices);
|
|
264
|
+
const max = Math.max(...viewableIndices);
|
|
265
|
+
viewableIndexMin.value = min;
|
|
266
|
+
viewableIndexMax.value = max;
|
|
267
|
+
(_a = props.onViewableItemsChanged) === null || _a === void 0 ? void 0 : _a.call(props, info);
|
|
268
|
+
});
|
|
269
|
+
return (_jsx(DraggableFlatListProvider, { activeKey: activeKey, keyExtractor: keyExtractor, horizontal: !!props.horizontal, layoutAnimationDisabled: layoutAnimationDisabled, children: _jsx(GestureDetector, { gesture: panGesture, children: _jsxs(Animated.View, { style: props.containerStyle, ref: containerRef, onLayout: onContainerLayout, children: [props.renderPlaceholder && (_jsx(PlaceholderItem, { renderPlaceholder: props.renderPlaceholder })), _jsx(AnimatedFlatList, Object.assign({}, props, { data: props.data, onViewableItemsChanged: onViewableItemsChanged, CellRendererComponent: CellRendererComponent, ref: flatlistRef, onContentSizeChange: onListContentSizeChange, scrollEnabled: !activeKey && scrollEnabled, renderItem: renderItem, extraData: extraData, keyExtractor: keyExtractor, onScroll: scrollHandler, scrollEventThrottle: 16, simultaneousHandlers: props.simultaneousHandlers, removeClippedSubviews: false })), !!props.onScrollOffsetChange && (_jsx(ScrollOffsetListener, { onScrollOffsetChange: props.onScrollOffsetChange, scrollOffset: scrollOffset }))] }) }) }));
|
|
270
|
+
}
|
|
271
|
+
function DraggableFlatList(props, ref) {
|
|
272
|
+
// Use web version if available and on web platform
|
|
273
|
+
if (WEB && DraggableFlatListWeb) {
|
|
274
|
+
const { data, renderItem, keyExtractor, onDragEnd, onDragBegin, onRelease, onPlaceholderIndexChange, activationDistance, containerStyle, horizontal } = props, otherProps = __rest(props, ["data", "renderItem", "keyExtractor", "onDragEnd", "onDragBegin", "onRelease", "onPlaceholderIndexChange", "activationDistance", "containerStyle", "horizontal"]);
|
|
275
|
+
return (_jsx(DraggableFlatListWeb, Object.assign({ data: data, renderItem: renderItem, keyExtractor: keyExtractor, onDragEnd: onDragEnd, onDragBegin: onDragBegin, onRelease: onRelease, onPlaceholderIndexChange: onPlaceholderIndexChange, activationDistance: activationDistance, containerStyle: containerStyle ? containerStyle : undefined, horizontal: horizontal }, otherProps)));
|
|
276
|
+
}
|
|
277
|
+
return (_jsx(PropsProvider, Object.assign({}, props, { children: _jsx(AnimatedValueProvider, { children: _jsx(RefProvider, { flatListRef: ref, children: _jsx(MemoizedInner, Object.assign({}, props)) }) }) })));
|
|
278
|
+
}
|
|
279
|
+
const MemoizedInner = typedMemo(DraggableFlatListInner);
|
|
280
|
+
// Generic forwarded ref type assertion taken from:
|
|
281
|
+
// https://fettblog.eu/typescript-react-generic-forward-refs/#option-1%3A-type-assertion
|
|
282
|
+
export default React.forwardRef(DraggableFlatList);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { WebDraggableFlatListProps } from "../constants/DraggableFlatList/types.web";
|
|
2
|
+
declare function DraggableFlatListWeb<T>({ data, renderItem, keyExtractor, onDragEnd, onDragBegin, onRelease, onPlaceholderIndexChange, activationDistance, containerStyle, horizontal, ...props }: WebDraggableFlatListProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export default DraggableFlatListWeb;
|
|
4
|
+
//# sourceMappingURL=DraggableFlatList.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DraggableFlatList.web.d.ts","sourceRoot":"","sources":["../../src/DraggableFlatList/DraggableFlatList.web.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,iBAAS,oBAAoB,CAAC,CAAC,EAAE,EAC/B,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,WAAW,EACX,SAAS,EACT,wBAAwB,EACxB,kBAAqD,EACrD,cAAc,EACd,UAAkB,EAClB,GAAG,KAAK,EACT,EAAE,yBAAyB,CAAC,CAAC,CAAC,2CAwW9B;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
/// <reference lib="dom" /> TODO: DO NOT REMOVE THIS LINE
|
|
14
|
+
import React from "react";
|
|
15
|
+
import { DEFAULT_PROPS } from "../constants/DraggableFlatList/constants";
|
|
16
|
+
import { CellProvider } from "../context/DraggableFlatList/cellContext";
|
|
17
|
+
import DraggableFlatListProvider from "../context/DraggableFlatList/draggableFlatListContext";
|
|
18
|
+
function DraggableFlatListWeb(_a) {
|
|
19
|
+
var { data, renderItem, keyExtractor, onDragEnd, onDragBegin, onRelease, onPlaceholderIndexChange, activationDistance = DEFAULT_PROPS.activationDistance, containerStyle, horizontal = false } = _a, props = __rest(_a, ["data", "renderItem", "keyExtractor", "onDragEnd", "onDragBegin", "onRelease", "onPlaceholderIndexChange", "activationDistance", "containerStyle", "horizontal"]);
|
|
20
|
+
const [draggedIndex, setDraggedIndex] = React.useState(null);
|
|
21
|
+
const [tempData, setTempData] = React.useState(null);
|
|
22
|
+
const placeholderIndexRef = React.useRef(null);
|
|
23
|
+
const containerRef = React.useRef(null);
|
|
24
|
+
const itemRefs = React.useRef(new Map());
|
|
25
|
+
const currentIndexRef = React.useRef(null);
|
|
26
|
+
const draggedKeyRef = React.useRef(null);
|
|
27
|
+
const positionsRef = React.useRef(new Map());
|
|
28
|
+
const lastReorderIndexRef = React.useRef(null);
|
|
29
|
+
const lastPointerRef = React.useRef(null);
|
|
30
|
+
const dragAnchorRef = React.useRef(null);
|
|
31
|
+
const containerRectRef = React.useRef(null);
|
|
32
|
+
const [dragGhost, setDragGhost] = React.useState(null);
|
|
33
|
+
const activeKey = draggedKeyRef.current;
|
|
34
|
+
const getKey = React.useCallback((item, index) => {
|
|
35
|
+
return keyExtractor(item, index);
|
|
36
|
+
}, [keyExtractor]);
|
|
37
|
+
const handleDragStart = React.useCallback((e, index) => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
setDraggedIndex(index);
|
|
40
|
+
const key = keyExtractor(data[index], index);
|
|
41
|
+
draggedKeyRef.current = key;
|
|
42
|
+
currentIndexRef.current = index;
|
|
43
|
+
setTempData([...data]);
|
|
44
|
+
placeholderIndexRef.current = index;
|
|
45
|
+
onDragBegin === null || onDragBegin === void 0 ? void 0 : onDragBegin(index);
|
|
46
|
+
e.dataTransfer.effectAllowed = "move";
|
|
47
|
+
e.dataTransfer.setData("text/plain", index.toString());
|
|
48
|
+
const el = itemRefs.current.get(key);
|
|
49
|
+
if (el) {
|
|
50
|
+
const rect = el.getBoundingClientRect();
|
|
51
|
+
const container = containerRef.current;
|
|
52
|
+
if (container) {
|
|
53
|
+
containerRectRef.current = container.getBoundingClientRect();
|
|
54
|
+
}
|
|
55
|
+
const img = new Image();
|
|
56
|
+
img.src =
|
|
57
|
+
"data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'></svg>";
|
|
58
|
+
e.dataTransfer.setDragImage(img, 0, 0);
|
|
59
|
+
const mouseY = e.clientY;
|
|
60
|
+
const mouseX = e.clientX;
|
|
61
|
+
const anchor = dragAnchorRef.current;
|
|
62
|
+
setDragGhost({
|
|
63
|
+
x: e.clientX,
|
|
64
|
+
y: e.clientY,
|
|
65
|
+
offsetX: (_a = anchor === null || anchor === void 0 ? void 0 : anchor.offsetX) !== null && _a !== void 0 ? _a : rect.width / 2,
|
|
66
|
+
offsetY: (_b = anchor === null || anchor === void 0 ? void 0 : anchor.offsetY) !== null && _b !== void 0 ? _b : rect.height / 2,
|
|
67
|
+
width: rect.width,
|
|
68
|
+
height: rect.height,
|
|
69
|
+
item: data[index],
|
|
70
|
+
index,
|
|
71
|
+
key,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}, [onDragBegin, data, keyExtractor]);
|
|
75
|
+
const handleDragEnd = React.useCallback(() => {
|
|
76
|
+
if (draggedIndex !== null) {
|
|
77
|
+
onRelease === null || onRelease === void 0 ? void 0 : onRelease(draggedIndex);
|
|
78
|
+
}
|
|
79
|
+
placeholderIndexRef.current = null;
|
|
80
|
+
lastPointerRef.current = null;
|
|
81
|
+
setDraggedIndex(null);
|
|
82
|
+
setDragGhost(null);
|
|
83
|
+
lastReorderIndexRef.current = null;
|
|
84
|
+
}, [draggedIndex, onRelease]);
|
|
85
|
+
const handleContainerDragOver = React.useCallback((e) => {
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
setDragGhost((prev) => {
|
|
88
|
+
const rect = containerRectRef.current;
|
|
89
|
+
if (!prev || !rect)
|
|
90
|
+
return prev;
|
|
91
|
+
return Object.assign(Object.assign({}, prev), { x: e.clientX - rect.left, y: e.clientY - rect.top });
|
|
92
|
+
});
|
|
93
|
+
if (!tempData || !draggedKeyRef.current)
|
|
94
|
+
return;
|
|
95
|
+
const mouseY = e.clientY;
|
|
96
|
+
const mouseX = e.clientX;
|
|
97
|
+
let nextIndex = null;
|
|
98
|
+
if (lastPointerRef.current) {
|
|
99
|
+
const dx = Math.abs(mouseX - lastPointerRef.current.x);
|
|
100
|
+
const dy = Math.abs(mouseY - lastPointerRef.current.y);
|
|
101
|
+
if (dx < 2 && dy < 2) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
lastPointerRef.current = { x: mouseX, y: mouseY };
|
|
106
|
+
for (let i = 0; i < tempData.length; i++) {
|
|
107
|
+
const key = keyExtractor(tempData[i], i);
|
|
108
|
+
const el = itemRefs.current.get(key);
|
|
109
|
+
if (!el)
|
|
110
|
+
continue;
|
|
111
|
+
const rect = el.getBoundingClientRect();
|
|
112
|
+
const isInside = horizontal
|
|
113
|
+
? mouseX >= rect.left && mouseX <= rect.right
|
|
114
|
+
: mouseY >= rect.top && mouseY <= rect.bottom;
|
|
115
|
+
if (!isInside)
|
|
116
|
+
continue;
|
|
117
|
+
const isAfter = horizontal
|
|
118
|
+
? mouseX > rect.left + rect.width / 1.5
|
|
119
|
+
: mouseY > rect.top + rect.height / 1.5;
|
|
120
|
+
nextIndex = isAfter ? i + 1 : i;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
if (nextIndex === null ||
|
|
124
|
+
placeholderIndexRef.current === nextIndex ||
|
|
125
|
+
lastReorderIndexRef.current === nextIndex) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
positionsRef.current.clear();
|
|
129
|
+
tempData.forEach((item, index) => {
|
|
130
|
+
const key = keyExtractor(item, index);
|
|
131
|
+
const el = itemRefs.current.get(key);
|
|
132
|
+
if (el)
|
|
133
|
+
positionsRef.current.set(key, el.getBoundingClientRect());
|
|
134
|
+
});
|
|
135
|
+
placeholderIndexRef.current = nextIndex;
|
|
136
|
+
onPlaceholderIndexChange === null || onPlaceholderIndexChange === void 0 ? void 0 : onPlaceholderIndexChange(nextIndex);
|
|
137
|
+
setTempData((prev) => {
|
|
138
|
+
if (!prev || !draggedKeyRef.current)
|
|
139
|
+
return prev;
|
|
140
|
+
const from = prev.findIndex((item, index) => keyExtractor(item, index) === draggedKeyRef.current);
|
|
141
|
+
if (from === -1 || from === nextIndex)
|
|
142
|
+
return prev;
|
|
143
|
+
const arr = [...prev];
|
|
144
|
+
const [item] = arr.splice(from, 1);
|
|
145
|
+
arr.splice(nextIndex, 0, item);
|
|
146
|
+
return arr;
|
|
147
|
+
});
|
|
148
|
+
lastReorderIndexRef.current = nextIndex;
|
|
149
|
+
requestAnimationFrame(() => {
|
|
150
|
+
positionsRef.current.forEach((prevRect, key) => {
|
|
151
|
+
if (key === draggedKeyRef.current)
|
|
152
|
+
return;
|
|
153
|
+
const el = itemRefs.current.get(key);
|
|
154
|
+
if (!el)
|
|
155
|
+
return;
|
|
156
|
+
const nextRect = el.getBoundingClientRect();
|
|
157
|
+
const dx = prevRect.left - nextRect.left;
|
|
158
|
+
const dy = prevRect.top - nextRect.top;
|
|
159
|
+
if (!dx && !dy)
|
|
160
|
+
return;
|
|
161
|
+
el.style.transform = `translate(${dx}px, ${dy}px)`;
|
|
162
|
+
el.style.transition = "none";
|
|
163
|
+
requestAnimationFrame(() => {
|
|
164
|
+
el.style.transform = "";
|
|
165
|
+
el.style.transition =
|
|
166
|
+
"transform 220ms cubic-bezier(0.22, 1, 0.36, 1)";
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}, [tempData, horizontal, keyExtractor, onPlaceholderIndexChange]);
|
|
171
|
+
const workingData = tempData !== null && tempData !== void 0 ? tempData : data;
|
|
172
|
+
const getItemStyle = (key) => key === draggedKeyRef.current ? { opacity: 0 } : {};
|
|
173
|
+
React.useLayoutEffect(() => {
|
|
174
|
+
if (draggedKeyRef.current !== null)
|
|
175
|
+
return;
|
|
176
|
+
itemRefs.current.forEach((el) => {
|
|
177
|
+
el.style.transform = "";
|
|
178
|
+
el.style.transition = "";
|
|
179
|
+
});
|
|
180
|
+
}, [workingData]);
|
|
181
|
+
return (_jsx(DraggableFlatListProvider, { activeKey: activeKey, keyExtractor: keyExtractor, horizontal: !!horizontal, layoutAnimationDisabled: false, children: _jsxs("div", Object.assign({ ref: containerRef, style: Object.assign({ display: horizontal ? "flex" : "block", overflow: horizontal ? "auto" : "visible", minHeight: horizontal ? "auto" : "100%" }, containerStyle), onDragOver: handleContainerDragOver, onDrop: (e) => {
|
|
182
|
+
e.preventDefault();
|
|
183
|
+
if (!tempData || !draggedKeyRef.current)
|
|
184
|
+
return;
|
|
185
|
+
const from = data.findIndex((item) => keyExtractor(item, 0) === draggedKeyRef.current);
|
|
186
|
+
const to = placeholderIndexRef.current;
|
|
187
|
+
if (from === -1 || to == null)
|
|
188
|
+
return;
|
|
189
|
+
const newData = [...data];
|
|
190
|
+
const [item] = newData.splice(from, 1);
|
|
191
|
+
newData.splice(to, 0, item);
|
|
192
|
+
onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd({ from, to, data: newData });
|
|
193
|
+
draggedKeyRef.current = null;
|
|
194
|
+
currentIndexRef.current = null;
|
|
195
|
+
placeholderIndexRef.current = null;
|
|
196
|
+
setDragGhost(null);
|
|
197
|
+
setDraggedIndex(null);
|
|
198
|
+
setTempData(null);
|
|
199
|
+
lastReorderIndexRef.current = null;
|
|
200
|
+
itemRefs.current.forEach((el) => {
|
|
201
|
+
el.style.transform = "";
|
|
202
|
+
el.style.transition = "";
|
|
203
|
+
});
|
|
204
|
+
lastPointerRef.current = null;
|
|
205
|
+
onRelease === null || onRelease === void 0 ? void 0 : onRelease(from);
|
|
206
|
+
} }, props, { children: [workingData.map((item, index) => {
|
|
207
|
+
const key = getKey(item, index);
|
|
208
|
+
const isActive = key === draggedKeyRef.current;
|
|
209
|
+
return (_jsx(CellProvider, { isActive: isActive, children: _jsx("div", { ref: (el) => {
|
|
210
|
+
if (el) {
|
|
211
|
+
itemRefs.current.set(key, el);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
itemRefs.current.delete(key);
|
|
215
|
+
}
|
|
216
|
+
}, draggable: draggedIndex === null, onMouseDown: (e) => {
|
|
217
|
+
const el = itemRefs.current.get(key);
|
|
218
|
+
if (!el)
|
|
219
|
+
return;
|
|
220
|
+
const rect = el.getBoundingClientRect();
|
|
221
|
+
dragAnchorRef.current = {
|
|
222
|
+
offsetX: e.clientX - rect.left,
|
|
223
|
+
offsetY: e.clientY - rect.top,
|
|
224
|
+
};
|
|
225
|
+
}, onDragStart: (e) => {
|
|
226
|
+
handleDragStart(e, index);
|
|
227
|
+
}, onDragEnd: handleDragEnd, style: Object.assign({ cursor: draggedIndex === null ? "grab" : "grabbing", userSelect: "none", position: "relative" }, getItemStyle(key)), children: renderItem({
|
|
228
|
+
item,
|
|
229
|
+
getIndex: () => index,
|
|
230
|
+
drag: () => { },
|
|
231
|
+
isActive,
|
|
232
|
+
}) }) }, key));
|
|
233
|
+
}), dragGhost && (_jsx(CellProvider, { isActive: true, children: _jsx("div", { style: {
|
|
234
|
+
position: "absolute",
|
|
235
|
+
left: dragGhost.x - dragGhost.offsetX,
|
|
236
|
+
top: dragGhost.y - dragGhost.offsetY,
|
|
237
|
+
width: dragGhost.width,
|
|
238
|
+
height: dragGhost.height,
|
|
239
|
+
pointerEvents: "none",
|
|
240
|
+
zIndex: 9999,
|
|
241
|
+
}, children: renderItem({
|
|
242
|
+
item: dragGhost.item,
|
|
243
|
+
getIndex: () => dragGhost.index,
|
|
244
|
+
drag: () => { },
|
|
245
|
+
isActive: true,
|
|
246
|
+
}) }) }))] })) }));
|
|
247
|
+
}
|
|
248
|
+
export default DraggableFlatListWeb;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FlatList } from "react-native-gesture-handler";
|
|
3
|
+
import { DraggableFlatListProps } from "../constants/DraggableFlatList/types";
|
|
4
|
+
declare function NestableDraggableFlatListInner<T>(props: DraggableFlatListProps<T>, ref?: React.ForwardedRef<FlatList<T>>): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare const NestableDraggableFlatList: <T>(props: DraggableFlatListProps<T> & {
|
|
6
|
+
ref?: React.ForwardedRef<FlatList<T>>;
|
|
7
|
+
}) => ReturnType<typeof NestableDraggableFlatListInner>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=NestableDraggableFlatList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NestableDraggableFlatList.d.ts","sourceRoot":"","sources":["../../src/DraggableFlatList/NestableDraggableFlatList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAKxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAG3E,iBAAS,8BAA8B,CAAC,CAAC,EACvC,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAChC,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,2CAiFtC;AAED,eAAO,MAAM,yBAAyB,EAEjC,CAAC,CAAC,EACL,KAAK,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;CAAE,KACzE,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import React from "react";
|
|
12
|
+
import { findNodeHandle, LogBox } from "react-native";
|
|
13
|
+
import { useDerivedValue, useSharedValue } from "react-native-reanimated";
|
|
14
|
+
import { useStableCallback } from "../hooks/DraggableFlatList/useStableCallback";
|
|
15
|
+
import { useNestedAutoScroll } from "../hooks/DraggableFlatList/useNestedAutoScroll";
|
|
16
|
+
import { useSafeNestableScrollContainerContext } from "../context/DraggableFlatList/nestableScrollContainerContext";
|
|
17
|
+
import DraggableFlatList from "./DraggableFlatList";
|
|
18
|
+
function NestableDraggableFlatListInner(props, ref) {
|
|
19
|
+
const hasSuppressedWarnings = React.useRef(false);
|
|
20
|
+
if (!hasSuppressedWarnings.current) {
|
|
21
|
+
LogBox.ignoreLogs([
|
|
22
|
+
"VirtualizedLists should never be nested inside plain ScrollViews with the same orientation because it can break windowing",
|
|
23
|
+
]); // Ignore log notification by message
|
|
24
|
+
//@ts-ignore
|
|
25
|
+
console.reportErrorsAsExceptions = false;
|
|
26
|
+
hasSuppressedWarnings.current = true;
|
|
27
|
+
}
|
|
28
|
+
const { scrollableRef, outerScrollOffset, setOuterScrollEnabled } = useSafeNestableScrollContainerContext();
|
|
29
|
+
const listVerticalOffset = useSharedValue(0);
|
|
30
|
+
const [animVals, setAnimVals] = React.useState({});
|
|
31
|
+
const defaultHoverOffset = useSharedValue(0);
|
|
32
|
+
const [listHoverOffset, setListHoverOffset] = React.useState(defaultHoverOffset);
|
|
33
|
+
const hoverOffset = useDerivedValue(() => {
|
|
34
|
+
return listHoverOffset.value + listVerticalOffset.value;
|
|
35
|
+
}, [listHoverOffset]);
|
|
36
|
+
useNestedAutoScroll(Object.assign(Object.assign({}, animVals), { hoverOffset }));
|
|
37
|
+
const onListContainerLayout = useStableCallback((_a) => __awaiter(this, [_a], void 0, function* ({ containerRef }) {
|
|
38
|
+
const nodeHandle = findNodeHandle(scrollableRef.current);
|
|
39
|
+
const onSuccess = (_x, y) => {
|
|
40
|
+
listVerticalOffset.value = y;
|
|
41
|
+
};
|
|
42
|
+
const onFail = () => {
|
|
43
|
+
console.log("## nested draggable list measure fail");
|
|
44
|
+
};
|
|
45
|
+
//@ts-ignore
|
|
46
|
+
containerRef.current.measureLayout(nodeHandle, onSuccess, onFail);
|
|
47
|
+
}));
|
|
48
|
+
const onDragBegin = useStableCallback((params) => {
|
|
49
|
+
var _a;
|
|
50
|
+
setOuterScrollEnabled(false);
|
|
51
|
+
(_a = props.onDragBegin) === null || _a === void 0 ? void 0 : _a.call(props, params);
|
|
52
|
+
});
|
|
53
|
+
const onDragEnd = useStableCallback((params) => {
|
|
54
|
+
var _a;
|
|
55
|
+
setOuterScrollEnabled(true);
|
|
56
|
+
(_a = props.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(props, params);
|
|
57
|
+
});
|
|
58
|
+
const onAnimValInit = useStableCallback((params) => {
|
|
59
|
+
var _a;
|
|
60
|
+
setListHoverOffset(params.hoverOffset);
|
|
61
|
+
setAnimVals(Object.assign(Object.assign({}, params), { hoverOffset }));
|
|
62
|
+
(_a = props.onAnimValInit) === null || _a === void 0 ? void 0 : _a.call(props, params);
|
|
63
|
+
});
|
|
64
|
+
return (_jsx(DraggableFlatList, Object.assign({ ref: ref, onContainerLayout: onListContainerLayout, activationDistance: props.activationDistance || 20, scrollEnabled: false }, props, { outerScrollOffset: outerScrollOffset, onDragBegin: onDragBegin, onDragEnd: onDragEnd, onAnimValInit: onAnimValInit })));
|
|
65
|
+
}
|
|
66
|
+
export const NestableDraggableFlatList = React.forwardRef(NestableDraggableFlatListInner);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ScrollViewProps } from "react-native";
|
|
3
|
+
import { ScrollView } from "react-native-gesture-handler";
|
|
4
|
+
export declare const NestableScrollContainer: React.ForwardRefExoticComponent<ScrollViewProps & React.RefAttributes<ScrollView>>;
|
|
5
|
+
//# sourceMappingURL=NestableScrollContainer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NestableScrollContainer.d.ts","sourceRoot":"","sources":["../../src/DraggableFlatList/NestableScrollContainer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAqB,eAAe,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAmD1D,eAAO,MAAM,uBAAuB,oFAYnC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { ScrollView } from "react-native-gesture-handler";
|
|
4
|
+
import Animated, { useAnimatedScrollHandler } from "react-native-reanimated";
|
|
5
|
+
import { useStableCallback } from "../hooks/DraggableFlatList/useStableCallback";
|
|
6
|
+
import { NestableScrollContainerProvider, useSafeNestableScrollContainerContext, } from "../context/DraggableFlatList/nestableScrollContainerContext";
|
|
7
|
+
const AnimatedScrollView = Animated.createAnimatedComponent(ScrollView);
|
|
8
|
+
function NestableScrollContainerInner(props) {
|
|
9
|
+
const { outerScrollOffset, containerSize, scrollViewSize, scrollableRef, outerScrollEnabled, } = useSafeNestableScrollContainerContext();
|
|
10
|
+
const onScroll = useAnimatedScrollHandler({
|
|
11
|
+
onScroll: ({ contentOffset }) => {
|
|
12
|
+
outerScrollOffset.value = contentOffset.y;
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
const onLayout = useStableCallback((event) => {
|
|
16
|
+
const { nativeEvent: { layout }, } = event;
|
|
17
|
+
containerSize.value = layout.height;
|
|
18
|
+
});
|
|
19
|
+
const onContentSizeChange = useStableCallback((w, h) => {
|
|
20
|
+
var _a;
|
|
21
|
+
scrollViewSize.value = h;
|
|
22
|
+
(_a = props.onContentSizeChange) === null || _a === void 0 ? void 0 : _a.call(props, w, h);
|
|
23
|
+
});
|
|
24
|
+
return (_jsx(AnimatedScrollView, Object.assign({}, props, { onLayout: onLayout, onContentSizeChange: onContentSizeChange, scrollEnabled: outerScrollEnabled, ref: scrollableRef, scrollEventThrottle: 1, onScroll: onScroll })));
|
|
25
|
+
}
|
|
26
|
+
export const NestableScrollContainer = React.forwardRef((props, forwardedRef) => {
|
|
27
|
+
return (_jsx(NestableScrollContainerProvider, { forwardedRef: forwardedRef || undefined, children: _jsx(NestableScrollContainerInner, Object.assign({}, props)) }));
|
|
28
|
+
});
|