From 89d698d0450bbc9a964d71c20219384876b3ce6c Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:33:39 +0800 Subject: [PATCH] ui(plugins): use ContextMenu --- src/index.ts | 3 +- src/ui/components/ContextMenu.tsx | 17 +++++++++ src/ui/settings/components/AssetDisplay.tsx | 1 - src/ui/settings/components/Card.tsx | 42 ++++++++++----------- src/ui/settings/components/PluginCard.tsx | 19 +++++----- 5 files changed, 48 insertions(+), 34 deletions(-) create mode 100644 src/ui/components/ContextMenu.tsx diff --git a/src/index.ts b/src/index.ts index 23100bf..d32c177 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { patchLogHook } from "@lib/debug"; import { patchCommands } from "@lib/commands"; import { initPlugins } from "@lib/plugins"; -import { initThemes, patchChatBackground } from "@lib/themes"; +import { patchChatBackground } from "@lib/themes"; import { patchAssets } from "@ui/assets"; import initQuickInstall from "@ui/quickInstall"; import initSafeMode from "@ui/safeMode"; @@ -10,7 +10,6 @@ import initFixes from "@lib/fixes"; import logger from "@lib/logger"; import windowObject from "@lib/windowObject"; -initThemes() export default async () => { // Load everything in parallel const unloads = await Promise.all([ diff --git a/src/ui/components/ContextMenu.tsx b/src/ui/components/ContextMenu.tsx new file mode 100644 index 0000000..bb076b3 --- /dev/null +++ b/src/ui/components/ContextMenu.tsx @@ -0,0 +1,17 @@ +import { findByProps } from "@/lib/metro/filters"; + +const { ContextMenu } = findByProps("ContextMenu"); + +export default ContextMenu as (props: { + triggerOnLongPress: boolean; + items: Array<{ + label: string, + iconSource: number, + action: () => unknown, + [key: string]: any; + }>; + align: "left" | "right" | "above" | "below" | "auto" | null; + title: string; + children: React.FC; + [key: string]: any; +}) => JSX.Element; \ No newline at end of file diff --git a/src/ui/settings/components/AssetDisplay.tsx b/src/ui/settings/components/AssetDisplay.tsx index 3786f12..3b85e82 100644 --- a/src/ui/settings/components/AssetDisplay.tsx +++ b/src/ui/settings/components/AssetDisplay.tsx @@ -1,7 +1,6 @@ import { Asset } from "@types"; import { ReactNative as RN, clipboard } from "@metro/common"; import { showToast } from "@ui/toasts"; -import { getAssetIDByName } from "@ui/assets"; import { Forms } from "@ui/components"; interface AssetDisplayProps { asset: Asset } diff --git a/src/ui/settings/components/Card.tsx b/src/ui/settings/components/Card.tsx index b650d1a..aefe642 100644 --- a/src/ui/settings/components/Card.tsx +++ b/src/ui/settings/components/Card.tsx @@ -1,9 +1,10 @@ +import ContextMenu from "@/ui/components/ContextMenu"; import { ReactNative as RN, stylesheet } from "@metro/common"; import { findByProps } from "@metro/filters"; import { getAssetIDByName } from "@ui/assets"; import { semanticColors } from "@ui/color"; -const { TableRow, TableRowIcon, TableSwitchRow, TableCheckboxRow, TableRowGroup } = findByProps("TableRow"); +const { TableRow, TableRowIcon, TableSwitchRow, TableCheckboxRow, TableRowGroup, IconButton } = findByProps("TableRow"); const { hideActionSheet } = findByProps("openLazy", "hideActionSheet"); const { showSimpleActionSheet } = findByProps("showSimpleActionSheet"); @@ -53,6 +54,7 @@ interface CardProps { toggleValue?: boolean; onToggleChange?: (v: boolean) => void; descriptionLabel?: string | React.ComponentType; + /** @deprecated use overflowActions */ actions?: Action[]; overflowTitle?: string; overflowActions?: OverflowAction[]; @@ -87,26 +89,24 @@ export default function Card(props: CardProps) { label={props.descriptionLabel} trailing={ - {props.overflowActions && showSimpleActionSheet({ - key: "CardOverflow", - header: { - title: props.overflowTitle, - icon: props.headerIcon && , - onClose: () => hideActionSheet(), - }, - options: props.overflowActions?.map(i => ({ ...i, icon: getAssetIDByName(i.icon) })), - })} - > - - } - {props.actions?.map(({ icon, onPress }) => ( - - - - ))} + {props.overflowActions && + ({ + label: i.label, + iconSource: getAssetIDByName(i.icon), + action: i.onPress + }))} + align="below" + title={props.overflowTitle!!} + children={(props) => } + /> + } } /> diff --git a/src/ui/settings/components/PluginCard.tsx b/src/ui/settings/components/PluginCard.tsx index e142b89..be43cce 100644 --- a/src/ui/settings/components/PluginCard.tsx +++ b/src/ui/settings/components/PluginCard.tsx @@ -42,6 +42,14 @@ export default function PluginCard({ item: plugin, index }: CardWrapper) descriptionLabel={plugin.manifest.description} overflowTitle={plugin.manifest.name} overflowActions={[ + ...(settings ? [{ + label: "Plugin settings", + icon: "settings", + onPress: () => navigation.push("VendettaCustomPage", { + title: plugin.manifest.name, + render: settings, + }) + }] : []), { icon: "ic_sync_24px", label: "Refetch", @@ -112,16 +120,7 @@ export default function PluginCard({ item: plugin, index }: CardWrapper) } } }), - }, - ]} - actions={[ - ...(settings ? [{ - icon: "settings", - onPress: () => navigation.push("VendettaCustomPage", { - title: plugin.manifest.name, - render: settings, - }) - }] : []), + } ]} /> )