* 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>
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import React, { useCallback, useState } from "react";
|
|
import { Text, View, StyleSheet, TouchableOpacity } from "react-native";
|
|
import DraggableFlatList, {
|
|
ScaleDecorator,
|
|
ShadowDecorator,
|
|
OpacityDecorator,
|
|
RenderItemParams,
|
|
} from "react-native-draggable-flatlist";
|
|
|
|
import { mapIndexToData, Item } from "../utils";
|
|
|
|
const NUM_ITEMS = 100;
|
|
|
|
const initialData: Item[] = [...Array(NUM_ITEMS)].map(mapIndexToData);
|
|
|
|
export default function Basic() {
|
|
const [data, setData] = useState(initialData);
|
|
|
|
const renderItem = useCallback(
|
|
({ item, drag, isActive }: RenderItemParams<Item>) => {
|
|
return (
|
|
<ShadowDecorator>
|
|
<ScaleDecorator>
|
|
<OpacityDecorator>
|
|
<TouchableOpacity
|
|
activeOpacity={1}
|
|
onLongPress={drag}
|
|
disabled={isActive}
|
|
style={[
|
|
styles.rowItem,
|
|
{ backgroundColor: isActive ? "blue" : item.backgroundColor },
|
|
]}
|
|
>
|
|
<Text style={styles.text}>{item.text}</Text>
|
|
</TouchableOpacity>
|
|
</OpacityDecorator>
|
|
</ScaleDecorator>
|
|
</ShadowDecorator>
|
|
);
|
|
},
|
|
[]
|
|
);
|
|
|
|
return (
|
|
<DraggableFlatList
|
|
data={data}
|
|
onDragEnd={({ data }) => setData(data)}
|
|
keyExtractor={(item) => item.key}
|
|
renderItem={renderItem}
|
|
renderPlaceholder={() => (
|
|
<View style={{ flex: 1, backgroundColor: "tomato" }} />
|
|
)}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
rowItem: {
|
|
height: 100,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
},
|
|
text: {
|
|
color: "white",
|
|
fontSize: 24,
|
|
fontWeight: "bold",
|
|
textAlign: "center",
|
|
},
|
|
});
|