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),
currentAccount.account?.id != nil {
currentAccount.account?.id != nil
{
Divider().edgesIgnoringSafeArea(.all)
NotificationsTab(popToRootTab: $popToRootTab, lockedType: nil)
.environment(\.isSecondaryColumn, true)

View file

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

View file

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

View file

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

View file

@ -44,7 +44,7 @@ class ShareViewController: UIViewController {
childView.view.topAnchor.constraint(equalTo: self.view.topAnchor),
childView.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
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()
.frame(height: 200)
.overlay {
headerImageView
headerImageView
}
accountInfoView
}

View file

@ -2,36 +2,36 @@ import Env
import SwiftUI
public struct FontPicker: UIViewControllerRepresentable {
@Environment(\.dismiss) var dismiss
@Environment(\.dismiss) var dismiss
public class Coordinator: NSObject, UIFontPickerViewControllerDelegate {
private let dismiss: DismissAction
public class Coordinator: NSObject, UIFontPickerViewControllerDelegate {
private let dismiss: DismissAction
public init(dismiss: DismissAction) {
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(dismiss: DismissAction) {
self.dismiss = dismiss
}
public init() {}
public func makeCoordinator() -> Coordinator {
Coordinator(dismiss: dismiss)
public func fontPickerViewControllerDidCancel(_: UIFontPickerViewController) {
dismiss()
}
public func makeUIViewController(context: Context) -> UIFontPickerViewController {
let controller = UIFontPickerViewController()
controller.delegate = context.coordinator
return controller
public func fontPickerViewControllerDidPickFont(_ viewController: UIFontPickerViewController) {
UserPreferences.shared.chosenFont = UIFont(descriptor: viewController.selectedFontDescriptor!, size: 0)
dismiss()
}
}
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
}
public enum FontState: Int, CaseIterable {
case system
case custom
public enum FontState: Int, CaseIterable {
case system
case custom
@MainActor
public var title: LocalizedStringKey {
switch self {
case .system:
return "settings.display.font.system"
case .custom:
return "settings.display.font.custom"
}
}
@MainActor
public var title: LocalizedStringKey {
switch self {
case .system:
return "settings.display.font.system"
case .custom:
return "settings.display.font.custom"
}
}
}
public enum AvatarPosition: String, CaseIterable {
case leading, top

View file

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

View file

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

View file

@ -33,7 +33,7 @@ public class QuickLook: ObservableObject {
paths.append(path)
}
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) {

View file

@ -26,7 +26,7 @@ public class UserPreferences: ObservableObject {
@AppStorage("app_default_post_visibility") public var appDefaultPostVisibility: Models.Visibility = .pub
@AppStorage("app_default_posts_sensitive") public var appDefaultPostsSensitive = false
@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 {
if useInstanceContentSettings {
@ -69,22 +69,23 @@ public class UserPreferences: ObservableObject {
}
}
public var chosenFont: UIFont? {
get {
guard let chosenFontData,
let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil }
public var chosenFont: UIFont? {
get {
guard let chosenFontData,
let font = try? NSKeyedUnarchiver.unarchivedObject(ofClass: UIFont.self, from: chosenFontData) else { return nil }
return font
}
set {
if let font = newValue,
let data = try? NSKeyedArchiver.archivedData(withRootObject: font, requiringSecureCoding: false) {
chosenFontData = data
} else {
chosenFontData = nil
}
}
return font
}
set {
if let font = newValue,
let data = try? NSKeyedArchiver.archivedData(withRootObject: font, requiringSecureCoding: false)
{
chosenFontData = data
} else {
chosenFontData = nil
}
}
}
@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
// when it renders to attributed text
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 {

View file

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

View file

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

View file

@ -103,7 +103,7 @@ public struct NotificationsListView: View {
bottom: 12,
trailing: .layoutPadding))
.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 {
HStack { }
HStack {}
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.listRowInsets(.init())

View file

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

View file

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

View file

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

View file

@ -86,7 +86,8 @@ struct StatusRowContextMenu: View {
}
} label: {
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")
} else {
Label("status.action.translate", systemImage: "captions.bubble")

View file

@ -317,7 +317,8 @@ public struct StatusRowView: View {
ProgressView()
} else {
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)")
} else {
Text("status.action.translate")