Skip to content

Commit 46b4e52

Browse files
authored
Merge pull request #4181 from anyproto/ios-5255-update-object-settings-menu-converted-to-project
IOS-5255 Update Object Settings Menu
2 parents ceb36d1 + e721230 commit 46b4e52

29 files changed

+575
-51
lines changed

Anytype/Sources/PresentationLayer/Flows/EditorSetFlow/EditorSetCoordinatorViewModel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ final class EditorSetCoordinatorViewModel:
253253

254254
func templateEditingHandler(
255255
setting: ObjectCreationSetting,
256-
onSetAsDefaultTempalte: @escaping (String) -> Void,
256+
onSetAsDefaultTemplate: @escaping (String) -> Void,
257257
onTemplateSelection: ((ObjectCreationSetting) -> Void)?
258258
) {
259-
legacySetObjectCreationSettingsCoordinator.templateEditingHandler(setting: setting, onSetAsDefaultTempalte: onSetAsDefaultTempalte, onTemplateSelection: onTemplateSelection)
259+
legacySetObjectCreationSettingsCoordinator.templateEditingHandler(setting: setting, onSetAsDefaultTemplate: onSetAsDefaultTemplate, onTemplateSelection: onTemplateSelection)
260260
}
261261

262262
func onObjectTypeLayoutTap(_ data: LayoutPickerData) {
@@ -282,7 +282,7 @@ final class EditorSetCoordinatorViewModel:
282282

283283
templatesCoordinator.showTemplatesPicker(
284284
data: data,
285-
onSetAsDefaultTempalte: { [weak self] templateId in
285+
onSetAsDefaultTemplate: { [weak self] templateId in
286286
self?.setTemplateAsDefault(objectId: objectId, templateId: templateId)
287287
}
288288
)

Anytype/Sources/PresentationLayer/ObjectCreationSettings/SetObjectCreationSettingsCoordinator.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ protocol SetObjectCreationSettingsCoordinatorProtocol: AnyObject, SetObjectCreat
88
func showTemplateEditing(
99
setting: ObjectCreationSetting,
1010
onTemplateSelection: (() -> Void)?,
11-
onSetAsDefaultTempalte: @escaping (String) -> Void,
11+
onSetAsDefaultTemplate: @escaping (String) -> Void,
1212
completion: (() -> Void)?
1313
)
1414
}
@@ -32,7 +32,7 @@ final class SetObjectCreationSettingsCoordinator:
3232
func showTemplateEditing(
3333
setting: ObjectCreationSetting,
3434
onTemplateSelection: (() -> Void)?,
35-
onSetAsDefaultTempalte: @escaping (String) -> Void,
35+
onSetAsDefaultTemplate: @escaping (String) -> Void,
3636
completion: (() -> Void)?
3737
) {
3838
let editorView = EditorPageCoordinatorView(
@@ -47,10 +47,13 @@ final class SetObjectCreationSettingsCoordinator:
4747
}
4848
)
4949

50-
self.useAsTemplateAction = onSetAsDefaultTempalte
50+
self.useAsTemplateAction = onSetAsDefaultTemplate
5151

5252
let editingTemplateViewController = TemplateEditingViewController(
5353
editorViewController: UIHostingController(rootView: editorView),
54+
objectId: setting.templateId,
55+
spaceId: setting.spaceId,
56+
output: self,
5457
onSettingsTap: { [weak self] in
5558
guard let self = self else { return }
5659
editorModuleInput?.showSettings(output: self)
@@ -112,20 +115,20 @@ final class SetObjectCreationSettingsCoordinator:
112115

113116
func templateEditingHandler(
114117
setting: ObjectCreationSetting,
115-
onSetAsDefaultTempalte: @escaping (String) -> Void,
118+
onSetAsDefaultTemplate: @escaping (String) -> Void,
116119
onTemplateSelection: ((ObjectCreationSetting) -> Void)?
117120
) {
118121
showTemplateEditing(
119122
setting: setting,
120123
onTemplateSelection: { [weak self] in
121124
self?.navigationContext.dismissAllPresented(animated: true) {
122-
onSetAsDefaultTempalte(setting.templateId)
125+
onSetAsDefaultTemplate(setting.templateId)
123126
onTemplateSelection?(setting)
124127
}
125128
},
126-
onSetAsDefaultTempalte: { [weak self] templateId in
129+
onSetAsDefaultTemplate: { [weak self] templateId in
127130
self?.navigationContext.dismissTopPresented(animated: true, completion: {
128-
onSetAsDefaultTempalte(templateId)
131+
onSetAsDefaultTemplate(templateId)
129132
})
130133
},
131134
completion: nil

Anytype/Sources/PresentationLayer/ObjectCreationSettings/TemplatesCoordinator.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ protocol TemplatesCoordinatorProtocol {
88
@MainActor
99
func showTemplatesPicker(
1010
document: some BaseDocumentProtocol,
11-
onSetAsDefaultTempalte: @escaping (String) -> Void
11+
onSetAsDefaultTemplate: @escaping (String) -> Void
1212
)
1313

1414
@MainActor
1515
func showTemplatesPicker(
1616
data: TemplatePickerViewModelData,
17-
onSetAsDefaultTempalte: @escaping (String) -> Void
17+
onSetAsDefaultTemplate: @escaping (String) -> Void
1818
)
1919
}
2020

@@ -26,30 +26,30 @@ final class TemplatesCoordinator: TemplatesCoordinatorProtocol, ObjectSettingsCo
2626
private var toastPresenter: any ToastPresenterProtocol
2727

2828
private var editorModuleInputs = [String: any EditorPageModuleInput]()
29-
private var onSetAsDefaultTempalte: ((String) -> Void)?
29+
private var onSetAsDefaultTemplate: ((String) -> Void)?
3030

3131
nonisolated init() {}
3232

3333
@MainActor
3434
func showTemplatesPicker(
3535
document: some BaseDocumentProtocol,
36-
onSetAsDefaultTempalte: @escaping (String) -> Void
36+
onSetAsDefaultTemplate: @escaping (String) -> Void
3737
) {
3838
let data = TemplatePickerViewModelData(
3939
mode: .objectTemplate(objectId: document.objectId),
4040
typeId: document.details?.objectType.id,
4141
spaceId: document.spaceId,
4242
defaultTemplateId: nil
4343
)
44-
showTemplatesPicker(data: data, onSetAsDefaultTempalte: onSetAsDefaultTempalte)
44+
showTemplatesPicker(data: data, onSetAsDefaultTemplate: onSetAsDefaultTemplate)
4545
}
4646

4747
@MainActor
4848
func showTemplatesPicker(
4949
data: TemplatePickerViewModelData,
50-
onSetAsDefaultTempalte: @escaping (String) -> Void
50+
onSetAsDefaultTemplate: @escaping (String) -> Void
5151
) {
52-
self.onSetAsDefaultTempalte = onSetAsDefaultTempalte
52+
self.onSetAsDefaultTemplate = onSetAsDefaultTemplate
5353
let picker = TemplatePickerView(viewModel: .init(data: data, output: self))
5454
let hostViewController = UIHostingController(rootView: picker)
5555
hostViewController.modalPresentationStyle = .fullScreen
@@ -101,7 +101,7 @@ extension TemplatesCoordinator: TemplatePickerViewModuleOutput {
101101
func didCreateTemplate(templateId: String) {}
102102

103103
func didTapUseTemplateAsDefault(templateId: String) {
104-
onSetAsDefaultTempalte?(templateId)
104+
onSetAsDefaultTemplate?(templateId)
105105
}
106106

107107
func didUndoRedo() {

Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Editing/TemplateEditingViewController.swift

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ final class TemplateEditingViewController: UIViewController {
88
private let editorViewController: UIViewController
99
private let onSettingsTap: () -> Void
1010
private let onSelectTemplateTap: (() -> Void)?
11+
private let objectId: String
12+
private let spaceId: String
13+
private weak var output: (any ObjectSettingsCoordinatorOutput)?
14+
private var settingsMenuView: UIView?
1115

1216
private lazy var keyboardHelper = KeyboardEventsListnerHelper(
1317
didShowAction: { [weak selectTemplateButton] _ in
@@ -35,10 +39,16 @@ final class TemplateEditingViewController: UIViewController {
3539

3640
init(
3741
editorViewController: UIViewController,
42+
objectId: String,
43+
spaceId: String,
44+
output: any ObjectSettingsCoordinatorOutput,
3845
onSettingsTap: @escaping () -> Void,
3946
onSelectTemplateTap: (() -> Void)?
4047
) {
4148
self.editorViewController = editorViewController
49+
self.objectId = objectId
50+
self.spaceId = spaceId
51+
self.output = output
4252
self.onSettingsTap = onSettingsTap
4353
self.onSelectTemplateTap = onSelectTemplateTap
4454

@@ -54,8 +64,8 @@ final class TemplateEditingViewController: UIViewController {
5464
override func viewDidLoad() {
5565
super.viewDidLoad()
5666

57-
setupLayout()
5867
setupView()
68+
setupLayout()
5969
}
6070

6171
@objc
@@ -73,6 +83,13 @@ final class TemplateEditingViewController: UIViewController {
7383
settingsButton.setImage(UIImage(asset: .X24.more), for: .normal)
7484
settingsButton.addTarget(self, action: #selector(didTapSettingButton), for: .touchUpInside)
7585
settingsButton.tintColor = .Control.secondary
86+
87+
if FeatureFlags.newObjectSettings, let output {
88+
let menuContainer = ObjectSettingsMenuContainer(objectId: objectId, spaceId: spaceId, output: output)
89+
let hostingController = UIHostingController(rootView: menuContainer)
90+
hostingController.view.backgroundColor = .clear
91+
self.settingsMenuView = hostingController.view
92+
}
7693
}
7794

7895
private func setupLayout() {
@@ -89,9 +106,16 @@ final class TemplateEditingViewController: UIViewController {
89106
$0.centerY.equal(to: fakeNavigationView.centerYAnchor)
90107
}
91108

92-
fakeNavigationView.addSubview(settingsButton) {
93-
$0.trailing.equal(to: fakeNavigationView.trailingAnchor, constant: -20)
94-
$0.centerY.equal(to: fakeNavigationView.centerYAnchor)
109+
if FeatureFlags.newObjectSettings, let settingsMenuView {
110+
fakeNavigationView.addSubview(settingsMenuView) {
111+
$0.trailing.equal(to: fakeNavigationView.trailingAnchor, constant: -20)
112+
$0.centerY.equal(to: fakeNavigationView.centerYAnchor)
113+
}
114+
} else {
115+
fakeNavigationView.addSubview(settingsButton) {
116+
$0.trailing.equal(to: fakeNavigationView.trailingAnchor, constant: -20)
117+
$0.centerY.equal(to: fakeNavigationView.centerYAnchor)
118+
}
95119
}
96120

97121
embedChild(editorViewController, into: view)

Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Picker/TemplatePickerView.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import SwiftUI
2+
import AnytypeCore
23

34
struct TemplatePickerView: View {
45
@StateObject var viewModel: TemplatePickerViewModel
@@ -92,12 +93,23 @@ struct TemplatePickerView: View {
9293
}
9394
}
9495

96+
@ViewBuilder
9597
private var settingsButton: some View {
96-
Button {
97-
viewModel.onSettingsButtonTap()
98-
} label: {
99-
Image(asset: .X24.more)
100-
.foregroundColor(.Control.secondary)
98+
if FeatureFlags.newObjectSettings {
99+
if viewModel.items.isNotEmpty {
100+
ObjectSettingsMenuContainer(
101+
objectId: viewModel.selectedItem().object.id,
102+
spaceId: viewModel.spaceId,
103+
output: viewModel.output
104+
)
105+
}
106+
} else {
107+
Button {
108+
viewModel.onSettingsButtonTap()
109+
} label: {
110+
Image(asset: .X24.more)
111+
.foregroundColor(.Control.secondary)
112+
}
101113
}
102114
}
103115
}

Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Picker/TemplatePickerViewModel.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Services
33
import SwiftUI
44

55
@MainActor
6-
protocol TemplatePickerViewModuleOutput: AnyObject {
6+
protocol TemplatePickerViewModuleOutput: AnyObject, ObjectSettingsCoordinatorOutput {
77
func onTemplatesChanged(_ templates: [ObjectDetails], completion: ([TemplatePickerData]) -> Void)
88
func onTemplateSettingsTap(_ model: TemplatePickerViewModel.Item)
99
func selectionOptionsView(_ provider: some OptionsItemProvider) -> AnyView
@@ -40,7 +40,9 @@ final class TemplatePickerViewModel: ObservableObject, OptionsItemProvider {
4040
if case .objectTemplate = data.mode { return true }
4141
return false
4242
}
43-
43+
44+
var spaceId: String { data.spaceId }
45+
4446
private let data: TemplatePickerViewModelData
4547
private var didSetupDefaultItem = false
4648
private var dismiss: DismissAction?
@@ -49,8 +51,8 @@ final class TemplatePickerViewModel: ObservableObject, OptionsItemProvider {
4951
private var objectService: any ObjectActionsServiceProtocol
5052
@Injected(\.templatesSubscription)
5153
private var templatesSubscriptionService: any TemplatesSubscriptionServiceProtocol
52-
53-
private weak var output: (any TemplatePickerViewModuleOutput)?
54+
55+
weak var output: (any TemplatePickerViewModuleOutput)?
5456

5557
// MARK: - OptionsItemProvider
5658

Anytype/Sources/PresentationLayer/ObjectCreationSettings/Views/Selection/SetObjectCreationSettingsViewModel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protocol SetObjectCreationSettingsOutput: AnyObject {
1515
func onObjectTypesSearchAction(setDocument: some SetDocumentProtocol, completion: @escaping (ObjectType) -> Void)
1616
func templateEditingHandler(
1717
setting: ObjectCreationSetting,
18-
onSetAsDefaultTempalte: @escaping (String) -> Void,
18+
onSetAsDefaultTemplate: @escaping (String) -> Void,
1919
onTemplateSelection: ((ObjectCreationSetting) -> Void)?
2020
)
2121
}
@@ -98,7 +98,7 @@ final class SetObjectCreationSettingsViewModel: ObservableObject {
9898
AnytypeAnalytics.instance().logTemplateCreate(objectType: .object(typeId: objectTypeId), spaceId: spaceId)
9999
output?.templateEditingHandler(
100100
setting: ObjectCreationSetting(objectTypeId: objectTypeId, spaceId: spaceId, templateId: templateId),
101-
onSetAsDefaultTempalte: { [weak self] templateId in
101+
onSetAsDefaultTemplate: { [weak self] templateId in
102102
self?.setTemplateAsDefault(templateId: templateId)
103103
},
104104
onTemplateSelection: data.onTemplateSelection
@@ -221,7 +221,7 @@ final class SetObjectCreationSettingsViewModel: ObservableObject {
221221
case .editTemplate:
222222
output?.templateEditingHandler(
223223
setting: ObjectCreationSetting(objectTypeId: objectTypeId, spaceId: spaceId, templateId: templateViewModel.id),
224-
onSetAsDefaultTempalte: { [weak self] templateId in
224+
onSetAsDefaultTemplate: { [weak self] templateId in
225225
self?.setTemplateAsDefault(templateId: templateId)
226226
},
227227
onTemplateSelection: data.onTemplateSelection

Anytype/Sources/PresentationLayer/TextEditor/EditorPage/EditorPageController.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ final class EditorPageController: UIViewController {
5454

5555
private lazy var navigationBarHelper: EditorNavigationBarHelper = EditorNavigationBarHelper(
5656
navigationBarView: navigationBarView,
57-
navigationBarBackgroundView: navigationBarBackgroundView,
57+
navigationBarBackgroundView: navigationBarBackgroundView,
58+
objectId: viewModel.document.objectId,
59+
spaceId: viewModel.document.spaceId,
60+
output: viewModel.router,
5861
onSettingsBarButtonItemTap: { [weak viewModel] in
5962
UISelectionFeedbackGenerator().selectionChanged()
6063
viewModel?.showSettings()
61-
},
64+
},
6265
onSelectAllBarButtonItemTap: { [weak self] allSelected in
6366
self?.handleSelectState(allSelected: allSelected)
6467
},
@@ -67,7 +70,7 @@ final class EditorPageController: UIViewController {
6770
},
6871
onTemplatesButtonTap: { [weak viewModel] in
6972
viewModel?.showTemplates()
70-
},
73+
},
7174
onSyncStatusTap: { [weak viewModel] in
7275
UISelectionFeedbackGenerator().selectionChanged()
7376
viewModel?.showSyncStatusInfo()

Anytype/Sources/PresentationLayer/TextEditor/EditorPage/Utils/EditorNavigationBarHelper/EditorNavigationBarHelper.swift

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22
import UIKit
33
import Services
44
import SwiftUI
5+
import AnytypeCore
56

67
@MainActor
78
final class EditorNavigationBarHelper {
@@ -16,6 +17,7 @@ final class EditorNavigationBarHelper {
1617
private let selectAllButton: UIButton
1718

1819
private let settingsItem: UIEditorBarButtonItem
20+
private let settingsMenuView: UIView?
1921
private let syncStatusItem: EditorSyncStatusItem
2022
private let webBannerItem: EditorWebBannerItem
2123
private let rightContanerForEditing: UIView
@@ -38,6 +40,9 @@ final class EditorNavigationBarHelper {
3840
init(
3941
navigationBarView: EditorNavigationBarView,
4042
navigationBarBackgroundView: UIView,
43+
objectId: String,
44+
spaceId: String,
45+
output: (any ObjectSettingsCoordinatorOutput)?,
4146
onSettingsBarButtonItemTap: @escaping () -> Void,
4247
onSelectAllBarButtonItemTap: @escaping (Bool) -> Void,
4348
onDoneBarButtonItemTap: @escaping () -> Void,
@@ -48,6 +53,16 @@ final class EditorNavigationBarHelper {
4853
self.navigationBarView = navigationBarView
4954
self.navigationBarBackgroundView = navigationBarBackgroundView
5055
self.settingsItem = UIEditorBarButtonItem(imageAsset: .X24.more, action: onSettingsBarButtonItemTap)
56+
57+
if FeatureFlags.newObjectSettings {
58+
let menuContainer = ObjectSettingsMenuContainer(objectId: objectId, spaceId: spaceId, output: output)
59+
let hostingController = UIHostingController(rootView: menuContainer)
60+
hostingController.view.backgroundColor = .clear
61+
self.settingsMenuView = hostingController.view
62+
} else {
63+
self.settingsMenuView = nil
64+
}
65+
5166
self.syncStatusItem = EditorSyncStatusItem(onTap: onSyncStatusTap)
5267
self.webBannerItem = EditorWebBannerItem(onTap: onWebBannerTap)
5368

@@ -94,11 +109,19 @@ final class EditorNavigationBarHelper {
94109
)
95110

96111
self.rightContanerForEditing.layoutUsing.stack {
97-
$0.hStack(
98-
spacing: 12,
99-
syncStatusItem,
100-
settingsItem
101-
)
112+
if FeatureFlags.newObjectSettings, let settingsMenuView {
113+
$0.hStack(
114+
spacing: 12,
115+
syncStatusItem,
116+
settingsMenuView
117+
)
118+
} else {
119+
$0.hStack(
120+
spacing: 12,
121+
syncStatusItem,
122+
settingsItem
123+
)
124+
}
102125
}
103126

104127
navigationBarView.bannerView = webBannerItem

0 commit comments

Comments
 (0)