From b9555cf7dd0c90081ddc95191cd6c9cb0b109512 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 4 Nov 2022 21:49:37 -0400 Subject: [PATCH] Dynamic type support in assorted places --- .../Compose/ComposeAttachmentRow.swift | 1 - .../Compose/ComposeAutocompleteView.swift | 17 ++++----- .../Compose/ComposeCurrentAccount.swift | 4 +-- .../Compose/ComposeEmojiTextField.swift | 5 +-- Tusker/Screens/Compose/ComposeReplyView.swift | 2 +- Tusker/Screens/Compose/ComposeTextView.swift | 12 ++----- .../Screens/Compose/MainComposeTextView.swift | 6 ++-- .../Large Image/LargeImageViewController.xib | 11 +++--- .../Account Cell/AccountTableViewCell.swift | 6 ++++ .../Account Cell/AccountTableViewCell.xib | 17 ++++++--- Tusker/Views/AccountDisplayNameLabel.swift | 12 ++++--- .../Views/Asset Picker/AlbumTableViewCell.xib | 9 ++--- .../Asset Picker/AllPhotosTableViewCell.xib | 9 ++--- .../ConfirmLoadMoreCollectionViewCell.swift | 2 ++ .../Views/Draft Cell/DraftTableViewCell.swift | 7 ++++ .../Views/Draft Cell/DraftTableViewCell.xib | 35 +++++++++++-------- 16 files changed, 93 insertions(+), 62 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeAttachmentRow.swift b/Tusker/Screens/Compose/ComposeAttachmentRow.swift index b02fd266..ee804578 100644 --- a/Tusker/Screens/Compose/ComposeAttachmentRow.swift +++ b/Tusker/Screens/Compose/ComposeAttachmentRow.swift @@ -49,7 +49,6 @@ struct ComposeAttachmentRow: View { ComposeTextView(text: $attachment.attachmentDescription, placeholder: Text("Describe for the visually impaired…"), minHeight: 80) .heightDidChange(self.heightChanged) .backgroundColor(.clear) - .fontSize(17) case .recognizingText: ProgressView() diff --git a/Tusker/Screens/Compose/ComposeAutocompleteView.swift b/Tusker/Screens/Compose/ComposeAutocompleteView.swift index b32b2a21..39265460 100644 --- a/Tusker/Screens/Compose/ComposeAutocompleteView.swift +++ b/Tusker/Screens/Compose/ComposeAutocompleteView.swift @@ -66,11 +66,11 @@ struct ComposeAutocompleteMentionsView: View { .cornerRadius(preferences.avatarStyle.cornerRadiusFraction * 30) VStack(alignment: .leading) { - AccountDisplayNameLabel(account: account.value, fontSize: 14) + AccountDisplayNameLabel(account: account.value, textStyle: .subheadline, emojiSize: 14) .foregroundColor(Color(UIColor.label)) Text(verbatim: "@\(account.value.acct)") - .font(.system(size: 12)) + .font(.caption) .foregroundColor(Color(UIColor.label)) } } @@ -174,6 +174,7 @@ struct ComposeAutocompleteEmojisView: View { @State var expanded = false @State private var emojis: [Emoji] = [] + @ScaledMetric private var emojiSize = 30 var body: some View { // When exapnded, the toggle button should be at the top. When collapsed, it should be centered. @@ -212,13 +213,13 @@ struct ComposeAutocompleteEmojisView: View { private var verticalGrid: some View { ScrollView { - LazyVGrid(columns: [GridItem(.adaptive(minimum: 30), spacing: 4)]) { + LazyVGrid(columns: [GridItem(.adaptive(minimum: emojiSize), spacing: 4)]) { ForEach(emojis, id: \.shortcode) { (emoji) in Button { uiState.currentInput?.autocomplete(with: ":\(emoji.shortcode):") } label: { CustomEmojiImageView(emoji: emoji) - .frame(height: 30) + .frame(height: emojiSize) } } } @@ -236,19 +237,19 @@ struct ComposeAutocompleteEmojisView: View { } label: { HStack(spacing: 4) { CustomEmojiImageView(emoji: emoji) - .frame(height: 30) + .frame(height: emojiSize) Text(verbatim: ":\(emoji.shortcode):") .foregroundColor(Color(UIColor.label)) } } - .frame(height: 30) + .frame(height: emojiSize) } .animation(.linear(duration: 0.2), value: emojis) - Spacer(minLength: 30) + Spacer(minLength: emojiSize) } .padding(.horizontal, 8) - .frame(height: 46) + .frame(height: emojiSize + 16) } } diff --git a/Tusker/Screens/Compose/ComposeCurrentAccount.swift b/Tusker/Screens/Compose/ComposeCurrentAccount.swift index 41e393d1..6bb471ff 100644 --- a/Tusker/Screens/Compose/ComposeCurrentAccount.swift +++ b/Tusker/Screens/Compose/ComposeCurrentAccount.swift @@ -27,11 +27,11 @@ struct ComposeCurrentAccount: View { if let id = account?.id, let account = mastodonController.persistentContainer.account(for: id) { VStack(alignment: .leading) { - AccountDisplayNameLabel(account: account, fontSize: 20) + AccountDisplayNameLabel(account: account, textStyle: .title2, emojiSize: 24) .lineLimit(1) Text(verbatim: "@\(account.acct)") - .font(.system(size: 17, weight: .light)) + .font(.body.weight(.light)) .foregroundColor(.secondary) .lineLimit(1) } diff --git a/Tusker/Screens/Compose/ComposeEmojiTextField.swift b/Tusker/Screens/Compose/ComposeEmojiTextField.swift index b3ac0ea1..d7e18398 100644 --- a/Tusker/Screens/Compose/ComposeEmojiTextField.swift +++ b/Tusker/Screens/Compose/ComposeEmojiTextField.swift @@ -46,12 +46,13 @@ struct ComposeEmojiTextField: UIViewRepresentable { view.placeholder = placeholder view.borderStyle = .roundedRect + view.font = .preferredFont(forTextStyle: .body) + view.adjustsFontForContentSizeCategory = true + view.backgroundColor = backgroundColor view.delegate = context.coordinator view.addTarget(context.coordinator, action: #selector(Coordinator.didChange(_:)), for: .editingChanged) - view.backgroundColor = backgroundColor - // otherwise when the text gets too wide it starts expanding the ComposeView view.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) diff --git a/Tusker/Screens/Compose/ComposeReplyView.swift b/Tusker/Screens/Compose/ComposeReplyView.swift index f7b1a441..000e8b29 100644 --- a/Tusker/Screens/Compose/ComposeReplyView.swift +++ b/Tusker/Screens/Compose/ComposeReplyView.swift @@ -26,7 +26,7 @@ struct ComposeReplyView: View { VStack(alignment: .leading, spacing: 0) { HStack { - AccountDisplayNameLabel(account: status.account, fontSize: 17) + AccountDisplayNameLabel(account: status.account, textStyle: .body, emojiSize: 17) .lineLimit(1) .layoutPriority(1) diff --git a/Tusker/Screens/Compose/ComposeTextView.swift b/Tusker/Screens/Compose/ComposeTextView.swift index 1d2d5f29..48d1a374 100644 --- a/Tusker/Screens/Compose/ComposeTextView.swift +++ b/Tusker/Screens/Compose/ComposeTextView.swift @@ -15,7 +15,6 @@ struct ComposeTextView: View { private var heightDidChange: ((CGFloat) -> Void)? private var backgroundColor = UIColor.secondarySystemBackground - private var fontSize: CGFloat = 20 @State private var height: CGFloat? @@ -31,7 +30,7 @@ struct ComposeTextView: View { if text.isEmpty, let placeholder = placeholder { placeholder - .font(.system(size: fontSize)) + .font(.body) .foregroundColor(.secondary) .offset(x: 4, y: 8) } @@ -39,7 +38,7 @@ struct ComposeTextView: View { WrappedTextView( text: $text, textDidChange: self.textDidChange, - font: .systemFont(ofSize: fontSize) + font: .preferredFont(forTextStyle: .body) ) .frame(height: height ?? minHeight) } @@ -61,12 +60,6 @@ struct ComposeTextView: View { copy.backgroundColor = color return copy } - - func fontSize(_ size: CGFloat) -> Self { - var copy = self - copy.fontSize = size - return copy - } } struct WrappedTextView: UIViewRepresentable { @@ -82,6 +75,7 @@ struct WrappedTextView: UIViewRepresentable { textView.isEditable = true textView.backgroundColor = .clear textView.font = font + textView.adjustsFontForContentSizeCategory = true textView.textContainer.lineBreakMode = .byWordWrapping return textView } diff --git a/Tusker/Screens/Compose/MainComposeTextView.swift b/Tusker/Screens/Compose/MainComposeTextView.swift index 2d1975dd..5302ebfc 100644 --- a/Tusker/Screens/Compose/MainComposeTextView.swift +++ b/Tusker/Screens/Compose/MainComposeTextView.swift @@ -33,6 +33,7 @@ struct MainComposeTextView: View { @State private var height: CGFloat? @State private var becomeFirstResponder: Bool = false @State private var hasFirstAppeared = false + @ScaledMetric private var fontSize = 20 var body: some View { ZStack(alignment: .topLeading) { @@ -40,7 +41,7 @@ struct MainComposeTextView: View { if draft.text.isEmpty { placeholder - .font(.system(size: 20)) + .font(.system(size: fontSize)) .foregroundColor(.secondary) .offset(x: 4, y: 8) } @@ -79,7 +80,8 @@ struct MainComposeWrappedTextView: UIViewRepresentable { textView.delegate = context.coordinator textView.isEditable = true textView.backgroundColor = .clear - textView.font = .systemFont(ofSize: 20) + textView.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 20)) + textView.adjustsFontForContentSizeCategory = true textView.textContainer.lineBreakMode = .byWordWrapping context.coordinator.textView = textView return textView diff --git a/Tusker/Screens/Large Image/LargeImageViewController.xib b/Tusker/Screens/Large Image/LargeImageViewController.xib index bd383434..7c1eb9e7 100644 --- a/Tusker/Screens/Large Image/LargeImageViewController.xib +++ b/Tusker/Screens/Large Image/LargeImageViewController.xib @@ -1,9 +1,9 @@ - + - + @@ -42,6 +42,7 @@ + @@ -54,7 +55,7 @@ - + @@ -75,9 +76,9 @@ -