diff --git a/Packages/ComposeUI/Sources/ComposeUI/API/PostService.swift b/Packages/ComposeUI/Sources/ComposeUI/API/PostService.swift index cd88a9141..ae84c7c52 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 ecf21d5c5..635e75ce0 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 3fe96d603..591b1757b 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 4209b7745..e4213931c 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 742479e62..9eb42ce7a 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 906b44c2f..ffff7c1f2 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 1841295be..67bce479d 100644 --- a/Tusker/Screens/Compose/ComposeHostingController.swift +++ b/Tusker/Screens/Compose/ComposeHostingController.swift @@ -81,16 +81,6 @@ class ComposeHostingController: UIHostingController