Skip to content

Commit a9addeb

Browse files
committed
use onLayout params
1 parent d2226c0 commit a9addeb

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/components/DraggableFlatList.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
FlatListProps,
1111
NativeScrollEvent,
1212
NativeSyntheticEvent,
13+
LayoutChangeEvent,
1314
} from "react-native";
1415
import {
1516
PanGestureHandler,
@@ -147,15 +148,10 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) {
147148

148149
const autoScrollNode = useAutoScroll();
149150

150-
const onContainerLayout = () => {
151-
const containerNode = isReanimatedV2
152-
? containerRef.current
153-
: containerRef.current?.getNode();
154-
155-
//@ts-ignore
156-
containerNode?.measure((_x, _y, w, h) => {
157-
containerSize.setValue(props.horizontal ? w : h);
158-
});
151+
const onContainerLayout = ({
152+
nativeEvent: { layout },
153+
}: LayoutChangeEvent) => {
154+
containerSize.setValue(props.horizontal ? layout.width : layout.height);
159155
};
160156

161157
const onListContentSizeChange = (w: number, h: number) => {
@@ -193,7 +189,8 @@ function DraggableFlatListInner<T>(props: DraggableFlatListProps<T>) {
193189
const renderItem: ListRenderItem<T> = useCallback(
194190
({ item, index }) => {
195191
const key = keyExtractor(item, index);
196-
if (index !== keyToIndexRef.current.get(key)) keyToIndexRef.current.set(key, index);
192+
if (index !== keyToIndexRef.current.get(key))
193+
keyToIndexRef.current.set(key, index);
197194

198195
return (
199196
<RowItem

0 commit comments

Comments
 (0)