Skip to content

Commit

Permalink
Fixes an issue of the MonsterNavigationBarHeader.
Browse files Browse the repository at this point in the history
- Fix an issue that header content isn't updated when selection is changed.
- Fix an issue that another name is cut off on iPadOS 15.
  • Loading branch information
mntone committed Jan 12, 2024
1 parent ee737ea commit 3780aee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
45 changes: 24 additions & 21 deletions src/App/Views/Details/MonsterNavigationBarHeader.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import SwiftUI

#if os(iOS)

import SwiftUI

@available(macOS, unavailable)
@available(watchOS, unavailable)
struct MonsterNavigationBarHeader: View {
let viewModel: MonsterViewModel
let name: String
let anotherName: String

@Environment(\.verticalSizeClass)
private var verticalSizeClass
Expand All @@ -17,21 +18,24 @@ struct MonsterNavigationBarHeader: View {
private var adjustedSubheadline: CGFloat = 14

var body: some View {
if let name = viewModel.name {
if let anotherName = viewModel.anotherName,
verticalSizeClass != .compact {
VStack(spacing: 2) {
Text(name)
.font(.system(size: adjustedHeadline, weight: .semibold))

Text(anotherName)
.font(.system(size: adjustedSubheadline, weight: .regular))
.foregroundStyle(.secondary)
}
.accessibilityElement(children: .combine)
} else {
if verticalSizeClass != .compact {
let content = VStack(spacing: 2) {
Text(name)
.font(.headline)
.font(.system(size: adjustedHeadline, weight: .semibold))

Text(anotherName)
.font(.system(size: adjustedSubheadline, weight: .regular))
.foregroundStyle(.secondary)
}
.accessibilityElement(children: .combine)

if #available(iOS 16.0, *) {
content
} else if UIDevice.current.userInterfaceIdiom == .pad {
// Fix title are cut off on iPadOS 15.
content.frame(maxWidth: 240.0)
} else {
content
}
}
}
Expand All @@ -41,12 +45,11 @@ struct MonsterNavigationBarHeader: View {
@available(macOS, unavailable)
@available(watchOS, unavailable)
#Preview {
let viewModel = MonsterViewModel()
viewModel.set(id: "mockgame:gulu_qoo")
return NavigationStack {
NavigationStack {
EmptyView().toolbar {
ToolbarItem(placement: .principal) {
MonsterNavigationBarHeader(viewModel: viewModel)
MonsterNavigationBarHeader(name: "Powered Lime Gulu Qoo",
anotherName: "Loudest Piyopiyo")
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/App/Views/Details/MonsterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ struct MonsterView: View {
.headerProminence(.increased)
#if os(iOS)
.block { content in
if !isAccessibilitySize, settings?.showTitle ?? true {
if !isAccessibilitySize,
settings?.showTitle ?? true,
let name = viewModel.name,
let anotherName = viewModel.anotherName {
content.toolbar {
ToolbarItem(placement: .principal) {
MonsterNavigationBarHeader(viewModel: viewModel)
MonsterNavigationBarHeader(name: name, anotherName: anotherName)
.dynamicTypeSize(...DynamicTypeSize.xxLarge) // Fix iOS 15
}
}
Expand Down

0 comments on commit 3780aee

Please sign in to comment.