fix(mobile): preserve artist marquee and anchor navigation menu

This commit is contained in:
joshuafhiggins committed 2026-11-15 14:28:32 -05:00 Verified
1 parent 9046df1733
commit 60aa5da47f
5 files changed
+166 -22

No files matched your search

+10 -22
View File
@@ -44,6 +44,7 @@ import {
NowPlayingQueue,
QUEUE_HORIZONTAL_INSET,
} from "@/components/now-playing-queue"
import { PlayerArtistMenu } from "@/components/player-artist-menu"
import { PlayerSlider } from "@/components/player-slider"
import { PlayerSymbol } from "@/components/player-symbol"
import { useFavorites } from "@/contexts/favorites"
@@ -544,28 +545,15 @@ function SongMeta({
{ color: colors.foreground },
]}
/>
<MediaActionMenu
navigation={{
artist: { id: song.artist.id },
album: { id: song.album.id },
}}
includeActions={["go-album", "go-artist"]}
onAction={handleAction}
>
<Pressable
accessibilityRole="button"
accessibilityLabel={song.artist.name}
accessibilityHint="Opens album and artist options"
>
<MarqueeText
text={song.artist.name}
style={[
compact ? styles.compactArtist : styles.artist,
{ color: colors.secondaryForeground },
]}
/>
</Pressable>
</MediaActionMenu>
<PlayerArtistMenu song={song} compact={compact} onAction={handleAction}>
<MarqueeText
text={song.artist.name}
style={[
compact ? styles.compactArtist : styles.artist,
{ color: colors.secondaryForeground },
]}
/>
</PlayerArtistMenu>
</View>
<Pressable
onPress={() => void toggleSongFavorite(song.id)}
@@ -0,0 +1,79 @@
import { requireNativeView, requireOptionalNativeModule } from "expo"
import { useState, type ReactNode } from "react"
import { Platform, StyleSheet, View, type ViewProps } from "react-native"
import {
MediaActionMenu,
type MediaAction,
} from "@/components/media-context-menu"
import type { BrowseSong } from "@otunes/convex/types"
const NativeMenu =
Platform.OS === "ios" && requireOptionalNativeModule("PlayerNavigationMenu")
? requireNativeView<
ViewProps & {
artist: string
album: string
fontSize: number
onAction: (event: { nativeEvent: { action: MediaAction } }) => void
}
>("PlayerNavigationMenu")
: null
export function PlayerArtistMenu({
song,
compact,
onAction,
children,
}: {
song: BrowseSong
compact: boolean
onAction: (action: MediaAction) => void
children: ReactNode
}) {
const [size, setSize] = useState({ width: 0, height: 0 })
return (
<View
style={styles.container}
onLayout={({ nativeEvent: { layout } }) =>
setSize({ width: layout.width, height: layout.height })
}
>
<View
pointerEvents="none"
accessibilityElementsHidden
importantForAccessibility="no-hide-descendants"
>
{children}
</View>
{NativeMenu ? (
<NativeMenu
style={StyleSheet.absoluteFill}
artist={song.artist.name}
album={song.album.title}
fontSize={compact ? 15 : 20}
onAction={({ nativeEvent }) => onAction(nativeEvent.action)}
/>
) : size.width > 0 ? (
<MediaActionMenu
style={StyleSheet.absoluteFill}
includeActions={["go-album", "go-artist"]}
onAction={onAction}
>
<View
style={size}
accessible
accessibilityRole="button"
accessibilityLabel={song.artist.name}
accessibilityHint="Opens album and artist options"
/>
</MediaActionMenu>
) : null}
</View>
)
}
const styles = StyleSheet.create({
container: { overflow: "hidden" },
})
@@ -0,0 +1,4 @@
{
"platforms": ["apple"],
"apple": { "modules": ["PlayerNavigationMenuModule"] }
}
@@ -0,0 +1,17 @@
Pod::Spec.new do |s|
s.name = 'PlayerNavigationMenu'
s.version = '1.0.0'
s.summary = 'Native player navigation menu for oTunes'
s.description = s.summary
s.license = { :type => 'MIT' }
s.author = 'oTunes'
s.homepage = 'https://otunes.abunchofknowitalls.com'
s.platforms = { :ios => '16.4' }
s.swift_version = '5.9'
s.source = { :git => '' }
s.static_framework = true
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.dependency 'ExpoModulesCore'
s.frameworks = 'UIKit'
s.source_files = '**/*.swift'
end
@@ -0,0 +1,56 @@
import ExpoModulesCore
import UIKit
public class PlayerNavigationMenuModule: Module {
public func definition() -> ModuleDefinition {
Name("PlayerNavigationMenu")
View(PlayerNavigationMenuView.self) {
Events("onAction")
Prop("artist") { (view: PlayerNavigationMenuView, value: String) in
view.artist = value
}
Prop("album") { (view: PlayerNavigationMenuView, value: String) in
view.album = value
}
Prop("fontSize") { (view: PlayerNavigationMenuView, value: Double) in
view.fontSize = CGFloat(value)
}
}
}
}
final class PlayerNavigationMenuView: ExpoView {
let onAction = EventDispatcher()
var artist = "" { didSet { updateMenu(); setNeedsLayout() } }
var album = "" { didSet { updateMenu() } }
var fontSize: CGFloat = 20 { didSet { setNeedsLayout() } }
private let button = UIButton(type: .custom)
required init(appContext: AppContext? = nil) {
super.init(appContext: appContext)
button.showsMenuAsPrimaryAction = true
button.preferredMenuElementOrder = .fixed
button.accessibilityHint = "Opens album and artist options"
addSubview(button)
}
private func updateMenu() {
button.accessibilityLabel = artist
button.menu = UIMenu(children: [
UIAction(title: "Go to Album", subtitle: album, image: UIImage(systemName: "square.stack")) { [weak self] _ in
self?.onAction(["action": "go-album"])
},
UIAction(title: "Go to Artist", subtitle: artist, image: UIImage(systemName: "music.mic")) { [weak self] _ in
self?.onAction(["action": "go-artist"])
},
])
}
override func layoutSubviews() {
super.layoutSubviews()
// Anchor to the visible artist text, not the marquee's offscreen track.
let textWidth = (artist as NSString).size(withAttributes: [.font: UIFont.systemFont(ofSize: fontSize)]).width
button.frame = CGRect(x: 0, y: 0, width: min(ceil(textWidth), bounds.width), height: bounds.height)
}
}