Skip to content

Commit b780c49

Browse files
authored
fix: glitching when reordering items (#586)
* fix: glitching when reordering items * fix: don't change animation style as that causes glitches
1 parent debd2ca commit b780c49

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/components/CellRendererComponent.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
LayoutChangeEvent,
55
MeasureLayoutOnSuccessCallback,
66
StyleProp,
7-
StyleSheet,
87
ViewStyle,
98
} from "react-native";
109
import Animated, {
@@ -163,11 +162,7 @@ function CellRendererComponent<T>(props: Props<T>) {
163162
? itemLayoutAnimation
164163
: undefined
165164
}
166-
style={[
167-
props.style,
168-
baseStyle,
169-
activeKey ? animStyle : styles.zeroTranslate,
170-
]}
165+
style={[props.style, baseStyle, animStyle]}
171166
pointerEvents={activeKey ? "none" : "auto"}
172167
>
173168
<CellProvider isActive={isActive}>{children}</CellProvider>
@@ -177,12 +172,6 @@ function CellRendererComponent<T>(props: Props<T>) {
177172

178173
export default typedMemo(CellRendererComponent);
179174

180-
const styles = StyleSheet.create({
181-
zeroTranslate: {
182-
transform: [{ translateX: 0 }, { translateY: 0 }],
183-
},
184-
});
185-
186175
declare global {
187176
namespace NodeJS {
188177
interface Global {

src/components/DraggableFlatList.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import React, {
66
useRef,
77
useState,
88
} from "react";
9-
import { ListRenderItem, FlatListProps, LayoutChangeEvent } from "react-native";
9+
import {
10+
ListRenderItem,
11+
FlatListProps,
12+
LayoutChangeEvent,
13+
InteractionManager,
14+
} from "react-native";
1015
import {
1116
FlatList,
1217
Gesture,
@@ -20,7 +25,7 @@ import Animated, {
2025
withSpring,
2126
} from "react-native-reanimated";
2227
import CellRendererComponent from "./CellRendererComponent";
23-
import { DEFAULT_PROPS, isWeb } from "../constants";
28+
import { DEFAULT_PROPS } from "../constants";
2429
import PlaceholderItem from "./PlaceholderItem";
2530
import RowItem from "./RowItem";
2631
import { DraggableFlatListProps } from "../types";
@@ -114,6 +119,9 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) {
114119
if (dataHasChanged) {
115120
// When data changes make sure `activeKey` is nulled out in the same render pass
116121
activeKey = null;
122+
InteractionManager.runAfterInteractions(() => {
123+
reset();
124+
});
117125
}
118126

119127
useEffect(() => {
@@ -221,7 +229,8 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) {
221229
}
222230

223231
onDragEnd?.({ from, to, data: newData });
224-
reset();
232+
233+
setActiveKey(null);
225234
}
226235
);
227236

0 commit comments

Comments
 (0)