From 5cfcb5ebb062e9233d4f59ec4147d424597a357f Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Mon, 27 Jun 2022 15:26:55 -0700 Subject: [PATCH] use toolbarGroup for create label modal on macOS --- .../xcshareddata/swiftpm/Package.resolved | 9 -- apple/OmnivoreKit/Package.swift | 12 +- .../Sources/App/Views/Labels/LabelsView.swift | 143 ++++++++++-------- 3 files changed, 89 insertions(+), 75 deletions(-) diff --git a/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved b/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved index 37df64703..5090a25ab 100644 --- a/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/apple/Omnivore.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -153,15 +153,6 @@ "version" : "2.1.0" } }, - { - "identity" : "pspdfkit-sp", - "kind" : "remoteSourceControl", - "location" : "https://github.com/PSPDFKit/PSPDFKit-SP", - "state" : { - "branch" : "master", - "revision" : "b7e5465ab62f5b48735145756e371502fa2a24f0" - } - }, { "identity" : "sovran-swift", "kind" : "remoteSourceControl", diff --git a/apple/OmnivoreKit/Package.swift b/apple/OmnivoreKit/Package.swift index f5ef78249..e72036ffe 100644 --- a/apple/OmnivoreKit/Package.swift +++ b/apple/OmnivoreKit/Package.swift @@ -55,9 +55,9 @@ let package = Package( var appPackageDependencies: [Target.Dependency] { var deps: [Target.Dependency] = ["Views", "Services", "Models", "Utils"] -// #if canImport(UIKit) - deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP")) -// #endif + #if canImport(UIKit) + deps.append(.product(name: "PSPDFKit", package: "PSPDFKit-SP")) + #endif return deps } @@ -69,8 +69,8 @@ var dependencies: [Package.Dependency] { .package(url: "git@github.com:segmentio/analytics-swift.git", .upToNextMajor(from: "1.0.0")), .package(url: "https://github.com/google/GoogleSignIn-iOS", from: "6.2.2") ] -// #if canImport(UIKit) - deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master")) -// #endif + #if canImport(UIKit) + deps.append(.package(url: "https://github.com/PSPDFKit/PSPDFKit-SP", branch: "master")) + #endif return deps } diff --git a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsView.swift b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsView.swift index c91ba2484..d26a4dc98 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Labels/LabelsView.swift @@ -37,7 +37,6 @@ struct LabelsView: View { List { innerBody } - .listStyle(InsetListStyle()) #endif } .task { await viewModel.loadLabels(dataService: dataService, item: nil) } @@ -108,81 +107,105 @@ struct CreateLabelView: View { return [firstSwatch] + webSwatches + additionalSwatches }() - var body: some View { - NavigationView { - VStack { - HStack { - if !newLabelName.isEmpty, newLabelColor != .clear { - TextChip(text: newLabelName, color: newLabelColor) - } else { - Text("Assign a name and color.").font(.appBody) - } - Spacer() + var innerBody: some View { + VStack { + HStack { + if !newLabelName.isEmpty, newLabelColor != .clear { + TextChip(text: newLabelName, color: newLabelColor) + } else { + Text("Assign a name and color.").font(.appBody) } - .padding(.bottom, 8) + Spacer() + } + .padding(.bottom, 8) - TextField("Label Name", text: $newLabelName) - #if os(iOS) - .keyboardType(.alphabet) - #endif - .textFieldStyle(StandardTextFieldStyle()) + TextField("Label Name", text: $newLabelName) + #if os(iOS) + .keyboardType(.alphabet) + #endif + .textFieldStyle(StandardTextFieldStyle()) - ScrollView(.horizontal, showsIndicators: false) { - LazyHGrid(rows: rows, alignment: .top, spacing: 20) { - ForEach(swatches, id: \.self) { swatch in - ZStack { - Circle() - .fill(swatch) - .frame(width: 50, height: 50) - .onTapGesture { - newLabelColor = swatch - } - .padding(10) - - if newLabelColor == swatch { - Circle() - .stroke(swatch, lineWidth: 5) - .frame(width: 60, height: 60) + ScrollView(.horizontal, showsIndicators: false) { + LazyHGrid(rows: rows, alignment: .top, spacing: 20) { + ForEach(swatches, id: \.self) { swatch in + ZStack { + Circle() + .fill(swatch) + .frame(width: 50, height: 50) + .onTapGesture { + newLabelColor = swatch } + .padding(10) + + if newLabelColor == swatch { + Circle() + .stroke(swatch, lineWidth: 5) + .frame(width: 60, height: 60) } } } } - Spacer() } - .padding() - .toolbar { + Spacer() + } + .padding() + .toolbar { + #if os(iOS) ToolbarItem(placement: .barLeading) { - Button( - action: { viewModel.showCreateEmailModal = false }, - label: { Text("Cancel").foregroundColor(.appGrayTextContrast) } - ) + cancelCreateLabelButton } ToolbarItem(placement: .barTrailing) { - Button( - action: { - viewModel.createLabel( - dataService: dataService, - name: newLabelName, - color: newLabelColor, - description: nil - ) - }, - label: { Text("Create").foregroundColor(.appGrayTextContrast) } - ) - .opacity(shouldDisableCreateButton ? 0.2 : 1) - .disabled(shouldDisableCreateButton) + createLabelButton + } + #else + ToolbarItemGroup { + createLabelButton + cancelCreateLabelButton } - } - .navigationTitle("Create New Label") - #if os(iOS) - .navigationBarTitleDisplayMode(.inline) #endif - .onAppear { - newLabelColor = swatches.first ?? .clear - } } } + + var cancelCreateLabelButton: some View { + Button( + action: { viewModel.showCreateEmailModal = false }, + label: { Text("Cancel").foregroundColor(.appGrayTextContrast) } + ) + } + + var createLabelButton: some View { + Button( + action: { + viewModel.createLabel( + dataService: dataService, + name: newLabelName, + color: newLabelColor, + description: nil + ) + }, + label: { Text("Create").foregroundColor(.appGrayTextContrast) } + ) + .opacity(shouldDisableCreateButton ? 0.2 : 1) + .disabled(shouldDisableCreateButton) + } + + var body: some View { + #if os(iOS) + NavigationView { + innerBody + .navigationTitle("Create New Label") + .navigationBarTitleDisplayMode(.inline) + .task { + newLabelColor = swatches.first ?? .clear + } + } + #else + innerBody + .task { + newLabelColor = swatches.first ?? .clear + } + #endif + } } private let webSwatchHexes = [