* 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>
120 lines
2.9 KiB
TypeScript
120 lines
2.9 KiB
TypeScript
import React, { useState, useCallback } from "react";
|
|
import { Text, View, StyleSheet, TouchableOpacity } from "react-native";
|
|
|
|
import {
|
|
RenderItemParams,
|
|
ScaleDecorator,
|
|
ShadowDecorator,
|
|
NestableScrollContainer,
|
|
NestableDraggableFlatList,
|
|
} from "react-native-draggable-flatlist";
|
|
|
|
import { mapIndexToData, Item } from "../utils";
|
|
|
|
const NUM_ITEMS = 6;
|
|
const initialData1 = [...Array(NUM_ITEMS)].fill(0).map(mapIndexToData);
|
|
const initialData2 = [...Array(NUM_ITEMS)].fill(0).map(mapIndexToData);
|
|
const initialData3 = [...Array(NUM_ITEMS)].fill(0).map(mapIndexToData);
|
|
|
|
function NestedDraggableListScreen() {
|
|
const [data1, setData1] = useState(initialData1);
|
|
const [data2, setData2] = useState(initialData2);
|
|
const [data3, setData3] = useState(initialData3);
|
|
|
|
const renderItem = useCallback((params: RenderItemParams<Item>) => {
|
|
return (
|
|
<ShadowDecorator>
|
|
<ScaleDecorator activeScale={1.25}>
|
|
<RowItem {...params} />
|
|
</ScaleDecorator>
|
|
</ShadowDecorator>
|
|
);
|
|
}, []);
|
|
|
|
const keyExtractor = (item) => item.key;
|
|
|
|
return (
|
|
<View style={styles.container}>
|
|
<NestableScrollContainer>
|
|
<Header text="List 1" />
|
|
<NestableDraggableFlatList
|
|
data={data1}
|
|
renderItem={renderItem}
|
|
keyExtractor={keyExtractor}
|
|
onDragEnd={({ data }) => setData1(data)}
|
|
/>
|
|
<Header text="List 2" />
|
|
<NestableDraggableFlatList
|
|
data={data2}
|
|
renderItem={renderItem}
|
|
keyExtractor={keyExtractor}
|
|
onDragEnd={({ data }) => setData2(data)}
|
|
/>
|
|
<Header text="List 3" />
|
|
<NestableDraggableFlatList
|
|
data={data3}
|
|
renderItem={renderItem}
|
|
keyExtractor={keyExtractor}
|
|
onDragEnd={({ data }) => setData3(data)}
|
|
/>
|
|
</NestableScrollContainer>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
function Header({ text }: { text: string }) {
|
|
return (
|
|
<View style={{ padding: 10, backgroundColor: "seashell" }}>
|
|
<Text style={{ fontSize: 24, fontWeight: "bold", color: "gray" }}>
|
|
{text}
|
|
</Text>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
type RowItemProps = {
|
|
item: Item;
|
|
drag: () => void;
|
|
};
|
|
|
|
function RowItem({ item, drag }: RowItemProps) {
|
|
return (
|
|
<TouchableOpacity
|
|
activeOpacity={1}
|
|
onLongPress={drag}
|
|
style={[
|
|
styles.row,
|
|
{
|
|
backgroundColor: item.backgroundColor,
|
|
width: item.width,
|
|
height: item.height,
|
|
},
|
|
]}
|
|
>
|
|
<Text style={styles.text}>{item.text}</Text>
|
|
</TouchableOpacity>
|
|
);
|
|
}
|
|
|
|
export default NestedDraggableListScreen;
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: "seashell",
|
|
paddingTop: 44,
|
|
},
|
|
row: {
|
|
flexDirection: "row",
|
|
flex: 1,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
padding: 15,
|
|
},
|
|
text: {
|
|
fontWeight: "bold",
|
|
color: "white",
|
|
fontSize: 32,
|
|
},
|
|
});
|