From 3e3c69c41c9fbfe0a0c0a72f3a362eb820f8d4d7 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Wed, 1 Nov 2023 18:58:44 +0100 Subject: [PATCH] format --- IceCubesApp/App/AppRegistry.swift | 2 +- IceCubesApp/App/Main/IceCubesApp+Menu.swift | 2 +- IceCubesApp/App/Main/IceCubesApp+Scene.swift | 11 ++--- .../App/Main/IceCubesApp+Sidebar.swift | 3 +- IceCubesApp/App/Main/IceCubesApp+Tabbar.swift | 5 +- IceCubesApp/App/Main/IceCubesApp.swift | 4 +- IceCubesApp/App/SideBarView.swift | 2 +- .../App/Tabs/Settings/SettingsTab.swift | 2 +- .../Account/AccountDetailContextMenu.swift | 2 +- .../Account/AccountDetailHeaderView.swift | 2 +- .../Detail/ConversationMessageView.swift | 14 +++--- .../Sources/DesignSystem/SceneDelegate.swift | 10 ++-- .../Views/LazyResizableImage.swift | 46 +++++++++---------- .../Views/StatusEditorToolbarItem.swift | 5 +- Packages/Env/Sources/Env/QuickLook.swift | 6 +-- .../Env/Sources/Env/UserPreferences.swift | 32 ++++++------- .../MediaUI/MediaUIAttachmentImageView.swift | 6 +-- .../MediaUI/MediaUIAttachmentVideoView.swift | 4 +- .../MediaUI/MediaUITransferableImage.swift | 6 +-- .../MediaUI/Sources/MediaUI/MediaUIView.swift | 30 ++++++------ .../MediaUI/MediaUIZoomableContainer.swift | 46 +++++++++---------- .../Sources/Models/MediaAttachement.swift | 16 +++---- .../Sources/Models/SwiftData/Draft.swift | 2 +- .../Models/SwiftData/LocalTimeline.swift | 2 +- .../Sources/Models/SwiftData/TagGroup.swift | 2 +- Packages/Network/Sources/Network/Client.swift | 7 +-- .../Status/Editor/StatusEditorView.swift | 4 +- .../Sources/Status/Row/StatusRowView.swift | 2 +- .../Subviews/StatusRowMediaPreviewView.swift | 4 +- .../Sources/Timeline/TimelineView.swift | 10 ++-- 30 files changed, 142 insertions(+), 147 deletions(-) diff --git a/IceCubesApp/App/AppRegistry.swift b/IceCubesApp/App/AppRegistry.swift index b0178ad8..f5eb7a83 100644 --- a/IceCubesApp/App/AppRegistry.swift +++ b/IceCubesApp/App/AppRegistry.swift @@ -6,11 +6,11 @@ import Env import Explore import LinkPresentation import Lists +import MediaUI import Models import Status import SwiftUI import Timeline -import MediaUI @MainActor extension View { diff --git a/IceCubesApp/App/Main/IceCubesApp+Menu.swift b/IceCubesApp/App/Main/IceCubesApp+Menu.swift index 7f311af5..522bcfee 100644 --- a/IceCubesApp/App/Main/IceCubesApp+Menu.swift +++ b/IceCubesApp/App/Main/IceCubesApp+Menu.swift @@ -1,5 +1,5 @@ -import SwiftUI import Env +import SwiftUI extension IceCubesApp { @CommandsBuilder diff --git a/IceCubesApp/App/Main/IceCubesApp+Scene.swift b/IceCubesApp/App/Main/IceCubesApp+Scene.swift index 383fcf60..2f065257 100644 --- a/IceCubesApp/App/Main/IceCubesApp+Scene.swift +++ b/IceCubesApp/App/Main/IceCubesApp+Scene.swift @@ -1,7 +1,7 @@ -import SwiftUI import Env -import Status import MediaUI +import Status +import SwiftUI extension IceCubesApp { var appScene: some Scene { @@ -26,9 +26,9 @@ extension IceCubesApp { .sheet(item: $quickLook.selectedMediaAttachment) { selectedMediaAttachment in MediaUIView(selectedAttachment: selectedMediaAttachment, attachments: quickLook.mediaAttachments) - .presentationBackground(.ultraThinMaterial) - .presentationCornerRadius(16) - .withEnvironments() + .presentationBackground(.ultraThinMaterial) + .presentationCornerRadius(16) + .withEnvironments() } .onChange(of: pushNotificationsService.handledNotification) { _, newValue in if newValue != nil { @@ -72,7 +72,6 @@ extension IceCubesApp { } } - var otherScenes: some Scene { WindowGroup(for: WindowDestination.self) { destination in Group { diff --git a/IceCubesApp/App/Main/IceCubesApp+Sidebar.swift b/IceCubesApp/App/Main/IceCubesApp+Sidebar.swift index 4da9cf4b..f5d460bd 100644 --- a/IceCubesApp/App/Main/IceCubesApp+Sidebar.swift +++ b/IceCubesApp/App/Main/IceCubesApp+Sidebar.swift @@ -1,5 +1,5 @@ -import SwiftUI import Env +import SwiftUI extension IceCubesApp { var sidebarView: some View { @@ -46,5 +46,4 @@ extension IceCubesApp { .frame(maxWidth: .secondaryColumnWidth) .id(appAccountsManager.currentAccount.id) } - } diff --git a/IceCubesApp/App/Main/IceCubesApp+Tabbar.swift b/IceCubesApp/App/Main/IceCubesApp+Tabbar.swift index 5b396fb7..6fde66f8 100644 --- a/IceCubesApp/App/Main/IceCubesApp+Tabbar.swift +++ b/IceCubesApp/App/Main/IceCubesApp+Tabbar.swift @@ -1,5 +1,5 @@ -import SwiftUI import Env +import SwiftUI extension IceCubesApp { var tabBarView: some View { @@ -45,8 +45,7 @@ extension IceCubesApp { } .id(appAccountsManager.currentClient.id) } - - + private func badgeFor(tab: Tab) -> Int { if tab == .notifications, selectedTab != tab, let token = appAccountsManager.currentAccount.oauthToken diff --git a/IceCubesApp/App/Main/IceCubesApp.swift b/IceCubesApp/App/Main/IceCubesApp.swift index f83261bf..4578e490 100644 --- a/IceCubesApp/App/Main/IceCubesApp.swift +++ b/IceCubesApp/App/Main/IceCubesApp.swift @@ -4,12 +4,12 @@ import AVFoundation import DesignSystem import Env import KeychainSwift +import MediaUI import Network import RevenueCat import Status import SwiftUI import Timeline -import MediaUI @main struct IceCubesApp: App { @@ -41,7 +41,7 @@ struct IceCubesApp: App { appScene otherScenes } - + func setNewClientsInEnv(client: Client) { currentAccount.setClient(client: client) currentInstance.setClient(client: client) diff --git a/IceCubesApp/App/SideBarView.swift b/IceCubesApp/App/SideBarView.swift index e7b79404..c95cc7a4 100644 --- a/IceCubesApp/App/SideBarView.swift +++ b/IceCubesApp/App/SideBarView.swift @@ -8,7 +8,7 @@ import SwiftUI @MainActor struct SideBarView: View { @Environment(\.openWindow) private var openWindow - + @Environment(AppAccountsManager.self) private var appAccounts @Environment(CurrentAccount.self) private var currentAccount @Environment(Theme.self) private var theme diff --git a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift index 88af1e56..c457f0d8 100644 --- a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift +++ b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift @@ -169,7 +169,7 @@ struct SettingsTabs: View { private var otherSections: some View { @Bindable var preferences = preferences Section("settings.section.other") { - if !ProcessInfo.processInfo.isMacCatalystApp{ + if !ProcessInfo.processInfo.isMacCatalystApp { Picker(selection: $preferences.preferredBrowser) { ForEach(PreferredBrowser.allCases, id: \.rawValue) { browser in switch browser { diff --git a/Packages/Account/Sources/Account/AccountDetailContextMenu.swift b/Packages/Account/Sources/Account/AccountDetailContextMenu.swift index aec72dbb..0d0f9c09 100644 --- a/Packages/Account/Sources/Account/AccountDetailContextMenu.swift +++ b/Packages/Account/Sources/Account/AccountDetailContextMenu.swift @@ -7,7 +7,7 @@ public struct AccountDetailContextMenu: View { @Environment(RouterPath.self) private var routerPath @Environment(CurrentInstance.self) private var currentInstance @Environment(UserPreferences.self) private var preferences - + @Binding var showBlockConfirmation: Bool var viewModel: AccountDetailViewModel diff --git a/Packages/Account/Sources/Account/AccountDetailHeaderView.swift b/Packages/Account/Sources/Account/AccountDetailHeaderView.swift index 3627c671..6c8ea777 100644 --- a/Packages/Account/Sources/Account/AccountDetailHeaderView.swift +++ b/Packages/Account/Sources/Account/AccountDetailHeaderView.swift @@ -81,7 +81,7 @@ struct AccountDetailHeaderView: View { return } let attachement = MediaAttachment.imageWith(url: account.header) - + if ProcessInfo.processInfo.isMacCatalystApp { openWindow(value: WindowDestination.mediaViewer(attachments: [attachement], selectedAttachment: attachement)) diff --git a/Packages/Conversations/Sources/Conversations/Detail/ConversationMessageView.swift b/Packages/Conversations/Sources/Conversations/Detail/ConversationMessageView.swift index 66cbaedd..c8c2e9fe 100644 --- a/Packages/Conversations/Sources/Conversations/Detail/ConversationMessageView.swift +++ b/Packages/Conversations/Sources/Conversations/Detail/ConversationMessageView.swift @@ -106,11 +106,10 @@ struct ConversationMessageView: View { Button { Task { do { - let status: Status - if isLiked { - status = try await client.post(endpoint: Statuses.unfavorite(id: message.id)) + let status: Status = if isLiked { + try await client.post(endpoint: Statuses.unfavorite(id: message.id)) } else { - status = try await client.post(endpoint: Statuses.favorite(id: message.id)) + try await client.post(endpoint: Statuses.favorite(id: message.id)) } withAnimation { isLiked = status.favourited == true @@ -123,11 +122,10 @@ struct ConversationMessageView: View { } Button { Task { do { - let status: Status - if isBookmarked { - status = try await client.post(endpoint: Statuses.unbookmark(id: message.id)) + let status: Status = if isBookmarked { + try await client.post(endpoint: Statuses.unbookmark(id: message.id)) } else { - status = try await client.post(endpoint: Statuses.bookmark(id: message.id)) + try await client.post(endpoint: Statuses.bookmark(id: message.id)) } withAnimation { isBookmarked = status.bookmarked == true diff --git a/Packages/DesignSystem/Sources/DesignSystem/SceneDelegate.swift b/Packages/DesignSystem/Sources/DesignSystem/SceneDelegate.swift index ee32cf7f..44881c96 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/SceneDelegate.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/SceneDelegate.swift @@ -14,12 +14,12 @@ import UIKit { guard let windowScene = scene as? UIWindowScene else { return } window = windowScene.keyWindow - + #if targetEnvironment(macCatalyst) - if let titlebar = windowScene.titlebar { - titlebar.titleVisibility = .hidden - titlebar.toolbar = nil - } + if let titlebar = windowScene.titlebar { + titlebar.titleVisibility = .hidden + titlebar.toolbar = nil + } #endif } } diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/LazyResizableImage.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/LazyResizableImage.swift index e9098869..b8833dbc 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/LazyResizableImage.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/LazyResizableImage.swift @@ -10,33 +10,33 @@ import NukeUI import SwiftUI /// A LazyImage (Nuke) with a geometry reader under the hood in order to use a Resize Processor to optimize performances on lists. -/// This views also allows smooth resizing of the images by debouncing the update of the ImageProcessor. +/// This views also allows smooth resizing of the images by debouncing the update of the ImageProcessor. public struct LazyResizableImage: View { - public init(url: URL?, @ViewBuilder content: @escaping (LazyImageState, GeometryProxy) -> Content) { - self.imageURL = url - self.content = content - } + public init(url: URL?, @ViewBuilder content: @escaping (LazyImageState, GeometryProxy) -> Content) { + imageURL = url + self.content = content + } - let imageURL: URL? - @State private var resizeProcessor: ImageProcessors.Resize? - @State private var debouncedTask: Task? + let imageURL: URL? + @State private var resizeProcessor: ImageProcessors.Resize? + @State private var debouncedTask: Task? - @ViewBuilder - private var content: (LazyImageState, _ proxy: GeometryProxy) -> Content + @ViewBuilder + private var content: (LazyImageState, _ proxy: GeometryProxy) -> Content - public var body: some View { - GeometryReader { proxy in - LazyImage(url: imageURL) { state in - content(state, proxy) - } - .processors([resizeProcessor == nil ? .resize(size: proxy.size) : resizeProcessor!]) - .onChange(of: proxy.size, initial: true) { oldValue, newValue in - debouncedTask?.cancel() - debouncedTask = Task { - do { try await Task.sleep(for: .milliseconds(200)) } catch { return } - resizeProcessor = .resize(size: newValue) - } - } + public var body: some View { + GeometryReader { proxy in + LazyImage(url: imageURL) { state in + content(state, proxy) + } + .processors([resizeProcessor == nil ? .resize(size: proxy.size) : resizeProcessor!]) + .onChange(of: proxy.size, initial: true) { _, newValue in + debouncedTask?.cancel() + debouncedTask = Task { + do { try await Task.sleep(for: .milliseconds(200)) } catch { return } + resizeProcessor = .resize(size: newValue) } + } } + } } diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/StatusEditorToolbarItem.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/StatusEditorToolbarItem.swift index c77d3c53..c7b18e65 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/StatusEditorToolbarItem.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/StatusEditorToolbarItem.swift @@ -4,8 +4,9 @@ import SwiftUI @MainActor public extension View { - func statusEditorToolbarItem(routerPath: RouterPath, - visibility: Models.Visibility) -> some ToolbarContent { + func statusEditorToolbarItem(routerPath _: RouterPath, + visibility: Models.Visibility) -> some ToolbarContent + { StatusEditorToolbarItem(visibility: visibility) } } diff --git a/Packages/Env/Sources/Env/QuickLook.swift b/Packages/Env/Sources/Env/QuickLook.swift index b3e89ffb..06980c60 100644 --- a/Packages/Env/Sources/Env/QuickLook.swift +++ b/Packages/Env/Sources/Env/QuickLook.swift @@ -6,11 +6,11 @@ import QuickLook @Observable public class QuickLook { public var selectedMediaAttachment: MediaAttachment? public var mediaAttachments: [MediaAttachment] = [] - + public static let shared = QuickLook() - + private init() {} - + public func prepareFor(selectedMediaAttachment: MediaAttachment, mediaAttachments: [MediaAttachment]) { self.selectedMediaAttachment = selectedMediaAttachment self.mediaAttachments = mediaAttachments diff --git a/Packages/Env/Sources/Env/UserPreferences.swift b/Packages/Env/Sources/Env/UserPreferences.swift index aeaef989..f5b21e41 100644 --- a/Packages/Env/Sources/Env/UserPreferences.swift +++ b/Packages/Env/Sources/Env/UserPreferences.swift @@ -80,28 +80,26 @@ import SwiftUI storage.pendingShownAtBottom = pendingShownAtBottom } } - + public var pendingShownLeft: Bool { didSet { storage.pendingShownLeft = pendingShownLeft } } - + public var pendingLocation: Alignment { - get { - let fromLeft = Locale.current.language.characterDirection == .leftToRight ? pendingShownLeft : !pendingShownLeft - if pendingShownAtBottom { - if fromLeft { - return .bottomLeading - } else { - return .bottomTrailing - } + let fromLeft = Locale.current.language.characterDirection == .leftToRight ? pendingShownLeft : !pendingShownLeft + if pendingShownAtBottom { + if fromLeft { + return .bottomLeading } else { - if fromLeft { - return .topLeading - } else { - return .topTrailing - } + return .bottomTrailing + } + } else { + if fromLeft { + return .topLeading + } else { + return .topTrailing } } } @@ -375,7 +373,7 @@ import SwiftUI } public var totalNotificationsCount: Int { - notificationsCount.compactMap{ $0.value }.reduce(0, +) + notificationsCount.compactMap(\.value).reduce(0, +) } public func reloadNotificationsCount(tokens: [OauthToken]) { @@ -456,6 +454,6 @@ import SwiftUI collapseLongPosts = storage.collapseLongPosts shareButtonBehavior = storage.shareButtonBehavior pendingShownAtBottom = storage.pendingShownAtBottom - pendingShownLeft = storage.pendingShownLeft + pendingShownLeft = storage.pendingShownLeft } } diff --git a/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentImageView.swift b/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentImageView.swift index b3f54a38..e29f1aaf 100644 --- a/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentImageView.swift +++ b/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentImageView.swift @@ -1,12 +1,12 @@ -import SwiftUI import Models import NukeUI +import SwiftUI struct MediaUIAttachmentImageView: View { let url: URL - + @GestureState private var zoom = 1.0 - + var body: some View { MediaUIZoomableContainer { LazyImage(url: url) { state in diff --git a/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentVideoView.swift b/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentVideoView.swift index cd0472bd..1d5c12d5 100644 --- a/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentVideoView.swift +++ b/Packages/MediaUI/Sources/MediaUI/MediaUIAttachmentVideoView.swift @@ -57,7 +57,7 @@ public struct MediaUIAttachmentVideoView: View { @Environment(Theme.self) private var theme @State var viewModel: MediaUIAttachmentVideoViewModel - + public init(viewModel: MediaUIAttachmentVideoViewModel) { _viewModel = .init(wrappedValue: viewModel) } @@ -67,7 +67,7 @@ public struct MediaUIAttachmentVideoView: View { VideoPlayer(player: viewModel.player) .accessibilityAddTraits(.startsMediaSession) - if !preferences.autoPlayVideo && !viewModel.forceAutoPlay { + if !preferences.autoPlayVideo, !viewModel.forceAutoPlay { Image(systemName: "play.fill") .font(isCompact ? .body : .largeTitle) .foregroundColor(theme.tintColor) diff --git a/Packages/MediaUI/Sources/MediaUI/MediaUITransferableImage.swift b/Packages/MediaUI/Sources/MediaUI/MediaUITransferableImage.swift index cc7ba426..9779431a 100644 --- a/Packages/MediaUI/Sources/MediaUI/MediaUITransferableImage.swift +++ b/Packages/MediaUI/Sources/MediaUI/MediaUITransferableImage.swift @@ -1,10 +1,10 @@ +import CoreTransferable import SwiftUI import UIKit -import CoreTransferable struct MediaUIImageTransferable: Codable, Transferable { let url: URL - + func fetchAsImage() async -> Image { let data = try? await URLSession.shared.data(from: url).0 guard let data, let uiimage = UIImage(data: data) else { @@ -12,7 +12,7 @@ struct MediaUIImageTransferable: Codable, Transferable { } return Image(uiImage: uiimage) } - + static var transferRepresentation: some TransferRepresentation { ProxyRepresentation { media in await media.fetchAsImage() diff --git a/Packages/MediaUI/Sources/MediaUI/MediaUIView.swift b/Packages/MediaUI/Sources/MediaUI/MediaUIView.swift index db49a5d5..23647bc5 100644 --- a/Packages/MediaUI/Sources/MediaUI/MediaUIView.swift +++ b/Packages/MediaUI/Sources/MediaUI/MediaUIView.swift @@ -1,7 +1,7 @@ -import Nuke -import SwiftUI import Models +import Nuke import QuickLook +import SwiftUI public struct MediaUIView: View, @unchecked Sendable { private let data: [DisplayData] @@ -36,8 +36,8 @@ public struct MediaUIView: View, @unchecked Sendable { } public init(selectedAttachment: MediaAttachment, attachments: [MediaAttachment]) { - self.data = attachments.compactMap { DisplayData(from: $0) } - self.initialItem = DisplayData(from: selectedAttachment) + data = attachments.compactMap { DisplayData(from: $0) } + initialItem = DisplayData(from: selectedAttachment) } } @@ -45,9 +45,9 @@ private struct MediaToolBar: ToolbarContent { let data: DisplayData var body: some ToolbarContent { -#if !targetEnvironment(macCatalyst) - DismissToolbarItem() -#endif + #if !targetEnvironment(macCatalyst) + DismissToolbarItem() + #endif QuickLookToolbarItem(itemUrl: data.url) AltTextToolbarItem(alt: data.description) SavePhotoToolbarItem(url: data.url, type: data.type) @@ -75,15 +75,15 @@ private struct AltTextToolbarItem: ToolbarContent { var body: some ToolbarContent { ToolbarItem(placement: .topBarTrailing) { - if let alt = alt { + if let alt { Button { isAlertDisplayed = true } label: { Text("status.image.alt-text.abbreviation") } .alert("status.editor.media.image-description", - isPresented: $isAlertDisplayed - ) { + isPresented: $isAlertDisplayed) + { Button("alert.button.ok", action: {}) } message: { Text(alt) @@ -118,8 +118,8 @@ private struct SavePhotoToolbarItem: ToolbarContent, @unchecked Sendable { } label: { switch state { case .unsaved: Image(systemName: "arrow.down.circle") - case .saving : ProgressView() - case .saved : Image(systemName: "checkmark.circle.fill") + case .saving: ProgressView() + case .saved: Image(systemName: "checkmark.circle.fill") } } } else { @@ -205,7 +205,7 @@ private struct QuickLookToolbarItem: ToolbarContent, @unchecked Sendable { in: .userDomainMask, appropriateFor: nil, create: false) - .appending(component: "quicklook") + .appending(component: "quicklook") } } @@ -236,9 +236,9 @@ private struct DisplayData: Identifiable, Hashable { guard let url = attachment.url else { return nil } guard let type = attachment.supportedType else { return nil } - self.id = attachment.id + id = attachment.id self.url = url - self.description = attachment.description + description = attachment.description self.type = DisplayType(from: type) } } diff --git a/Packages/MediaUI/Sources/MediaUI/MediaUIZoomableContainer.swift b/Packages/MediaUI/Sources/MediaUI/MediaUIZoomableContainer.swift index 66cabb5a..5ed46dbb 100644 --- a/Packages/MediaUI/Sources/MediaUI/MediaUIZoomableContainer.swift +++ b/Packages/MediaUI/Sources/MediaUI/MediaUIZoomableContainer.swift @@ -3,41 +3,41 @@ import UIKit // ref: https://stackoverflow.com/questions/74238414/is-there-an-easy-way-to-pinch-to-zoom-and-drag-any-view-in-swiftui -fileprivate let maxAllowedScale = 4.0 +private let maxAllowedScale = 4.0 @MainActor struct MediaUIZoomableContainer: View { let content: Content @State private var currentScale: CGFloat = 1.0 @State private var tapLocation: CGPoint = .zero - + init(@ViewBuilder content: () -> Content) { self.content = content() } - + func doubleTapAction(location: CGPoint) { tapLocation = location currentScale = currentScale == 1.0 ? maxAllowedScale : 1.0 } - + var body: some View { ZoomableScrollView(scale: $currentScale, tapLocation: $tapLocation) { content } .onTapGesture(count: 2, perform: doubleTapAction) } - + fileprivate struct ZoomableScrollView: UIViewRepresentable { private var content: ScollContent @Binding private var currentScale: CGFloat @Binding private var tapLocation: CGPoint - + init(scale: Binding, tapLocation: Binding, @ViewBuilder content: () -> ScollContent) { _currentScale = scale _tapLocation = tapLocation self.content = content() } - + func makeUIView(context: Context) -> UIScrollView { let scrollView = UIScrollView() scrollView.backgroundColor = .clear @@ -49,24 +49,24 @@ struct MediaUIZoomableContainer: View { scrollView.showsVerticalScrollIndicator = false scrollView.clipsToBounds = false scrollView.backgroundColor = .clear - + let hostedView = context.coordinator.hostingController.view! hostedView.translatesAutoresizingMaskIntoConstraints = true hostedView.autoresizingMask = [.flexibleWidth, .flexibleHeight] hostedView.frame = scrollView.bounds hostedView.backgroundColor = .clear scrollView.addSubview(hostedView) - + return scrollView } - + func makeCoordinator() -> Coordinator { - return Coordinator(hostingController: UIHostingController(rootView: content), scale: $currentScale) + Coordinator(hostingController: UIHostingController(rootView: content), scale: $currentScale) } - + func updateUIView(_ uiView: UIScrollView, context: Context) { context.coordinator.hostingController.rootView = content - + if uiView.zoomScale > uiView.minimumZoomScale { // Scale out uiView.setZoomScale(currentScale, animated: true) } else if tapLocation != .zero { // Scale in to a specific point @@ -74,32 +74,32 @@ struct MediaUIZoomableContainer: View { DispatchQueue.main.async { tapLocation = .zero } } } - + @MainActor func zoomRect(for scrollView: UIScrollView, scale: CGFloat, center: CGPoint) -> CGRect { let scrollViewSize = scrollView.bounds.size - + let width = scrollViewSize.width / scale let height = scrollViewSize.height / scale let x = center.x - (width / 2.0) let y = center.y - (height / 2.0) - + return CGRect(x: x, y: y, width: width, height: height) } - + class Coordinator: NSObject, UIScrollViewDelegate { var hostingController: UIHostingController @Binding var currentScale: CGFloat - + init(hostingController: UIHostingController, scale: Binding) { self.hostingController = hostingController _currentScale = scale } - - func viewForZooming(in scrollView: UIScrollView) -> UIView? { - return hostingController.view + + func viewForZooming(in _: UIScrollView) -> UIView? { + hostingController.view } - - func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) { + + func scrollViewDidEndZooming(_: UIScrollView, with _: UIView?, atScale scale: CGFloat) { currentScale = scale } } diff --git a/Packages/Models/Sources/Models/MediaAttachement.swift b/Packages/Models/Sources/Models/MediaAttachement.swift index 39986a5c..18b02fb3 100644 --- a/Packages/Models/Sources/Models/MediaAttachement.swift +++ b/Packages/Models/Sources/Models/MediaAttachement.swift @@ -44,14 +44,14 @@ public struct MediaAttachment: Codable, Identifiable, Hashable, Equatable { public let previewUrl: URL? public let description: String? public let meta: MetaContainer? - - public static func imageWith(url: URL) -> MediaAttachment{ - return .init(id: UUID().uuidString, - type: "image", - url: url, - previewUrl: url, - description: nil, - meta: nil) + + public static func imageWith(url: URL) -> MediaAttachment { + .init(id: UUID().uuidString, + type: "image", + url: url, + previewUrl: url, + description: nil, + meta: nil) } } diff --git a/Packages/Models/Sources/Models/SwiftData/Draft.swift b/Packages/Models/Sources/Models/SwiftData/Draft.swift index 34418c89..6a456b93 100644 --- a/Packages/Models/Sources/Models/SwiftData/Draft.swift +++ b/Packages/Models/Sources/Models/SwiftData/Draft.swift @@ -4,7 +4,7 @@ import SwiftUI @Model public class Draft { public var content: String = "" - public var creationDate: Date = Date() + public var creationDate: Date = .init() public init(content: String) { self.content = content diff --git a/Packages/Models/Sources/Models/SwiftData/LocalTimeline.swift b/Packages/Models/Sources/Models/SwiftData/LocalTimeline.swift index 84319a10..a24fd380 100644 --- a/Packages/Models/Sources/Models/SwiftData/LocalTimeline.swift +++ b/Packages/Models/Sources/Models/SwiftData/LocalTimeline.swift @@ -4,7 +4,7 @@ import SwiftUI @Model public class LocalTimeline { public var instance: String = "" - public var creationDate: Date = Date() + public var creationDate: Date = .init() public init(instance: String) { self.instance = instance diff --git a/Packages/Models/Sources/Models/SwiftData/TagGroup.swift b/Packages/Models/Sources/Models/SwiftData/TagGroup.swift index de8acfe1..910d1f97 100644 --- a/Packages/Models/Sources/Models/SwiftData/TagGroup.swift +++ b/Packages/Models/Sources/Models/SwiftData/TagGroup.swift @@ -6,7 +6,7 @@ import SwiftUI public var title: String = "" public var symbolName: String = "" public var tags: [String] = [] - public var creationDate: Date = Date() + public var creationDate: Date = .init() public init(title: String, symbolName: String, tags: [String]) { self.title = title diff --git a/Packages/Network/Sources/Network/Client.swift b/Packages/Network/Sources/Network/Client.swift index 991ff12d..e0b048c2 100644 --- a/Packages/Network/Sources/Network/Client.swift +++ b/Packages/Network/Sources/Network/Client.swift @@ -18,7 +18,7 @@ import SwiftUI public enum Version: String, Sendable { case v1, v2 } - + public enum ClientError: Error { case unexpectedRequest } @@ -93,7 +93,8 @@ import SwiftUI private func makeURL(scheme: String = "https", endpoint: Endpoint, forceVersion: Version? = nil, - forceServer: String? = nil) throws -> URL { + forceServer: String? = nil) throws -> URL + { var components = URLComponents() components.scheme = scheme components.host = forceServer ?? server @@ -140,7 +141,7 @@ import SwiftUI } public func getWithLink(endpoint: Endpoint) async throws -> (Entity, LinkHandler?) { - let (data, httpResponse) = try await urlSession.data(for: try makeGet(endpoint: endpoint)) + let (data, httpResponse) = try await urlSession.data(for: makeGet(endpoint: endpoint)) var linkHandler: LinkHandler? if let response = httpResponse as? HTTPURLResponse, let link = response.allHeaderFields["Link"] as? String diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorView.swift b/Packages/Status/Sources/Status/Editor/StatusEditorView.swift index 8b5dc2d6..a0a58dbe 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorView.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorView.swift @@ -27,7 +27,7 @@ public struct StatusEditorView: View { @State private var isDismissAlertPresented: Bool = false @State private var isLanguageConfirmPresented = false - + @State private var editingContainer: StatusEditorMediaContainer? public init(mode: StatusEditorViewModel.Mode) { @@ -290,7 +290,7 @@ public struct StatusEditorView: View { ) } } - + private func close() { if ProcessInfo.processInfo.isMacCatalystApp { dismissWindow() diff --git a/Packages/Status/Sources/Status/Row/StatusRowView.swift b/Packages/Status/Sources/Status/Row/StatusRowView.swift index 98e75224..8c3bde11 100644 --- a/Packages/Status/Sources/Status/Row/StatusRowView.swift +++ b/Packages/Status/Sources/Status/Row/StatusRowView.swift @@ -211,7 +211,7 @@ public struct StatusRowView: View { let attachments = viewModel.finalStatus.mediaAttachments if ProcessInfo.processInfo.isMacCatalystApp { openWindow(value: WindowDestination.mediaViewer(attachments: attachments, - selectedAttachment: attachments[0])) + selectedAttachment: attachments[0])) } else { quickLook.prepareFor(selectedMediaAttachment: attachments[0], mediaAttachments: attachments) } diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowMediaPreviewView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowMediaPreviewView.swift index 02f5769a..b594f3ea 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowMediaPreviewView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowMediaPreviewView.swift @@ -1,10 +1,10 @@ import DesignSystem import Env +import MediaUI import Models import Nuke import NukeUI import SwiftUI -import MediaUI @MainActor public struct StatusRowMediaPreviewView: View { @@ -29,7 +29,7 @@ public struct StatusRowMediaPreviewView: View { var availableWidth: CGFloat { if UIDevice.current.userInterfaceIdiom == .phone && - (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) || theme.statusDisplayStyle == .medium + (UIDevice.current.orientation == .landscapeLeft || UIDevice.current.orientation == .landscapeRight) || theme.statusDisplayStyle == .medium { return sceneDelegate.windowWidth * 0.80 } diff --git a/Packages/Timeline/Sources/Timeline/TimelineView.swift b/Packages/Timeline/Sources/Timeline/TimelineView.swift index c3603098..96d0d976 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineView.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineView.swift @@ -4,9 +4,9 @@ import Models import Network import Shimmer import Status +import SwiftData import SwiftUI import SwiftUIIntrospect -import SwiftData @MainActor public struct TimelineView: View { @@ -26,9 +26,9 @@ public struct TimelineView: View { @Binding var timeline: TimelineFilter @Binding var selectedTagGroup: TagGroup? @Binding var scrollToTopSignal: Int - + @Query(sort: \TagGroup.creationDate, order: .reverse) var tagGroups: [TagGroup] - + private let canFilterTimeline: Bool public init(timeline: Binding, @@ -224,7 +224,7 @@ public struct TimelineView: View { bottom: 8, trailing: .layoutPadding)) } - + @ToolbarContentBuilder private var toolbarTitleView: some ToolbarContent { ToolbarItem(placement: .principal) { @@ -262,7 +262,7 @@ public struct TimelineView: View { .accessibilityRespondsToUserInteraction(canFilterTimeline) } } - + @ToolbarContentBuilder private var toolbarTagGroupButton: some ToolbarContent { ToolbarItem(placement: .topBarTrailing) {