Skip to content

Commit

Permalink
No selection code needed
Browse files Browse the repository at this point in the history
  • Loading branch information
tero-paananen committed Mar 7, 2022
1 parent fa9e1b5 commit 4d262ea
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,35 @@ const INITIAL_DATA = Array.from({length: 30}, (_, i) => {

const App = () => {
const [data, setData] = useState<MyItem[]>(INITIAL_DATA);
const [selected, setSelected] = useState<Item | undefined>(undefined);

const renderItem = useCallback(
({item, drag}: {item: MyItem; drag?: (id: string) => void}) => {
return <MyListItem item={item} drag={drag} />;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[selected],
);

const handleMove = useCallback(
(fromIndex: number, toIndex: number, items: Item[]) => {
setSelected(undefined);
setData(items);
},
[],
);

const MyListItem = React.memo(
({item, drag}: {item: MyItem; drag?: (id: string) => void}) => {
const backgroundColor =
item.id === selected?.id ? 'lightgray' : undefined;
const handleLongPress = useCallback(() => {
drag && drag(item.id);
}, [drag, item.id]);
return (
<TouchableOpacity
onLongPress={handleLongPress}
style={[styles.itemContainer, {backgroundColor}]}
style={styles.itemContainer}
key={item.id}>
<Text style={[styles.item, {height: item.height}]}>{item.title}</Text>
</TouchableOpacity>
);
},
);
const renderItem = useCallback(
({item, drag}: {item: MyItem; drag?: (id: string) => void}) => {
return <MyListItem item={item} drag={drag} />;
},
[],
);

return (
<View style={styles.container}>
Expand Down

0 comments on commit 4d262ea

Please sign in to comment.