feat(mobile): include media names in share previews
This commit is contained in:
11 files changed
+39
-17
No files matched your search
@@ -38,7 +38,7 @@ in memory through setup and sign-in, and is opened after authentication.
|
||||
The browser may ask before opening the app. If the app is absent, the web page
|
||||
remains available. Native changes still require a new mobile build.
|
||||
|
||||
Native sharing supplies artwork through iOS link metadata and Android's chooser
|
||||
Native sharing supplies media titles and artwork through iOS link metadata and Android's chooser
|
||||
thumbnail, while sharing the original HTTPS URL. Receiving apps control whether
|
||||
they display previews. If artwork cannot load, the URL is still shared. Existing
|
||||
builds without the native sharing module fall back to URL-only sharing.
|
||||
@@ -186,7 +186,7 @@ export default function AlbumScreen() {
|
||||
stationArtistId={album.artist.id}
|
||||
selectedCount={album.tracks.length}
|
||||
favorited={isAlbumFav(album.id)}
|
||||
share={{ type: "album", albumId: album.id }}
|
||||
share={{ type: "album", albumId: album.id, title: album.title }}
|
||||
onAction={(action) =>
|
||||
void handleAlbumDetailAction(
|
||||
album.id as Id<"albums">,
|
||||
@@ -406,6 +406,7 @@ const AlbumTrackRow = memo(function AlbumTrackRow({
|
||||
type: "song",
|
||||
albumId: album.id,
|
||||
songId: track.id,
|
||||
title: `${track.title} - ${album.title}`,
|
||||
}}
|
||||
onAction={(action) => void onAction(track, album, action)}
|
||||
>
|
||||
|
||||
@@ -75,7 +75,11 @@ export default function ArtistScreen() {
|
||||
<MediaActionMenu
|
||||
selectedCount={data.albums.length}
|
||||
favorited={isArtistFav(data.artist.id)}
|
||||
share={{ type: "artist", artistId: data.artist.id }}
|
||||
share={{
|
||||
type: "artist",
|
||||
artistId: data.artist.id,
|
||||
title: data.artist.name,
|
||||
}}
|
||||
onAction={(action) =>
|
||||
void handleArtistAction(data.artist, action)
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ const ArtistRow = memo(function ArtistRow({
|
||||
return (
|
||||
<MediaContextMenu
|
||||
favorited={favorited}
|
||||
share={{ type: "artist", artistId: artist.id }}
|
||||
share={{ type: "artist", artistId: artist.id, title: artist.name }}
|
||||
onAction={(action) => void onAction(artist, action)}
|
||||
>
|
||||
<Pressable
|
||||
|
||||
@@ -254,6 +254,7 @@ function PlaylistContent({
|
||||
share={{
|
||||
type: "playlist",
|
||||
playlistId: playlistId ?? "favorites",
|
||||
title: playlist?.title ?? "oTunes",
|
||||
}}
|
||||
includeActions={canEdit ? OWNER_MENU_ACTIONS : undefined}
|
||||
onAction={handlePlaylistMenuAction}
|
||||
@@ -276,6 +277,7 @@ function PlaylistContent({
|
||||
palette.background,
|
||||
palette.isDark,
|
||||
playlistId,
|
||||
playlist?.title,
|
||||
router,
|
||||
songIds,
|
||||
])
|
||||
|
||||
@@ -80,7 +80,7 @@ export const AlbumCard = memo(function AlbumCard({
|
||||
favorited={isAlbumFavorite(album.id)}
|
||||
stationArtistId={album.artist.id}
|
||||
navigation={{ artist: { id: album.artist.id } }}
|
||||
share={{ type: "album", albumId: album.id }}
|
||||
share={{ type: "album", albumId: album.id, title: album.title }}
|
||||
onAction={(action) => void handleAlbumAction(album, action)}
|
||||
>
|
||||
<MusicEntityView kind="album" id={album.id}>
|
||||
@@ -125,7 +125,7 @@ export const ArtistCard = memo(function ArtistCard({
|
||||
return (
|
||||
<MediaContextMenu
|
||||
favorited={isArtistFavorite(artist.id)}
|
||||
share={{ type: "artist", artistId: artist.id }}
|
||||
share={{ type: "artist", artistId: artist.id, title: artist.name }}
|
||||
onAction={(action) => void handleArtistAction(artist, action)}
|
||||
>
|
||||
<MusicEntityView kind="artist" id={artist.id}>
|
||||
@@ -176,7 +176,11 @@ export const PlaylistCard = memo(function PlaylistCard({
|
||||
return (
|
||||
<MediaContextMenu
|
||||
showFavorite={false}
|
||||
share={{ type: "playlist", playlistId: playlist.id }}
|
||||
share={{
|
||||
type: "playlist",
|
||||
playlistId: playlist.id,
|
||||
title: playlist.title,
|
||||
}}
|
||||
onAction={(action) => void handlePlaylistAction(playlist, action)}
|
||||
>
|
||||
<MusicEntityView kind="playlist" id={playlist.id}>
|
||||
|
||||
@@ -147,6 +147,7 @@ export const SongListRow = memo(function SongListRow({
|
||||
type: "song",
|
||||
albumId: song.album.id,
|
||||
songId: song.id,
|
||||
title: `${song.title} - ${song.album.title}`,
|
||||
},
|
||||
onAction: (action) => onAction(song, action),
|
||||
}}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
export type MediaShareContext =
|
||||
export type MediaShareContext = (
|
||||
| { type: "album"; albumId: string }
|
||||
| { type: "song"; albumId: string; songId: string }
|
||||
| { type: "playlist"; playlistId: string; isFavorites?: boolean }
|
||||
| { type: "artist"; artistId: string }
|
||||
) & { title: string }
|
||||
|
||||
export function shouldShowShare(
|
||||
share: MediaShareContext | undefined,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { mediaShareUrl } from "@/lib/media-links"
|
||||
import { showError } from "@/lib/toast"
|
||||
|
||||
const nativeShare = requireOptionalNativeModule<{
|
||||
share: (url: string, artwork: string) => Promise<void>
|
||||
share: (url: string, artwork: string, title: string) => Promise<void>
|
||||
}>("MediaLinkShare")
|
||||
|
||||
export async function shareMediaLink(
|
||||
@@ -22,7 +22,7 @@ export async function shareMediaLink(
|
||||
showError("Sharing is not available on this device")
|
||||
return
|
||||
}
|
||||
await Sharing.shareAsync(url, { dialogTitle: "Share" })
|
||||
await Sharing.shareAsync(url, { dialogTitle: share.title })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -38,12 +38,17 @@ export async function shareMediaLink(
|
||||
: share.playlistId
|
||||
await nativeShare.share(
|
||||
url,
|
||||
`${serverUrl.replace(/\/+$/, "")}/api/${type}/${id}/cover?size=512`
|
||||
`${serverUrl.replace(/\/+$/, "")}/api/${type}/${id}/cover?size=512`,
|
||||
share.title
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
await Share.share(Platform.OS === "ios" ? { url } : { message: url })
|
||||
await Share.share(
|
||||
Platform.OS === "ios"
|
||||
? { url, title: share.title }
|
||||
: { message: url, title: share.title }
|
||||
)
|
||||
} catch (error) {
|
||||
if (error instanceof Error && /cancel/i.test(error.message)) {
|
||||
return
|
||||
|
||||
@@ -11,12 +11,13 @@ import java.net.URL
|
||||
class MediaLinkShare : Module() {
|
||||
override fun definition() = ModuleDefinition {
|
||||
Name("MediaLinkShare")
|
||||
AsyncFunction("share") { link: String, artwork: String ->
|
||||
AsyncFunction("share") { link: String, artwork: String, title: String ->
|
||||
val context = requireNotNull(appContext.reactContext)
|
||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||
type = "text/plain"
|
||||
putExtra(Intent.EXTRA_TEXT, link)
|
||||
putExtra(Intent.EXTRA_TITLE, "oTunes")
|
||||
putExtra(Intent.EXTRA_TITLE, title)
|
||||
putExtra(Intent.EXTRA_SUBJECT, title)
|
||||
}
|
||||
// ClipData supplies the chooser thumbnail while the shared item stays a URL.
|
||||
try {
|
||||
|
||||
@@ -5,9 +5,11 @@ internal import ExpoModulesCore
|
||||
private final class MediaLinkItem: NSObject, UIActivityItemSource {
|
||||
let url: URL
|
||||
let image: UIImage?
|
||||
init(url: URL, image: UIImage?) {
|
||||
let title: String
|
||||
init(url: URL, image: UIImage?, title: String) {
|
||||
self.url = url
|
||||
self.image = image
|
||||
self.title = title
|
||||
}
|
||||
func activityViewControllerPlaceholderItem(_ controller: UIActivityViewController) -> Any { url }
|
||||
func activityViewController(_ controller: UIActivityViewController, itemForActivityType: UIActivity.ActivityType?) -> Any? { url }
|
||||
@@ -15,6 +17,7 @@ private final class MediaLinkItem: NSObject, UIActivityItemSource {
|
||||
let metadata = LPLinkMetadata()
|
||||
metadata.originalURL = url
|
||||
metadata.url = url
|
||||
metadata.title = title
|
||||
if let image {
|
||||
metadata.imageProvider = NSItemProvider(object: image)
|
||||
metadata.iconProvider = NSItemProvider(object: image)
|
||||
@@ -26,7 +29,7 @@ private final class MediaLinkItem: NSObject, UIActivityItemSource {
|
||||
final class MediaLinkShare: Module {
|
||||
public func definition() -> ExpoModulesCore.ModuleDefinition {
|
||||
Name("MediaLinkShare")
|
||||
AsyncFunction("share") { (link: String, artwork: String) in
|
||||
AsyncFunction("share") { (link: String, artwork: String, title: String) in
|
||||
guard let url = URL(string: link), let artworkURL = URL(string: artwork) else { return }
|
||||
var image: UIImage?
|
||||
var request = URLRequest(url: artworkURL)
|
||||
@@ -39,7 +42,7 @@ final class MediaLinkShare: Module {
|
||||
await MainActor.run {
|
||||
guard let presenter = self.appContext?.utilities?.currentViewController() else { return }
|
||||
let controller = UIActivityViewController(
|
||||
activityItems: [MediaLinkItem(url: url, image: artworkImage)], applicationActivities: nil)
|
||||
activityItems: [MediaLinkItem(url: url, image: artworkImage, title: title)], applicationActivities: nil)
|
||||
if let popover = controller.popoverPresentationController {
|
||||
popover.sourceView = presenter.view
|
||||
popover.sourceRect = CGRect(x: presenter.view.bounds.midX, y: presenter.view.bounds.midY, width: 0, height: 0)
|
||||
|
||||
Reference in new issue
Block a user