Skip to content

Commit af30072

Browse files
committed
IOS-5401 Migrate
1 parent 3d6313d commit af30072

File tree

6 files changed

+60
-27
lines changed

6 files changed

+60
-27
lines changed

Anytype/Sources/ApplicationLayer/GlobalEnv/GlobalEnvModifier.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import SwiftUI
44
private struct GlobalEnvModifier: ViewModifier {
55

66
@State private var windowHolder = WindowHolder(window: nil)
7-
@Injected(\.userDefaultsStorage)
8-
private var userDefaults: any UserDefaultsStorageProtocol
9-
@Injected(\.legacyViewControllerProvider)
10-
private var viewControllerProvider: any ViewControllerProviderProtocol
7+
@State private var model = GlobalEnvModifierModel()
118

129
func body(content: Content) -> some View {
1310
content
@@ -17,13 +14,30 @@ private struct GlobalEnvModifier: ViewModifier {
1714
.setAppInterfaceStyleEnv(window: windowHolder.window)
1815
// Legacy :(
1916
.onChange(of: windowHolder) { _, newValue in
20-
viewControllerProvider.setSceneWindow(newValue.window)
21-
newValue.window?.overrideUserInterfaceStyle = userDefaults.userInterfaceStyle
17+
model.setSceneWindow(newValue.window)
18+
newValue.window?.overrideUserInterfaceStyle = model.userInterfaceStyle
2219
}
2320

2421
}
2522
}
2623

24+
@MainActor
25+
@Observable
26+
private final class GlobalEnvModifierModel {
27+
@Injected(\.userDefaultsStorage) @ObservationIgnored
28+
private var userDefaults: any UserDefaultsStorageProtocol
29+
@Injected(\.legacyViewControllerProvider) @ObservationIgnored
30+
private var viewControllerProvider: any ViewControllerProviderProtocol
31+
32+
var userInterfaceStyle: UIUserInterfaceStyle {
33+
userDefaults.userInterfaceStyle
34+
}
35+
36+
func setSceneWindow(_ window: UIWindow?) {
37+
viewControllerProvider.setSceneWindow(window)
38+
}
39+
}
40+
2741
extension View {
2842
func setupGlobalEnv() -> some View {
2943
self.modifier(GlobalEnvModifier())

Anytype/Sources/PresentationLayer/Common/SwiftUI/IconView/Specific/Object/TodoIconView.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import Services
55
struct TodoIconView: View {
66

77
private static let maxSide = 28.0
8-
9-
@Injected(\.objectActionsService)
10-
private var objectActionsService: any ObjectActionsServiceProtocol
8+
@State private var model = TodoIconViewModel()
119

1210
let checked: Bool
1311
let objectId: String?
@@ -20,10 +18,22 @@ struct TodoIconView: View {
2018
.frame(maxWidth: 28, maxHeight: 28)
2119
.onTapGesture {
2220
guard let objectId else { return }
23-
Task {
24-
try await objectActionsService.updateBundledDetails(contextID: objectId, details: [.done(!checked)])
25-
UIImpactFeedbackGenerator(style: .rigid).impactOccurred()
26-
}
21+
model.updateDone(objectId: objectId, checked: !checked)
2722
}
2823
}
2924
}
25+
26+
@MainActor
27+
@Observable
28+
private final class TodoIconViewModel {
29+
30+
@Injected(\.objectActionsService) @ObservationIgnored
31+
private var objectActionsService: any ObjectActionsServiceProtocol
32+
33+
func updateDone(objectId: String, checked: Bool) {
34+
Task {
35+
try await objectActionsService.updateBundledDetails(contextID: objectId, details: [.done(checked)])
36+
UIImpactFeedbackGenerator(style: .rigid).impactOccurred()
37+
}
38+
}
39+
}

Anytype/Sources/PresentationLayer/Debug/ExportStackGoroutines/ExportStackGoroutinesViewModifier.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import SwiftUI
22
import Services
33

4-
54
struct ExportStackGoroutinesViewModifier: ViewModifier {
6-
@Injected(\.debugService)
7-
private var debugService: any DebugServiceProtocol
85

6+
@State private var model = ExportStackGoroutinesViewModel()
97
@State private var shareUrlFile: URL?
108
@Binding var isPresented: Bool
119

@@ -21,10 +19,21 @@ struct ExportStackGoroutinesViewModifier: ViewModifier {
2119
}
2220

2321
private func exportStackGoroutines() {
24-
Task { shareUrlFile = try await debugService.exportStackGoroutinesZip() }
22+
Task { shareUrlFile = try await model.exportStackGoroutinesZip() }
2523
}
2624
}
2725

26+
@MainActor
27+
@Observable
28+
private final class ExportStackGoroutinesViewModel {
29+
30+
@Injected(\.debugService) @ObservationIgnored
31+
private var debugService: any DebugServiceProtocol
32+
33+
func exportStackGoroutinesZip() async throws -> URL {
34+
try await debugService.exportStackGoroutinesZip()
35+
}
36+
}
2837

2938
extension View {
3039
func exportStackGoroutinesSheet(isPresented: Binding<Bool>) -> some View {

Anytype/Sources/PresentationLayer/Modules/Chat/AttachmentProcessor.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import Factory
77
import AnytypeCore
88

99
@MainActor
10-
protocol AttachmentProcessor {
10+
protocol AttachmentProcessor: AnyObject {
1111
associatedtype Input
1212
func process(_ input: Input, spaceId: String) throws -> ChatLinkedObject
1313
}
1414

1515
@MainActor
16-
protocol AsyncAttachmentProcessor {
16+
protocol AsyncAttachmentProcessor: AnyObject {
1717
associatedtype Input
1818
func process(_ input: Input, spaceId: String) async throws -> ChatLinkedObject
1919
}
2020

2121
@MainActor
22-
struct FileAttachmentProcessor: AttachmentProcessor {
22+
final class FileAttachmentProcessor: AttachmentProcessor {
2323

2424
@Injected(\.fileActionsService)
2525
private var fileActionsService: any FileActionsServiceProtocol
@@ -39,7 +39,7 @@ struct FileAttachmentProcessor: AttachmentProcessor {
3939
}
4040

4141
@MainActor
42-
struct CameraMediaProcessor: AttachmentProcessor {
42+
final class CameraMediaProcessor: AttachmentProcessor {
4343

4444
@Injected(\.fileActionsService)
4545
private var fileActionsService: any FileActionsServiceProtocol
@@ -61,7 +61,7 @@ struct CameraMediaProcessor: AttachmentProcessor {
6161
}
6262

6363
@MainActor
64-
struct PhotosPickerProcessor: AsyncAttachmentProcessor {
64+
final class PhotosPickerProcessor: AsyncAttachmentProcessor {
6565

6666
@Injected(\.fileActionsService)
6767
private var fileActionsService: any FileActionsServiceProtocol
@@ -73,7 +73,7 @@ struct PhotosPickerProcessor: AsyncAttachmentProcessor {
7373
}
7474

7575
@MainActor
76-
struct PasteBufferProcessor: AsyncAttachmentProcessor {
76+
final class PasteBufferProcessor: AsyncAttachmentProcessor {
7777

7878
@Injected(\.fileActionsService)
7979
private var fileActionsService: any FileActionsServiceProtocol
@@ -87,7 +87,7 @@ struct PasteBufferProcessor: AsyncAttachmentProcessor {
8787
}
8888

8989
@MainActor
90-
struct LinkPreviewProcessor: AsyncAttachmentProcessor {
90+
final class LinkPreviewProcessor: AsyncAttachmentProcessor {
9191

9292
@Injected(\.bookmarkService)
9393
private var bookmarkService: any BookmarkServiceProtocol
@@ -106,7 +106,7 @@ struct LinkPreviewProcessor: AsyncAttachmentProcessor {
106106
}
107107

108108
@MainActor
109-
struct UploadedObjectProcessor: AttachmentProcessor {
109+
final class UploadedObjectProcessor: AttachmentProcessor {
110110

111111
func process(_ input: MessageAttachmentDetails, spaceId: String) throws -> ChatLinkedObject {
112112
return .uploadedObject(input)

Anytype/Sources/PresentationLayer/Modules/Chat/AttachmentValidator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct AttachmentValidationResult {
1313
}
1414

1515
@MainActor
16-
struct ChatAttachmentValidator {
16+
final class ChatAttachmentValidator {
1717

1818
@Injected(\.chatMessageLimits)
1919
private var chatMessageLimits: any ChatMessageLimitsProtocol

Anytype/Sources/PresentationLayer/TextEditor/BlocksViews/Blocks/File/Image/BlockImageViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Combine
44
import AnytypeCore
55

66
@MainActor
7-
struct BlockImageViewModel: BlockViewModelProtocol {
7+
final class BlockImageViewModel: BlockViewModelProtocol {
88
typealias Action<T> = (_ arg: T) -> Void
99

1010
@Injected(\.openedDocumentProvider)

0 commit comments

Comments
 (0)