Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Primuse/Views/Components/AlbumCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ struct AlbumCardView: View {
var showsSongCount = false
var isIntelligentRecommendation = false
var subtitle: String? = nil
var usesCoverZoomSource = false

var body: some View {
VStack(alignment: .leading, spacing: 6) {
AlbumArtworkView(album: album, cornerRadius: 10)
.aspectRatio(1, contentMode: .fit)
.searchRecommendationOverlay(isRecommended: isIntelligentRecommendation)
#if os(macOS)
.macFluentCoverSource(id: album.id)
#endif
.if(usesCoverZoomSource) {
$0.mediaZoomSource(.album, id: album.id, shape: .roundedRect(10))
}

VStack(alignment: .leading, spacing: 2) {
Text(album.title)
Expand Down
1 change: 1 addition & 0 deletions Primuse/Views/Components/CollectionCoverWallHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct CollectionCoverWallHeader<Fallback: View>: View {
.mask {
LinearGradient(stops: maskStops, startPoint: .top, endPoint: .bottom)
}
.if(topInset > 0) { $0.pmHeroOverscrollStretch() }
.accessibilityHidden(true)

titleBlock
Expand Down
55 changes: 46 additions & 9 deletions Primuse/Views/Components/PMMotion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ enum PMMotion: Sendable {
case entrance
/// 红心点亮时向外散开的那圈光点:从心形飞出、减速、淡掉。
case burst
/// Fluent 钻入详情页:封面沿弧线放大飞入、正文轻度上浮到位。
case drillIn
/// Fluent 退回总览页:正文先让位、封面逆向缩回原格位,节奏较钻入略干脆。
case drillOut

var animation: Animation {
switch self {
Expand All @@ -57,7 +61,7 @@ enum PMMotion: Sendable {
case .pageSwitch: return .easeOut(duration: 0.18)
case .contentAppear: return .easeOut(duration: 0.2)
case .list: return .snappy(duration: 0.22)
case .panel: return .easeInOut(duration: 0.25)
case .panel: return .spring(duration: 0.28, bounce: 0)
case .selection: return .spring(response: 0.3, dampingFraction: 0.86)
case .trackChange: return .easeInOut(duration: 0.28)
case .ambient: return .easeInOut(duration: 0.5)
Expand All @@ -67,6 +71,8 @@ enum PMMotion: Sendable {
case .trackSwapGentle: return .spring(response: 0.7, dampingFraction: 0.92)
case .entrance: return .spring(response: 0.5, dampingFraction: 0.86)
case .burst: return .easeOut(duration: 0.62)
case .drillIn: return .timingCurve(0.10, 0.90, 0.20, 1.0, duration: FluentDrillTransitionPolicy.enterDuration)
case .drillOut: return .timingCurve(0.16, 0.88, 0.26, 1.0, duration: FluentDrillTransitionPolicy.exitDuration)
}
}

Expand All @@ -77,7 +83,7 @@ enum PMMotion: Sendable {
case .control, .pageSwitch: return 0.18
case .contentAppear: return 0.2
case .list: return 0.22
case .panel: return 0.25
case .panel: return 0.3
case .selection: return 0.3
case .trackChange: return 0.28
case .ambient: return 0.5
Expand All @@ -87,14 +93,16 @@ enum PMMotion: Sendable {
case .trackSwapGentle: return 0.75
case .entrance: return 0.55
case .burst: return 0.62
case .drillIn: return FluentDrillTransitionPolicy.enterDuration + 0.05
case .drillOut: return FluentDrillTransitionPolicy.exitDuration + 0.04
}
}

/// 这一档会不会让界面上的东西挪位置。只改透明度的档位不算。
var involvesMovement: Bool {
switch self {
case .press, .list, .panel, .selection,
.pop, .toast, .trackSwap, .trackSwapGentle, .entrance, .burst:
.pop, .toast, .trackSwap, .trackSwapGentle, .entrance, .burst, .drillIn, .drillOut:
return true
case .hover, .control, .pageSwitch, .contentAppear, .trackChange, .ambient:
return false
Expand Down Expand Up @@ -457,18 +465,19 @@ private struct PMPageEnterModifier: ViewModifier {
content
.environment(\.pmPageEntering, entering)
.opacity(visible ? 1 : 0)
.offset(y: risen ? 0 : 8)
.offset(y: (risen || reduceMotion) ? 0 : 10)
.onAppear {
withAnimation(PMMotion.pageSwitch.animation) { visible = true }
if let rise = PMMotion.list.resolved(reduceMotion: reduceMotion) {
withAnimation(rise) { risen = true }
} else {
let anim: Animation = reduceMotion
? .easeOut(duration: 0.16)
: .timingCurve(0.12, 0.90, 0.24, 1.0, duration: 0.22)
withAnimation(anim) {
visible = true
risen = true
}
}
.task {
// 入场的时长之后, 再出现的内容各自淡入。
try? await Task.sleep(for: .milliseconds(260))
try? await Task.sleep(for: .milliseconds(240))
entering = false
}
}
Expand Down Expand Up @@ -773,3 +782,31 @@ extension View {
}
}
#endif

#if os(iOS)
extension View {
/// 详情页顶部全铺封面在下拉过卷时随阻力弹性拉伸,顶边贴齐屏顶不露缝(120Hz 纯图层变换)。
func pmHeroOverscrollStretch() -> some View {
modifier(PMHeroOverscrollStretchModifier())
}
}

private struct PMHeroOverscrollStretchModifier: ViewModifier {
@Environment(\.accessibilityReduceMotion) private var reduceMotion

func body(content: Content) -> some View {
let reduceMotion = reduceMotion
content.visualEffect { view, proxy in
let minY = proxy.frame(in: .scrollView(axis: .vertical)).minY
let frame = FluentDrillTransitionPolicy.heroOverscrollFrame(
pullOffset: Double(minY),
heroHeight: Double(proxy.size.height),
reduceMotion: reduceMotion
)
return view
.scaleEffect(frame.scale, anchor: .top)
.offset(y: frame.offsetY)
}
}
}
#endif
2 changes: 1 addition & 1 deletion Primuse/Views/Components/SongRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ private extension View {

/// 正在播那一行的波形。单独一个视图:播放、暂停只重画这一个图标;只有正在播的那一行会建它,
/// 别的行不观察播放状态。播放时律动,暂停时停在完整的静止波形。
private struct SongRowPlayingWaveform: View {
struct SongRowPlayingWaveform: View {
@Environment(AudioPlayerService.self) private var player
let tint: Color

Expand Down
42 changes: 33 additions & 9 deletions Primuse/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,19 +395,29 @@ extension EnvironmentValues {

// MARK: - 详情页 zoom 展开

/// 列表卡片与详情页之间的转场标识。专辑 / 艺术家 / 歌单共用一层导航栈的
/// 命名空间,靠 kind 区分,免得不同类型撞上同一个 ID 时互相匹配。
/// 列表卡片与详情页之间的转场标识。专辑 / 艺术家 / 歌单 / 流派 / 智能歌单 / 有声书共用一层
/// 导航栈的命名空间,靠 kind 区分,免得不同类型撞上同一个 ID 时互相匹配。
struct MediaZoomTransitionID: Hashable {
enum Kind: String {
case album
case artist
case playlist
case genre
case smartPlaylist
case spokenWordBook
}

let kind: Kind
let id: String
}

/// 列表页缩放转场源的裁剪形状:纯封面或圆形头像直接按自身形状飞出与缩回,避免拉扯标题文字。
enum MediaZoomSourceShape: Equatable {
case automatic
case roundedRect(CGFloat)
case circle
}

/// 用可选值:绝大多数视图不在这套转场里,取不到命名空间时两个修饰符都原样
/// 返回内容,页面照常 push,只是没有放大动画。
private struct MediaZoomNamespaceEnvironmentKey: EnvironmentKey {
Expand All @@ -423,17 +433,26 @@ extension EnvironmentValues {

private struct MediaZoomSourceModifier: ViewModifier {
let transitionID: MediaZoomTransitionID
let shape: MediaZoomSourceShape
@Environment(\.mediaZoomNamespace) private var namespace
@Environment(\.accessibilityReduceMotion) private var reduceMotion

@ViewBuilder
func body(content: Content) -> some View {
#if os(iOS)
if let namespace, !reduceMotion {
// 不自定义裁剪形状:卡片是"封面 + 标题"的组合,拿一个矩形去裁本来
// 就对不上,而圆形头像想要的超大圆角会让 continuous 圆角路径退化,
// 整张卡片被裁成空白。交给系统按视图自身形状取转场源。
content.matchedTransitionSource(id: transitionID, in: namespace)
switch shape {
case .automatic:
content.matchedTransitionSource(id: transitionID, in: namespace)
case .roundedRect(let radius):
content.matchedTransitionSource(id: transitionID, in: namespace) { source in
source.clipShape(RoundedRectangle(cornerRadius: radius, style: .continuous))
}
case .circle:
content.matchedTransitionSource(id: transitionID, in: namespace) { source in
source.clipShape(RoundedRectangle(cornerRadius: 999, style: .circular))
}
}
} else {
content
}
Expand Down Expand Up @@ -468,11 +487,16 @@ extension View {
environment(\.mediaZoomNamespace, namespace)
}

/// 挂在列表卡片上:详情页从这张卡片放大出来,返回时缩回原位。
func mediaZoomSource(_ kind: MediaZoomTransitionID.Kind, id: String) -> some View {
/// 挂在列表卡片或封面容器上:详情页从源形状放大出来,返回时缩回原位。
func mediaZoomSource(
_ kind: MediaZoomTransitionID.Kind,
id: String,
shape: MediaZoomSourceShape = .automatic
) -> some View {
modifier(
MediaZoomSourceModifier(
transitionID: MediaZoomTransitionID(kind: kind, id: id)
transitionID: MediaZoomTransitionID(kind: kind, id: id),
shape: shape
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion Primuse/Views/Home/HomeForYouSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ struct MacHomeForYouSection: View {
)
return HStack(spacing: 12) {
MacHomeDetailLink(album: album) {
AlbumArtworkView(album: album, size: 78, cornerRadius: PMRadius.m)
AlbumArtworkView(album: album, size: 78, cornerRadius: PMRadius.m).macFluentCoverSource(id: album.id)
}
.pmScrollingHelp(Text("go_to_album"))

Expand Down
3 changes: 1 addition & 2 deletions Primuse/Views/Home/HomeHeroRecommendations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,8 @@ struct HomeHeroRecommendationDetail: View {
if content == .albums, !model.albums.isEmpty {
LazyVGrid(columns: [GridItem(.adaptive(minimum: 145), spacing: 16)], spacing: 20) {
ForEach(model.albums) { album in
NavigationLink(value: album) { AlbumCardView(album: album, showsSongCount: true) }
NavigationLink(value: album) { AlbumCardView(album: album, showsSongCount: true, usesCoverZoomSource: true) }
.buttonStyle(.plain)
.mediaZoomSource(.album, id: album.id)
.accessibilityIdentifier("home.hero.recommendation.albumDetail.\(album.id)")
}
}
Expand Down
10 changes: 4 additions & 6 deletions Primuse/Views/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ private struct RecentlyAddedAlbumsView: View {
// 走首页导航栈上的 Album 目的地,和资料库的专辑网格一样从卡片放大展开。
ForEach(filteredAlbums) { album in
NavigationLink(value: album) {
AlbumCardView(album: album, showsSongCount: true)
AlbumCardView(album: album, showsSongCount: true, usesCoverZoomSource: true)
}
.buttonStyle(.pmPressable)
.mediaZoomSource(.album, id: album.id)
.contextMenu { Toggle("home_show_preview_albums", isOn: $showsExternalAlbums) }
}
}
Expand Down Expand Up @@ -2197,6 +2196,7 @@ struct HomeView: View {
}
.navigationDestination(for: SmartPlaylist.self) {
SmartPlaylistDetailView(smartPlaylistID: $0.id)
.mediaZoomDestination(.smartPlaylist, id: $0.id)
}
.navigationDestination(for: HomeLibraryPage.self) { page in
switch page {
Expand Down Expand Up @@ -5555,11 +5555,10 @@ struct HomeView: View {
LazyHGrid(rows: carouselRows(.recentlyAdded, height: Self.coverCardHeight(width: cardWidth), itemCount: shownAlbums.count), spacing: 14) {
ForEach(shownAlbums) { tile in
NavigationLink(value: HomeLibraryPage.recentAlbum(tile.id)) {
AlbumCardView(album: tile.album, showsSongCount: true)
AlbumCardView(album: tile.album, showsSongCount: true, usesCoverZoomSource: true)
.frame(width: cardWidth)
}
.buttonStyle(.pmPressable)
.mediaZoomSource(.album, id: tile.album.id)
.contextMenu { Toggle("home_show_preview_albums", isOn: $showsExternalAlbums) }
}
}
Expand Down Expand Up @@ -5587,10 +5586,9 @@ struct HomeView: View {
LazyVGrid(columns: recentlyAddedGridColumns, spacing: 20) {
ForEach(albums.prefix(sectionItemCount(.recentlyAdded, usesPadMetrics ? 12 : 6))) { tile in
NavigationLink(value: HomeLibraryPage.recentAlbum(tile.id)) {
AlbumCardView(album: tile.album, showsSongCount: true)
AlbumCardView(album: tile.album, showsSongCount: true, usesCoverZoomSource: true)
}
.buttonStyle(.pmPressable)
.mediaZoomSource(.album, id: tile.album.id)
.contextMenu { Toggle("home_show_preview_albums", isOn: $showsExternalAlbums) }
}
}
Expand Down
8 changes: 4 additions & 4 deletions Primuse/Views/Library/AlbumDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ struct AlbumDetailView: View {
.allowsHitTesting(false)
.accessibilityHidden(true)
}
.pmHeroOverscrollStretch()

VStack(spacing: 18) {
heroIdentityText(centered: true)
Expand Down Expand Up @@ -1021,7 +1022,7 @@ struct AlbumDetailView: View {
}
}
.padding(.horizontal, PMSpace.xxxl)
.padding(.top, PMSpace.l)
.padding(.top, PMSpace.l).macFluentContinuumContent()
}
.padding(.bottom, 112)
}
Expand Down Expand Up @@ -1425,9 +1426,7 @@ struct AlbumDetailView: View {
HStack(spacing: PMSpace.s10) {
ZStack {
if isCurrent {
Image(systemName: "play.fill")
.font(.system(size: 11, weight: .semibold))
.foregroundStyle(PMColor.brand)
SongRowPlayingWaveform(tint: PMColor.brand)
.pmFadeTransition()
} else if showsRowNumbers {
Text(verbatim: trackNumber.formatted(.number.locale(locale)))
Expand Down Expand Up @@ -1594,6 +1593,7 @@ private struct AlbumHeroActionRow: View {
PMHaptics.likeToggled(isLiked: !favorite.isLiked)
favorite.toggle()
}
.pmLikeBurst(isLiked: favorite.isLiked, tint: .red)
.accessibilityAddTraits(favorite.isLiked ? .isSelected : [])
.accessibilityIdentifier("libraryDetail.favorite")
}
Expand Down
Loading
Loading