Swift format

This commit is contained in:
Thomas Ricouard 2023-01-30 07:27:06 +01:00
parent 5871d13eee
commit 16636b12a9
26 changed files with 191 additions and 187 deletions

View file

@ -116,7 +116,8 @@ struct IceCubesApp: App {
} }
} }
if proxy.frame(in: .global).width > (.maxColumnWidth + .secondaryColumnWidth), if proxy.frame(in: .global).width > (.maxColumnWidth + .secondaryColumnWidth),
currentAccount.account?.id != nil { currentAccount.account?.id != nil
{
Divider().edgesIgnoringSafeArea(.all) Divider().edgesIgnoringSafeArea(.all)
NotificationsTab(popToRootTab: $popToRootTab, lockedType: nil) NotificationsTab(popToRootTab: $popToRootTab, lockedType: nil)
.environment(\.isSecondaryColumn, true) .environment(\.isSecondaryColumn, true)

View file

@ -12,7 +12,7 @@ struct QuickLookPreview: UIViewControllerRepresentable {
let selectedURL: URL let selectedURL: URL
let urls: [URL] let urls: [URL]
func makeUIViewController(context: Context) -> UIViewController { func makeUIViewController(context _: Context) -> UIViewController {
return AppQLPreviewController(selectedURL: selectedURL, urls: urls) return AppQLPreviewController(selectedURL: selectedURL, urls: urls)
} }
@ -25,7 +25,7 @@ class AppQLPreviewController: UIViewController {
let selectedURL: URL let selectedURL: URL
let urls: [URL] let urls: [URL]
var qlController : QLPreviewController? var qlController: QLPreviewController?
init(selectedURL: URL, urls: [URL]) { init(selectedURL: URL, urls: [URL]) {
self.selectedURL = selectedURL self.selectedURL = selectedURL
@ -33,49 +33,49 @@ class AppQLPreviewController: UIViewController {
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
} }
required init?(coder: NSCoder) { @available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
if self.qlController == nil { if qlController == nil {
self.qlController = QLPreviewController() qlController = QLPreviewController()
self.qlController?.dataSource = self qlController?.dataSource = self
self.qlController?.delegate = self qlController?.delegate = self
self.qlController?.currentPreviewItemIndex = urls.firstIndex(of: selectedURL) ?? 0 qlController?.currentPreviewItemIndex = urls.firstIndex(of: selectedURL) ?? 0
self.present(self.qlController!, animated: true) present(qlController!, animated: true)
} }
} }
} }
extension AppQLPreviewController : QLPreviewControllerDataSource { extension AppQLPreviewController: QLPreviewControllerDataSource {
func numberOfPreviewItems(in _: QLPreviewController) -> Int { func numberOfPreviewItems(in _: QLPreviewController) -> Int {
return self.urls.count return urls.count
} }
func previewController(_: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { func previewController(_: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
return self.urls[index] as QLPreviewItem return urls[index] as QLPreviewItem
} }
} }
extension AppQLPreviewController : QLPreviewControllerDelegate { extension AppQLPreviewController: QLPreviewControllerDelegate {
func previewController(_: QLPreviewController, editingModeFor _: QLPreviewItem) -> QLPreviewItemEditingMode { func previewController(_: QLPreviewController, editingModeFor _: QLPreviewItem) -> QLPreviewItemEditingMode {
.createCopy .createCopy
} }
func previewControllerWillDismiss(_ controller: QLPreviewController) { func previewControllerWillDismiss(_: QLPreviewController) {
self.dismiss(animated: true) dismiss(animated: true)
} }
} }
struct TransparentBackground: UIViewControllerRepresentable { struct TransparentBackground: UIViewControllerRepresentable {
public func makeUIViewController(context: Context) -> UIViewController { public func makeUIViewController(context _: Context) -> UIViewController {
return TransparentController() return TransparentController()
} }
public func updateUIViewController(_ uiViewController: UIViewController, context: Context) { public func updateUIViewController(_: UIViewController, context _: Context) {}
}
class TransparentController: UIViewController { class TransparentController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {

View file

@ -5,13 +5,13 @@ import Status
import SwiftUI import SwiftUI
struct DisplaySettingsView: View { struct DisplaySettingsView: View {
typealias FontState = Theme.FontState typealias FontState = Theme.FontState
@Environment(\.colorScheme) private var colorScheme @Environment(\.colorScheme) private var colorScheme
@EnvironmentObject private var theme: Theme @EnvironmentObject private var theme: Theme
@EnvironmentObject private var userPreferences: UserPreferences @EnvironmentObject private var userPreferences: UserPreferences
@State private var isFontSelectorPresented = false @State private var isFontSelectorPresented = false
var body: some View { var body: some View {
Form { Form {
@ -35,21 +35,21 @@ struct DisplaySettingsView: View {
.listRowBackground(theme.primaryBackgroundColor) .listRowBackground(theme.primaryBackgroundColor)
Section("settings.display.section.display") { Section("settings.display.section.display") {
Picker("settings.display.font", selection: .init(get: { Picker("settings.display.font", selection: .init(get: {
userPreferences.chosenFontData != nil ? FontState.custom : FontState.system userPreferences.chosenFontData != nil ? FontState.custom : FontState.system
}, set: { newValue in }, set: { newValue in
switch newValue { switch newValue {
case .system: case .system:
userPreferences.chosenFont = nil userPreferences.chosenFont = nil
case .custom: case .custom:
isFontSelectorPresented = true isFontSelectorPresented = true
}
})) {
ForEach(FontState.allCases, id: \.rawValue) { fontState in
Text(fontState.title).tag(fontState)
}
} }
.navigationDestination(isPresented: $isFontSelectorPresented, destination: { FontPicker() }) })) {
ForEach(FontState.allCases, id: \.rawValue) { fontState in
Text(fontState.title).tag(fontState)
}
}
.navigationDestination(isPresented: $isFontSelectorPresented, destination: { FontPicker() })
Picker("settings.display.avatar.position", selection: $theme.avatarPosition) { Picker("settings.display.avatar.position", selection: $theme.avatarPosition) {
ForEach(Theme.AvatarPosition.allCases, id: \.rawValue) { position in ForEach(Theme.AvatarPosition.allCases, id: \.rawValue) { position in
Text(position.description).tag(position) Text(position.description).tag(position)

View file

@ -23,8 +23,8 @@ struct IconSelectorView: View {
static var officialIcons: [Icon] { static var officialIcons: [Icon] {
[.primary, .alt1, .alt2, .alt3, .alt4, .alt5, .alt6, .alt7, .alt8, [.primary, .alt1, .alt2, .alt3, .alt4, .alt5, .alt6, .alt7, .alt8,
.alt9, .alt10, .alt11, .alt12, .alt13, .alt14, .alt9, .alt10, .alt11, .alt12, .alt13, .alt14,
.alt15, .alt16, .alt17, .alt18, .alt19] .alt15, .alt16, .alt17, .alt18, .alt19]
} }
static var albertKinngIcons: [Icon] { static var albertKinngIcons: [Icon] {

View file

@ -44,7 +44,7 @@ class ShareViewController: UIViewController {
childView.view.topAnchor.constraint(equalTo: self.view.topAnchor), childView.view.topAnchor.constraint(equalTo: self.view.topAnchor),
childView.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor), childView.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
childView.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor), childView.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
childView.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor) childView.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
]) ])
} }
} }

View file

@ -28,7 +28,7 @@ struct AccountDetailHeaderView: View {
Rectangle() Rectangle()
.frame(height: 200) .frame(height: 200)
.overlay { .overlay {
headerImageView headerImageView
} }
accountInfoView accountInfoView
} }

View file

@ -2,36 +2,36 @@ import Env
import SwiftUI import SwiftUI
public struct FontPicker: UIViewControllerRepresentable { public struct FontPicker: UIViewControllerRepresentable {
@Environment(\.dismiss) var dismiss @Environment(\.dismiss) var dismiss
public class Coordinator: NSObject, UIFontPickerViewControllerDelegate { public class Coordinator: NSObject, UIFontPickerViewControllerDelegate {
private let dismiss: DismissAction private let dismiss: DismissAction
public init(dismiss: DismissAction) { public init(dismiss: DismissAction) {
self.dismiss = dismiss self.dismiss = dismiss
}
public func fontPickerViewControllerDidCancel(_ viewController: UIFontPickerViewController) {
dismiss()
}
public func fontPickerViewControllerDidPickFont(_ viewController: UIFontPickerViewController) {
UserPreferences.shared.chosenFont = UIFont(descriptor: viewController.selectedFontDescriptor!, size: 0)
dismiss()
}
} }
public init() {} public func fontPickerViewControllerDidCancel(_: UIFontPickerViewController) {
dismiss()
public func makeCoordinator() -> Coordinator {
Coordinator(dismiss: dismiss)
} }
public func makeUIViewController(context: Context) -> UIFontPickerViewController { public func fontPickerViewControllerDidPickFont(_ viewController: UIFontPickerViewController) {
let controller = UIFontPickerViewController() UserPreferences.shared.chosenFont = UIFont(descriptor: viewController.selectedFontDescriptor!, size: 0)
controller.delegate = context.coordinator dismiss()
return controller
} }
}
public func updateUIViewController(_ viewController: UIFontPickerViewController, context: Context) {} public init() {}
public func makeCoordinator() -> Coordinator {
Coordinator(dismiss: dismiss)
}
public func makeUIViewController(context: Context) -> UIFontPickerViewController {
let controller = UIFontPickerViewController()
controller.delegate = context.coordinator
return controller
}
public func updateUIViewController(_: UIFontPickerViewController, context _: Context) {}
} }

View file

@ -9,20 +9,20 @@ public class Theme: ObservableObject {
case followSystemColorSchme case followSystemColorSchme
} }
public enum FontState: Int, CaseIterable { public enum FontState: Int, CaseIterable {
case system case system
case custom case custom
@MainActor @MainActor
public var title: LocalizedStringKey { public var title: LocalizedStringKey {
switch self { switch self {
case .system: case .system:
return "settings.display.font.system" return "settings.display.font.system"
case .custom: case .custom:
return "settings.display.font.custom" return "settings.display.font.custom"
} }
}
} }
}
public enum AvatarPosition: String, CaseIterable { public enum AvatarPosition: String, CaseIterable {
case leading, top case leading, top

View file

@ -48,7 +48,7 @@ struct ThemeApplier: ViewModifier {
setBarsColor(newValue) setBarsColor(newValue)
} }
.onChange(of: theme.selectedScheme) { newValue in .onChange(of: theme.selectedScheme) { newValue in
setWindowUserInterfaceStyle(from: newValue) setWindowUserInterfaceStyle(from: newValue)
} }
.onChange(of: colorScheme) { newColorScheme in .onChange(of: colorScheme) { newColorScheme in
if theme.followSystemColorScheme, if theme.followSystemColorScheme,
@ -64,8 +64,8 @@ struct ThemeApplier: ViewModifier {
#if canImport(UIKit) #if canImport(UIKit)
private func setWindowUserInterfaceStyle(from colorScheme: ColorScheme) { private func setWindowUserInterfaceStyle(from colorScheme: ColorScheme) {
guard !theme.followSystemColorScheme else { guard !theme.followSystemColorScheme else {
setWindowUserInterfaceStyle(.unspecified) setWindowUserInterfaceStyle(.unspecified)
return return
} }
switch colorScheme { switch colorScheme {
case .dark: case .dark:

View file

@ -5,8 +5,8 @@ private struct SecondaryColumnKey: EnvironmentKey {
static let defaultValue = false static let defaultValue = false
} }
extension EnvironmentValues { public extension EnvironmentValues {
public var isSecondaryColumn: Bool { var isSecondaryColumn: Bool {
get { self[SecondaryColumnKey.self] } get { self[SecondaryColumnKey.self] }
set { self[SecondaryColumnKey.self] = newValue } set { self[SecondaryColumnKey.self] = newValue }
} }

View file

@ -33,7 +33,7 @@ public class QuickLook: ObservableObject {
paths.append(path) paths.append(path)
} }
return paths.sorted { url1, url2 in return paths.sorted { url1, url2 in
return pathOrderMap[url1.lastPathComponent] ?? 0 < pathOrderMap[url2.lastPathComponent] ?? 0 pathOrderMap[url1.lastPathComponent] ?? 0 < pathOrderMap[url2.lastPathComponent] ?? 0
} }
}) })
withTransaction(transaction) { withTransaction(transaction) {

View file

@ -26,7 +26,7 @@ public class UserPreferences: ObservableObject {
@AppStorage("app_default_post_visibility") public var appDefaultPostVisibility: Models.Visibility = .pub @AppStorage("app_default_post_visibility") public var appDefaultPostVisibility: Models.Visibility = .pub
@AppStorage("app_default_posts_sensitive") public var appDefaultPostsSensitive = false @AppStorage("app_default_posts_sensitive") public var appDefaultPostsSensitive = false
@AppStorage("autoplay_video") public var autoPlayVideo = true @AppStorage("autoplay_video") public var autoPlayVideo = true
@AppStorage("chosen_font") public private(set) var chosenFontData: Data? @AppStorage("chosen_font") public private(set) var chosenFontData: Data?
public var postVisibility: Models.Visibility { public var postVisibility: Models.Visibility {
if useInstanceContentSettings { if useInstanceContentSettings {
@ -69,22 +69,23 @@ public class UserPreferences: ObservableObject {
} }
} }
public var chosenFont: UIFont? { public var chosenFont: UIFont? {
get { get {
guard let chosenFontData, guard let chosenFontData,
let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil } let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil }
return font return font
}
set {
if let font = newValue,
let data = try? NSKeyedArchiver.archivedData(withRootObject: font, requiringSecureCoding: false) {
chosenFontData = data
} else {
chosenFontData = nil
}
}
} }
set {
if let font = newValue,
let data = try? NSKeyedArchiver.archivedData(withRootObject: font, requiringSecureCoding: false)
{
chosenFontData = data
} else {
chosenFontData = nil
}
}
}
@Published public var serverPreferences: ServerPreferences? @Published public var serverPreferences: ServerPreferences?

View file

@ -24,7 +24,7 @@ public struct HTMLString: Decodable, Equatable, Hashable {
// other characters the markdown parser used picks up // other characters the markdown parser used picks up
// when it renders to attributed text // when it renders to attributed text
if let regex = try? NSRegularExpression(pattern: "([\\_\\`\\[\\\\])", options: .caseInsensitive) { if let regex = try? NSRegularExpression(pattern: "([\\_\\`\\[\\\\])", options: .caseInsensitive) {
htmlValue = regex.stringByReplacingMatches(in: htmlValue, options: [], range: NSRange(location: 0, length: htmlValue.count), withTemplate: "\\\\$1") htmlValue = regex.stringByReplacingMatches(in: htmlValue, options: [], range: NSRange(location: 0, length: htmlValue.count), withTemplate: "\\\\$1")
} }
do { do {

View file

@ -32,8 +32,8 @@ struct NotificationRowView: View {
} }
} }
} }
.alignmentGuide(.listRowSeparatorLeading) { viewDimensions in .alignmentGuide(.listRowSeparatorLeading) { _ in
return -100 -100
} }
} }

View file

@ -1,6 +1,6 @@
import DesignSystem
import Models import Models
import SwiftUI import SwiftUI
import DesignSystem
extension Models.Notification.NotificationType { extension Models.Notification.NotificationType {
func label(count: Int) -> LocalizedStringKey { func label(count: Int) -> LocalizedStringKey {

View file

@ -103,7 +103,7 @@ public struct NotificationsListView: View {
bottom: 12, bottom: 12,
trailing: .layoutPadding)) trailing: .layoutPadding))
.listRowBackground(notification.type == .mention && lockedType != .mention ? .listRowBackground(notification.type == .mention && lockedType != .mention ?
theme.secondaryBackgroundColor : theme.primaryBackgroundColor) theme.secondaryBackgroundColor : theme.primaryBackgroundColor)
} }
} }
@ -146,7 +146,7 @@ public struct NotificationsListView: View {
} }
private var topPaddingView: some View { private var topPaddingView: some View {
HStack { } HStack {}
.listRowBackground(Color.clear) .listRowBackground(Color.clear)
.listRowSeparator(.hidden) .listRowSeparator(.hidden)
.listRowInsets(.init()) .listRowInsets(.init())

View file

@ -51,8 +51,8 @@ public struct StatusDetailView: View {
StatusRowView(viewModel: .init(status: status, StatusRowView(viewModel: .init(status: status,
isCompact: false, isCompact: false,
isFocused: true)) isFocused: true))
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
.id(status.id) .id(status.id)
Divider() Divider()
.padding(.bottom, .dividerPadding * 2) .padding(.bottom, .dividerPadding * 2)
if !context.descendants.isEmpty { if !context.descendants.isEmpty {

View file

@ -1,6 +1,6 @@
import AVKit import AVKit
import SwiftUI
import Env import Env
import SwiftUI
class VideoPlayerViewModel: ObservableObject { class VideoPlayerViewModel: ObservableObject {
@Published var player: AVPlayer? @Published var player: AVPlayer?

View file

@ -87,7 +87,7 @@ struct StatusActionsView: View {
} }
.buttonStyle(.borderless) .buttonStyle(.borderless)
.disabled(action == .boost && .disabled(action == .boost &&
(viewModel.status.visibility == .direct || viewModel.status.visibility == .priv)) (viewModel.status.visibility == .direct || viewModel.status.visibility == .priv))
Spacer() Spacer()
} }
} }

View file

@ -86,7 +86,8 @@ struct StatusRowContextMenu: View {
} }
} label: { } label: {
if let statusLanguage = viewModel.status.language, if let statusLanguage = viewModel.status.language,
let lanugageName = Locale.current.localizedString(forLanguageCode: statusLanguage) { let lanugageName = Locale.current.localizedString(forLanguageCode: statusLanguage)
{
Label("status.action.translate-from-\(lanugageName)", systemImage: "captions.bubble") Label("status.action.translate-from-\(lanugageName)", systemImage: "captions.bubble")
} else { } else {
Label("status.action.translate", systemImage: "captions.bubble") Label("status.action.translate", systemImage: "captions.bubble")

View file

@ -317,7 +317,8 @@ public struct StatusRowView: View {
ProgressView() ProgressView()
} else { } else {
if let statusLanguage = status.language, if let statusLanguage = status.language,
let lanugageName = Locale.current.localizedString(forLanguageCode: statusLanguage) { let lanugageName = Locale.current.localizedString(forLanguageCode: statusLanguage)
{
Text("status.action.translate-from-\(lanugageName)") Text("status.action.translate-from-\(lanugageName)")
} else { } else {
Text("status.action.translate") Text("status.action.translate")