Skip to content

Commit

Permalink
ui(plugins): use ContextMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Feb 9, 2024
1 parent 8d2e17d commit 89d698d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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([
Expand Down
17 changes: 17 additions & 0 deletions src/ui/components/ContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -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;
1 change: 0 additions & 1 deletion src/ui/settings/components/AssetDisplay.tsx
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
42 changes: 21 additions & 21 deletions src/ui/settings/components/Card.tsx
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -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[];
Expand Down Expand Up @@ -87,26 +89,24 @@ export default function Card(props: CardProps) {
label={props.descriptionLabel}
trailing={
<RN.View style={styles.actions}>
{props.overflowActions && <RN.TouchableOpacity
onPress={() => showSimpleActionSheet({
key: "CardOverflow",
header: {
title: props.overflowTitle,
icon: props.headerIcon && <TableRowIcon style={{ marginRight: 8 }} source={getAssetIDByName(props.headerIcon)} />,
onClose: () => hideActionSheet(),
},
options: props.overflowActions?.map(i => ({ ...i, icon: getAssetIDByName(i.icon) })),
})}
>
<RN.Image style={styles.actionIcon} source={getAssetIDByName("ic_more_24px")} />
</RN.TouchableOpacity>}
{props.actions?.map(({ icon, onPress }) => (
<RN.TouchableOpacity
onPress={onPress}
>
<RN.Image style={styles.actionIcon} source={getAssetIDByName(icon)} />
</RN.TouchableOpacity>
))}
{props.overflowActions &&
<ContextMenu
triggerOnLongPress={false}
items={props.overflowActions.map(i => ({
label: i.label,
iconSource: getAssetIDByName(i.icon),
action: i.onPress
}))}
align="below"
title={props.overflowTitle!!}
children={(props) => <IconButton
{...props}
size="sm"
variant="secondary"
icon={getAssetIDByName("ic_settings_white_24px")}
/>}
/>
}
</RN.View>
}
/>
Expand Down
19 changes: 9 additions & 10 deletions src/ui/settings/components/PluginCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export default function PluginCard({ item: plugin, index }: CardWrapper<Plugin>)
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",
Expand Down Expand Up @@ -112,16 +120,7 @@ export default function PluginCard({ item: plugin, index }: CardWrapper<Plugin>)
}
}
}),
},
]}
actions={[
...(settings ? [{
icon: "settings",
onPress: () => navigation.push("VendettaCustomPage", {
title: plugin.manifest.name,
render: settings,
})
}] : []),
}
]}
/>
)
Expand Down

0 comments on commit 89d698d

Please sign in to comment.