react-native-drag-sort-list 1.0.2 → 1.0.4

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.
@@ -1,13 +1,11 @@
1
1
  /**
2
2
  * @file DragItemContainer.js
3
- * @description
3
+ * @description
4
4
  * @author liushun
5
- * @created 2025/12/24 14:28
6
- * @lastModified 2025/12/24 14:28
5
+ * @created 2025/12/20 13:22
6
+ * @lastModified 2025/12/20 13:22
7
7
  */
8
8
 
9
-
10
-
11
9
  import React, {useRef} from "react";
12
10
  import { Animated, Dimensions, Easing, StyleSheet, View } from 'react-native'
13
11
  import { Gesture, GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler'
@@ -21,7 +19,6 @@ const DragItemContainer = (props) => {
21
19
  const itemScaleAnime = useRef(new Animated.Value(1)).current;
22
20
 
23
21
  const isDragging = useRef(false);
24
-
25
22
  //长按手势处理
26
23
  const longPress = Gesture.LongPress().onStart((e)=>{
27
24
  itemScaleAnime.setValue(1.1)
@@ -36,10 +33,12 @@ const DragItemContainer = (props) => {
36
33
  onDragMove?.(e);
37
34
  }
38
35
  }).onTouchesUp((e)=>{ //停止拖拽
39
- isDragging.current = false;
40
- itemScaleAnime.setValue(1)
41
- setZIndex(0);
42
- onDragEnd?.(e);
36
+ if(isDragging.current){
37
+ isDragging.current = false;
38
+ itemScaleAnime.setValue(1)
39
+ setZIndex(0);
40
+ onDragEnd?.(e);
41
+ }
43
42
  }).activateAfterLongPress(505).enabled(true);
44
43
 
45
44
  //手势合并
@@ -16,8 +16,8 @@ import _ from "lodash";
16
16
  const TOP = 200; //上边距
17
17
  const BOTTOM = Dimensions.get('screen').height - 200; //下边距
18
18
 
19
- const TIME = Platform.OS === 'ios'?10:25; //每次滚动的时间间隔
20
- const DISTANCE = Platform.OS === 'ios'?2:4; //每次滚动的距离
19
+ const TIME = Platform.OS === 'ios'?10:10; //每次滚动的时间间隔
20
+ const DISTANCE = Platform.OS === 'ios'?5:5; //每次滚动的距离
21
21
 
22
22
  const MemoDragSortableView = (props, ref) => {
23
23
 
@@ -54,6 +54,8 @@ const MemoDragSortableView = (props, ref) => {
54
54
 
55
55
  const lastScrollYRef = useRef(0);
56
56
 
57
+ const needScrollYRef = useRef(0);
58
+
57
59
  //先构造拖拽所需数据, 由于改变位置是动画,所以不 setState 就可以改变位置
58
60
  useEffect(()=>{
59
61
 
@@ -101,7 +103,14 @@ const MemoDragSortableView = (props, ref) => {
101
103
  const startScroll = (distance) => {
102
104
  if(!scrollTimeRef.current){
103
105
  clearScrollInterval();
106
+ needScrollYRef.current = scrollYRef.current;
104
107
  scrollTimeRef.current = setInterval(() => {
108
+ console.log(needScrollYRef.current);
109
+ console.log("distance")
110
+ console.log(scrollYRef.current)
111
+ if(needScrollYRef.current - scrollYRef.current > 1){
112
+ return;
113
+ }
105
114
  //判断是否应该滚动,还是停止滚动
106
115
  if(Math.floor(scrollYRef?.current) <= Math.ceil(yRef.current + (parentYRef?parentYRef?.current:0)) && distance < 0){
107
116
  stopScroll();
@@ -113,8 +122,9 @@ const MemoDragSortableView = (props, ref) => {
113
122
  return;
114
123
  }
115
124
 
125
+ needScrollYRef.current = scrollYRef.current + distance;
116
126
  scrollViewRef?.current.scrollTo({
117
- y: scrollYRef?.current + distance,
127
+ y: needScrollYRef?.current,
118
128
  animated: false,
119
129
  })
120
130
  setDragOffSet(scrollYRef?.current - lastScrollYRef.current);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-drag-sort-list",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A powerful React Native drag and sort component library with support for single and multi-column layouts",
5
5
  "main": "index.js",
6
6
  "scripts": {