Skip to content

Commit

Permalink
fix: Use ‘Done’ button on iOS tag editor (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Jun 26, 2023
1 parent 193c868 commit 3e2eccd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,43 @@

import SwiftUI

struct Closeable: ViewModifier {
enum DismissableAction {
case close
case done
}

struct Dismissable: ViewModifier {

@Environment(\.dismiss) var dismiss

let action: DismissableAction

var placement: ToolbarItemPlacement {
switch action {
case .close:
return .cancellationAction
case .done:
return .confirmationAction
}
}

var text: String {
switch action {
case .close:
return "Close"
case .done:
return "Done"
}
}

func body(content: Content) -> some View {
content
.toolbar {
ToolbarItem(placement: .cancellationAction) {
ToolbarItem(placement: placement) {
Button {
dismiss()
} label: {
Text("Close")
Text(text)
}
}
}
Expand All @@ -41,8 +66,8 @@ struct Closeable: ViewModifier {

extension View {

func closeable() -> some View {
return modifier(Closeable())
func dismissable(_ action: DismissableAction) -> some View {
return modifier(Dismissable(action: action))
}

}
2 changes: 1 addition & 1 deletion core/Sources/BookmarksCore/Views/PhoneEditTagsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public struct PhoneEditTagsView: View {
}
.navigationTitle("Tags")
.navigationBarTitleDisplayMode(.inline)
.closeable()
.dismissable(.done)
.defaultFocus($focus, .input)
}
.navigationViewStyle(.stack)
Expand Down
2 changes: 1 addition & 1 deletion core/Sources/BookmarksCore/Views/PhoneInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct PhoneInfoView: View {
InfoContentView(applicationModel: applicationModel, id: id)
.environmentObject(applicationModel.tagsModel)
.navigationBarTitleDisplayMode(.inline)
.closeable()
.dismissable(.close)
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/Sources/BookmarksCore/Views/PhoneSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public struct PhoneSettingsView: View {
}
}
.navigationBarTitle("Settings", displayMode: .inline)
.closeable()
.dismissable(.close)
.sheet(item: $sheet) { sheet in
switch sheet {
case .about:
Expand Down
2 changes: 1 addition & 1 deletion core/Sources/BookmarksCore/Views/PhoneTagsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct PhoneTagsView: View {
NavigationView {
TagsContentView(applicationModel: applicationModel)
.navigationBarTitle("Tags", displayMode: .inline)
.closeable()
.dismissable(.close)
}
}

Expand Down

0 comments on commit 3e2eccd

Please sign in to comment.