fix(mobile): use native context menus for media rows
- Replace per-row SwiftUI menus on iOS with UIKit context menus - Apply long-list rendering props to album tracks
This commit is contained in:
2 files changed
+72
-2
No files matched your search
@@ -24,6 +24,7 @@ import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseAlbumDetail, BrowseAlbumTrack } from "@otunes/convex/types"
|
||||
import { formatDuration, formatMetadata } from "@/lib/format"
|
||||
import { useAppNavigation } from "@/lib/app-navigation"
|
||||
import { longListProps } from "@/lib/list"
|
||||
import { albumDetailSongs, rememberSongs } from "@/lib/song-cache"
|
||||
import { albumCoverUrl } from "@/lib/urls"
|
||||
import { radius, spacing, useThemeColors } from "@/lib/theme"
|
||||
@@ -129,6 +130,7 @@ export default function AlbumScreen() {
|
||||
}}
|
||||
/>
|
||||
<FlatList
|
||||
{...longListProps}
|
||||
data={album.tracks}
|
||||
keyExtractor={(track) => track.id}
|
||||
style={{ flex: 1, backgroundColor }}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { MenuView, type MenuAction } from "@expo/ui/community/menu"
|
||||
import type { ReactNode } from "react"
|
||||
import type { StyleProp, ViewStyle } from "react-native"
|
||||
import { requireNativeView } from "expo"
|
||||
import type { ComponentType, ReactNode } from "react"
|
||||
import {
|
||||
Platform,
|
||||
type StyleProp,
|
||||
type ViewProps,
|
||||
type ViewStyle,
|
||||
} from "react-native"
|
||||
|
||||
import { useServerConfig } from "@/contexts/server-config"
|
||||
import type { MediaShareContext } from "@/lib/media-links"
|
||||
@@ -190,7 +196,69 @@ function MediaMenuBase({
|
||||
)
|
||||
}
|
||||
|
||||
// Long-press menus are mounted once per list row. `MenuView` hosts a SwiftUI
|
||||
// view tree per row, which makes opening long lists stall the main thread, so
|
||||
// on iOS rows use the UIKit context menu view that ships with expo-router.
|
||||
const NativeContextMenuView =
|
||||
Platform.OS === "ios"
|
||||
? requireNativeView<
|
||||
ViewProps & { disableForceFlatten?: boolean; children: ReactNode }
|
||||
>("ExpoRouterNativeLinkPreview", "NativeLinkPreviewView")
|
||||
: null
|
||||
|
||||
const NativeContextMenuAction: ComponentType<{
|
||||
identifier: string
|
||||
title: string
|
||||
icon?: string
|
||||
onSelected: () => void
|
||||
}> | null =
|
||||
Platform.OS === "ios"
|
||||
? requireNativeView(
|
||||
"ExpoRouterNativeLinkPreview",
|
||||
"LinkPreviewNativeActionView"
|
||||
)
|
||||
: null
|
||||
|
||||
function NativeMediaContextMenu({
|
||||
children,
|
||||
onAction,
|
||||
share,
|
||||
...actionConfig
|
||||
}: MediaMenuWrapperProps) {
|
||||
const { config } = useServerConfig()
|
||||
|
||||
if (!NativeContextMenuView || !NativeContextMenuAction) {
|
||||
return children
|
||||
}
|
||||
|
||||
const handleAction = (action: MediaAction) => {
|
||||
if (action === "share" && share && config) {
|
||||
void shareMediaLink(config.serverUrl, share)
|
||||
return
|
||||
}
|
||||
onAction(action)
|
||||
}
|
||||
|
||||
return (
|
||||
<NativeContextMenuView style={{ display: "contents" }} disableForceFlatten>
|
||||
{children}
|
||||
{buildMediaMenuActions({ ...actionConfig, share }).map((action) => (
|
||||
<NativeContextMenuAction
|
||||
key={action.id}
|
||||
identifier={action.id ?? action.title}
|
||||
title={action.title}
|
||||
icon={typeof action.image === "string" ? action.image : undefined}
|
||||
onSelected={() => handleAction(action.id as MediaAction)}
|
||||
/>
|
||||
))}
|
||||
</NativeContextMenuView>
|
||||
)
|
||||
}
|
||||
|
||||
export function MediaContextMenu(props: MediaMenuWrapperProps) {
|
||||
if (Platform.OS === "ios") {
|
||||
return <NativeMediaContextMenu {...props} />
|
||||
}
|
||||
return <MediaMenuBase {...props} shouldOpenOnLongPress />
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user