Skip to content

Commit

Permalink
Add meta to edit item
Browse files Browse the repository at this point in the history
  • Loading branch information
dtun committed Aug 14, 2024
1 parent 0846d24 commit d174799
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion components/MyMenuEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DraggableFlatList, {
ShadowDecorator,
} from "react-native-draggable-flatlist";

import { getItemData } from "@/utils";
import { ItemSeparator } from "@/components/ItemSeparator";
import { MyMenuEditItem } from "@/components/MyMenuEditItem";

Expand Down Expand Up @@ -30,7 +31,7 @@ export function MyMenuEdit({
<ShadowDecorator>
<MyMenuEditItem
{...params}
menuData={menuData}
meta={getItemData(params.item.id, menuData)}
moveMenuItem={moveMenuItem}
toggleMenuItem={toggleMenuItem}
/>
Expand Down
8 changes: 3 additions & 5 deletions components/MyMenuEditItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { StyleSheet } from "react-native";

import { red } from "@/constants";
import { useEvent } from "@/hooks";
import { getItemData } from "@/utils";
import { Text, Icon, View, Pressable } from "@/components/Themed";

import type { AccessibilityActionEvent } from "react-native";
import type { RenderItemParams } from "react-native-draggable-flatlist";
import type { Direction, MenuItem, MenuData, Position } from "@/types";
import type { Direction, MenuItem, MenuItemMeta, Position } from "@/types";

let toggleAction = { name: "activate", label: "Toggle checked state" };
let upAction = { name: "up", label: "Move item up" };
Expand All @@ -18,15 +17,14 @@ let bottomAction = { name: "bottom", label: "Move item to bottom" };
export function MyMenuEditItem({
drag: onLongPress,
item: { icon, id, checked, title },
menuData,
meta: { isFirst, isLast },
moveMenuItem,
toggleMenuItem,
}: RenderItemParams<MenuItem> & {
menuData: MenuData;
meta: MenuItemMeta;
moveMenuItem: (id: string, direction: Direction | Position) => void;
toggleMenuItem: (id: string) => void;
}) {
let { isFirst, isLast } = getItemData(id, menuData);
let onAccessibilityAction = useOnAccessibilityAction({
id,
moveMenuItem,
Expand Down
4 changes: 4 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import { Ionicons } from "@expo/vector-icons";
import { SharedValue } from "react-native-reanimated";

import { getItemData } from "@/utils";

export type SharedNumber = SharedValue<number>;

export type IconName = keyof typeof Ionicons.glyphMap;
Expand All @@ -21,6 +23,8 @@ export type MenuItem = {

export type MenuData = MenuItem[];

export type MenuItemMeta = ReturnType<typeof getItemData>;

export type ThemeProps = {
lightColor?: string;
darkColor?: string;
Expand Down

0 comments on commit d174799

Please sign in to comment.