From 3780aee46a2a1469f6fa39c1c641a6ad065ca89a Mon Sep 17 00:00:00 2001 From: mntone <901816+mntone@users.noreply.github.com> Date: Fri, 12 Jan 2024 17:18:51 +0900 Subject: [PATCH] Fixes an issue of the MonsterNavigationBarHeader. - 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. --- .../Details/MonsterNavigationBarHeader.swift | 45 ++++++++++--------- src/App/Views/Details/MonsterView.swift | 7 ++- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/App/Views/Details/MonsterNavigationBarHeader.swift b/src/App/Views/Details/MonsterNavigationBarHeader.swift index dc8684c..b661fd5 100644 --- a/src/App/Views/Details/MonsterNavigationBarHeader.swift +++ b/src/App/Views/Details/MonsterNavigationBarHeader.swift @@ -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 @@ -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 } } } @@ -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") } } } diff --git a/src/App/Views/Details/MonsterView.swift b/src/App/Views/Details/MonsterView.swift index be0d68b..79ab5d7 100644 --- a/src/App/Views/Details/MonsterView.swift +++ b/src/App/Views/Details/MonsterView.swift @@ -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 } }