From 558675842a275fa4ae52b057f1929b9ea42644c7 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 7 Feb 2025 11:17:50 -0500 Subject: [PATCH] Remove unused ComposeUIConfig properties --- .../ComposeUI/Sources/ComposeUI/API/PostService.swift | 10 +++++----- .../ComposeUI/Sources/ComposeUI/ComposeUIConfig.swift | 7 ------- .../ComposeUI/Views/ComposeNavigationBarActions.swift | 3 ++- .../Sources/ComposeUI/Views/ComposeView.swift | 6 ++++-- .../Sources/ComposeUI/Views/NewMainTextView.swift | 2 +- ShareExtension/ShareHostingController.swift | 9 --------- Tusker/Screens/Compose/ComposeHostingController.swift | 10 ---------- 7 files changed, 12 insertions(+), 35 deletions(-) diff --git a/Packages/ComposeUI/Sources/ComposeUI/API/PostService.swift b/Packages/ComposeUI/Sources/ComposeUI/API/PostService.swift index cd88a91414..ae84c7c528 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/API/PostService.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/API/PostService.swift @@ -13,15 +13,15 @@ import UniformTypeIdentifiers @MainActor final class PostService: ObservableObject { private let mastodonController: any ComposeMastodonContext - private let config: ComposeUIConfig + private let contentType: StatusContentType private let draft: Draft @Published var currentStep = 1 @Published private(set) var totalSteps = 2 - init(mastodonController: any ComposeMastodonContext, config: ComposeUIConfig, draft: Draft) { + init(mastodonController: any ComposeMastodonContext, contentType: StatusContentType, draft: Draft) { self.mastodonController = mastodonController - self.config = config + self.contentType = contentType self.draft = draft } @@ -56,7 +56,7 @@ final class PostService: ObservableObject { request = Client.editStatus( id: editedStatusID, text: textForPosting(), - contentType: config.contentType, + contentType: contentType, spoilerText: contentWarning, sensitive: sensitive, language: mastodonController.instanceFeatures.createStatusWithLanguage ? draft.language : nil, @@ -87,7 +87,7 @@ final class PostService: ObservableObject { request = Client.createStatus( text: textForPosting(), - contentType: config.contentType, + contentType: contentType, inReplyTo: draft.inReplyToID, mediaIDs: uploadedAttachments, sensitive: sensitive, diff --git a/Packages/ComposeUI/Sources/ComposeUI/ComposeUIConfig.swift b/Packages/ComposeUI/Sources/ComposeUI/ComposeUIConfig.swift index ecf21d5c52..635e75ce09 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/ComposeUIConfig.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/ComposeUIConfig.swift @@ -25,13 +25,6 @@ public struct ComposeUIConfig { public var groupedCellBackgroundColor = Color(uiColor: .systemBackground) public var fillColor = Color(uiColor: .systemFill) - // TODO: remove these in favor of @PreferenceObserving - // Preferences - public var avatarStyle = AvatarImageView.Style.roundRect - public var useTwitterKeyboard = false - public var contentType = StatusContentType.plain - public var requireAttachmentDescriptions = false - // Host callbacks public var dismiss: @MainActor (DismissMode) -> Void = { _ in } public var presentAssetPicker: ((@MainActor @escaping ([PHPickerResult]) -> Void) -> Void)? diff --git a/Packages/ComposeUI/Sources/ComposeUI/Views/ComposeNavigationBarActions.swift b/Packages/ComposeUI/Sources/ComposeUI/Views/ComposeNavigationBarActions.swift index 3fe96d603a..591b1757b5 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Views/ComposeNavigationBarActions.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Views/ComposeNavigationBarActions.swift @@ -8,6 +8,7 @@ import SwiftUI import Combine import InstanceFeatures +import TuskerPreferences struct ComposeNavigationBarActions: ToolbarContent { @ObservedObject var draft: Draft @@ -100,7 +101,7 @@ private struct PostButton: View { let isPosting: Bool let postStatus: () async -> Void @EnvironmentObject private var instanceFeatures: InstanceFeatures - @Environment(\.composeUIConfig.requireAttachmentDescriptions) private var requireAttachmentDescriptions + @PreferenceObserving(\.$requireAttachmentDescriptions) private var requireAttachmentDescriptions var body: some View { Button { diff --git a/Packages/ComposeUI/Sources/ComposeUI/Views/ComposeView.swift b/Packages/ComposeUI/Sources/ComposeUI/Views/ComposeView.swift index 4209b77458..e4213931cf 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Views/ComposeView.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Views/ComposeView.swift @@ -9,6 +9,7 @@ import SwiftUI import CoreData import Pachyderm import TuskerComponents +import TuskerPreferences // State owned by the compose UI but that needs to be accessible from outside. public final class ComposeViewState: ObservableObject { @@ -87,7 +88,8 @@ private struct ComposeViewBody: View { @State private var isDismissing = false @State private var userConfirmedDelete = false @Environment(\.composeUIConfig) private var config - + @PreferenceObserving(\.$statusContentType) private var statusContentType + public var body: some View { navigation .environmentObject(mastodonController.instanceFeatures) @@ -215,7 +217,7 @@ private struct ComposeViewBody: View { return } - let poster = PostService(mastodonController: mastodonController, config: config, draft: draft) + let poster = PostService(mastodonController: mastodonController, contentType: statusContentType, draft: draft) state.poster = poster do { diff --git a/Packages/ComposeUI/Sources/ComposeUI/Views/NewMainTextView.swift b/Packages/ComposeUI/Sources/ComposeUI/Views/NewMainTextView.swift index 742479e627..9eb42ce7a4 100644 --- a/Packages/ComposeUI/Sources/ComposeUI/Views/NewMainTextView.swift +++ b/Packages/ComposeUI/Sources/ComposeUI/Views/NewMainTextView.swift @@ -37,7 +37,7 @@ private struct NewMainTextViewRepresentable: UIViewRepresentable { @Environment(\.isEnabled) private var isEnabled @Environment(\.colorScheme) private var colorScheme @Environment(\.composeUIConfig.fillColor) private var fillColor - @Environment(\.composeUIConfig.useTwitterKeyboard) private var useTwitterKeyboard + @PreferenceObserving(\.$useTwitterKeyboard) private var useTwitterKeyboard @Environment(\.composeUIConfig.textSelectionStartsAtBeginning) private var textSelectionStartsAtBeginning @PreferenceObserving(\.$statusContentType) private var statusContentType diff --git a/ShareExtension/ShareHostingController.swift b/ShareExtension/ShareHostingController.swift index 906b44c2f4..ffff7c1f27 100644 --- a/ShareExtension/ShareHostingController.swift +++ b/ShareExtension/ShareHostingController.swift @@ -58,15 +58,6 @@ class ShareHostingController: UIHostingController { config.groupedBackgroundColor = Color(uiColor: .appGroupedBackground) config.groupedCellBackgroundColor = Color(uiColor: .appGroupedCellBackground) config.fillColor = Color(uiColor: .appFill) - switch Preferences.shared.avatarStyle { - case .roundRect: - config.avatarStyle = .roundRect - case .circle: - config.avatarStyle = .circle - } - config.useTwitterKeyboard = Preferences.shared.useTwitterKeyboard - config.contentType = Preferences.shared.statusContentType - config.requireAttachmentDescriptions = Preferences.shared.requireAttachmentDescriptions config.dismiss = { [unowned self] in self.dismiss(mode: $0) } config.fetchAvatar = Self.fetchAvatar diff --git a/Tusker/Screens/Compose/ComposeHostingController.swift b/Tusker/Screens/Compose/ComposeHostingController.swift index 1841295beb..67bce479d6 100644 --- a/Tusker/Screens/Compose/ComposeHostingController.swift +++ b/Tusker/Screens/Compose/ComposeHostingController.swift @@ -81,16 +81,6 @@ class ComposeHostingController: UIHostingController