* first pass v2 migration * autoscroll (WIP * update decorators, cleanup * ts ignore * tweak constrained hover anim * use single useDerivedValue * fixed layout measurement (#325) Co-authored-by: Tatiana Iasencova <t.iasencova@unifun.com> * back to working * fix autoscroll * fix placeholder item * bugfix placeholder * add identityRetainingCallback * enforce reanimated v2 * fix onDragEnd * cleanup * fix filcker (mostly) * flip raf and setTimeout * fix placeholder position * fix filicker, nestable checkpoint * fix nested scroll * remove unnecessary wrapper * fix placeholderitem * cleanup, fix tests * remove fail case * add bob * 4.0.0-beta.0 * memoize, useAnimatedRef -> useRef * memoize, index -> getIndex * memoize * performance, cleanup * update README * fix ref types * 4.0.0-beta.1 * disable gestures when animating * bump reanimated * 4.0.0-beta.2 * fix commonjs build * 4.0.0-beta.3 * prevent flicker on web * use v2 gesture api * no worklet * useIdentityRetainingCallback -> useStableCallback * 4.0.0-beta.4 * foward refs * add example * add npmignore * 4.0.0-beta.5 * fix autoscroll not working after scroll down Co-authored-by: computerjazz <hi@danielmerrill.com> Co-authored-by: taniaI <47004999+taniaIas@users.noreply.github.com> Co-authored-by: Tatiana Iasencova <t.iasencova@unifun.com>
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
import React, { useState } from "react";
|
|
import { Text, View } from "react-native";
|
|
import { fireEvent, render } from "@testing-library/react-native";
|
|
import DraggableFlatList from "../src/index";
|
|
|
|
jest.mock("react-native-reanimated", () =>
|
|
require("react-native-reanimated/mock")
|
|
);
|
|
|
|
|
|
const DummyFlatList = (props) => {
|
|
const [data] = useState([
|
|
{ id: "1", name: "item 1" },
|
|
{ id: "2", name: "item 2" }
|
|
]);
|
|
|
|
return (
|
|
<DraggableFlatList
|
|
keyExtractor={item => item.id}
|
|
renderItem={({ item, drag }) => (
|
|
<View onLongPress={drag}>
|
|
<Text>{item.name}</Text>
|
|
</View>
|
|
)}
|
|
testID="draggable-flat-list"
|
|
data={data}
|
|
{...props}
|
|
/>
|
|
);
|
|
};
|
|
|
|
describe("DraggableFlatList", () => {
|
|
|
|
const setup = propOverrides => {
|
|
const defaultProps = {
|
|
...propOverrides
|
|
};
|
|
|
|
return render(<DummyFlatList {...defaultProps} />);
|
|
};
|
|
|
|
it("calls onDragBegin with the index of the element when the drag starts", () => {
|
|
const mockOnDragBegin = jest.fn();
|
|
const { getByText } = setup({ onDragBegin: mockOnDragBegin });
|
|
|
|
fireEvent(getByText("item 1"), "longPress");
|
|
|
|
expect(mockOnDragBegin).toHaveBeenCalledWith(0);
|
|
});
|
|
|
|
it("renders a placeholder when renderPlaceholder is defined", () => {
|
|
const renderPlaceholder = () => <View testID="some-placeholder" />;
|
|
const { getByText, getByTestId } = setup({
|
|
renderPlaceholder: renderPlaceholder
|
|
});
|
|
|
|
fireEvent(getByText("item 1"), "longPress");
|
|
|
|
expect(getByTestId("some-placeholder")).toBeDefined();
|
|
});
|
|
});
|