Improve swipe actions and settings (#808)

* Remove an unnecessary space from string

settings.swipeactions.status.trailing

* Make SwipeActionsSettingsView to be consistent with others

* Divide none as another section

* Add icons

* Make hollow icons work

* Show different button label by its status

* Use different colors by actions

* Fix swapped icons in settings

* Refactor
This commit is contained in:
Chanhwi Joo 2023-02-12 18:37:09 +09:00 committed by GitHub
parent e6c5f2a9ca
commit 0b3319c2e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 81 additions and 45 deletions

View file

@ -7,35 +7,56 @@ struct SwipeActionsSettingsView: View {
@EnvironmentObject private var userPreferences: UserPreferences @EnvironmentObject private var userPreferences: UserPreferences
var body: some View { var body: some View {
Form { Form {
Section("settings.swipeactions.status") { Section("settings.swipeactions.status") {
HStack { Label("settings.swipeactions.status.leading", systemImage: "arrow.right.circle")
Text("settings.swipeactions.status.leading")
Image(systemName: "arrow.right")
}
Picker(selection: $userPreferences.swipeActionsStatusLeadingLeft, label: makeSwipeLabel(left: true, text: "settings.swipeactions.status.leading.left")) { Picker(selection: $userPreferences.swipeActionsStatusLeadingLeft, label: makeSwipeLabel(left: true, text: "settings.swipeactions.status.leading.left")) {
ForEach(StatusAction.allCases) { action in Section {
Text(action.displayName).tag(action) Label(StatusAction.none.displayName(), systemImage: StatusAction.none.iconName()).tag(StatusAction.none)
}
Section {
ForEach(StatusAction.allCases) { action in
if (action != .none) {
Label(action.displayName(), systemImage: action.iconName()).tag(action)
}
}
} }
} }
Picker(selection: $userPreferences.swipeActionsStatusLeadingRight, label: makeSwipeLabel(left: false, text: "settings.swipeactions.status.leading.right")) { Picker(selection: $userPreferences.swipeActionsStatusLeadingRight, label: makeSwipeLabel(left: false, text: "settings.swipeactions.status.leading.right")) {
ForEach(StatusAction.allCases) { action in Section {
Text(action.displayName).tag(action) Label(StatusAction.none.displayName(), systemImage: StatusAction.none.iconName()).tag(StatusAction.none)
}
Section {
ForEach(StatusAction.allCases) { action in
if (action != .none) {
Label(action.displayName(), systemImage: action.iconName()).tag(action)
}
}
} }
} }
HStack { Label("settings.swipeactions.status.trailing", systemImage: "arrow.left.circle")
Text("settings.swipeactions.status.trailing")
Image(systemName: "arrow.left")
}
Picker(selection: $userPreferences.swipeActionsStatusTrailingLeft, label: makeSwipeLabel(left: true, text: "settings.swipeactions.status.trailing.left")) { Picker(selection: $userPreferences.swipeActionsStatusTrailingLeft, label: makeSwipeLabel(left: true, text: "settings.swipeactions.status.trailing.left")) {
ForEach(StatusAction.allCases) { action in Section {
Text(action.displayName).tag(action) Label(StatusAction.none.displayName(), systemImage: StatusAction.none.iconName()).tag(StatusAction.none)
}
Section {
ForEach(StatusAction.allCases) { action in
if (action != .none) {
Label(action.displayName(), systemImage: action.iconName()).tag(action)
}
}
} }
} }
Picker(selection: $userPreferences.swipeActionsStatusTrailingRight, label: makeSwipeLabel(left: false, text: "settings.swipeactions.status.trailing.right")) { Picker(selection: $userPreferences.swipeActionsStatusTrailingRight, label: makeSwipeLabel(left: false, text: "settings.swipeactions.status.trailing.right")) {
ForEach(StatusAction.allCases) { action in Section {
Text(action.displayName).tag(action) Label(StatusAction.none.displayName(), systemImage: StatusAction.none.iconName()).tag(StatusAction.none)
}
Section {
ForEach(StatusAction.allCases) { action in
if (action != .none) {
Label(action.displayName(), systemImage: action.iconName()).tag(action)
}
}
} }
} }
} }
@ -47,9 +68,7 @@ struct SwipeActionsSettingsView: View {
} }
private func makeSwipeLabel(left: Bool, text: LocalizedStringKey) -> some View { private func makeSwipeLabel(left: Bool, text: LocalizedStringKey) -> some View {
return HStack { return Label(text, systemImage: left ? "rectangle.lefthalf.filled" : "rectangle.righthalf.filled")
Image(systemName: left ? "rectangle.lefthalf.filled" : "rectangle.righthalf.filled") .padding(.leading, 16)
Text(text)
}.padding(.leading, 16)
} }
} }

View file

@ -171,7 +171,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -169,7 +169,7 @@
"settings.swipeactions.status.leading" = "Nach rechts wischen"; "settings.swipeactions.status.leading" = "Nach rechts wischen";
"settings.swipeactions.status.leading.left" = "links"; "settings.swipeactions.status.leading.left" = "links";
"settings.swipeactions.status.leading.right" = "links"; "settings.swipeactions.status.leading.right" = "links";
"settings.swipeactions.status.trailing" = " Nach links wischen"; "settings.swipeactions.status.trailing" = "Nach links wischen";
"settings.swipeactions.status.trailing.left" = "links"; "settings.swipeactions.status.trailing.left" = "links";
"settings.swipeactions.status.trailing.right" = "rechts"; "settings.swipeactions.status.trailing.right" = "rechts";
"settings.swipeactions.status" = "Beitrag"; "settings.swipeactions.status" = "Beitrag";

View file

@ -175,7 +175,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -173,7 +173,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -169,7 +169,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -172,7 +172,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -172,7 +172,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -172,7 +172,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -169,7 +169,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -172,7 +172,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -172,7 +172,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -172,7 +172,7 @@
"settings.swipeactions.status.leading" = "Swipe right"; "settings.swipeactions.status.leading" = "Swipe right";
"settings.swipeactions.status.leading.left" = "left"; "settings.swipeactions.status.leading.left" = "left";
"settings.swipeactions.status.leading.right" = "right"; "settings.swipeactions.status.leading.right" = "right";
"settings.swipeactions.status.trailing" = " Swipe left"; "settings.swipeactions.status.trailing" = "Swipe left";
"settings.swipeactions.status.trailing.left" = "left"; "settings.swipeactions.status.trailing.left" = "left";
"settings.swipeactions.status.trailing.right" = "right"; "settings.swipeactions.status.trailing.right" = "right";
"settings.swipeactions.status" = "Post"; "settings.swipeactions.status" = "Post";

View file

@ -4,9 +4,10 @@ public enum StatusAction : String, CaseIterable, Identifiable {
public var id: String { public var id: String {
"\(rawValue)" "\(rawValue)"
} }
case none, boost, reply, quote, favorite, bookmark
public var displayName: LocalizedStringKey { case none, reply, boost, favorite, bookmark, quote
public func displayName(isReblogged: Bool = false, isFavorited: Bool = false, isBookmarked: Bool = false) -> LocalizedStringKey {
switch self { switch self {
case .none: case .none:
return "settings.swipeactions.status.action.none" return "settings.swipeactions.status.action.none"
@ -15,11 +16,11 @@ public enum StatusAction : String, CaseIterable, Identifiable {
case .quote: case .quote:
return "settings.swipeactions.status.action.quote" return "settings.swipeactions.status.action.quote"
case .boost: case .boost:
return "settings.swipeactions.status.action.boost" return isReblogged ? "status.action.unboost" : "settings.swipeactions.status.action.boost"
case .favorite: case .favorite:
return "settings.swipeactions.status.action.favorite" return isFavorited ? "status.action.unfavorite" : "settings.swipeactions.status.action.favorite"
case .bookmark: case .bookmark:
return "settings.swipeactions.status.action.bookmark" return isBookmarked ? "status.action.unbookmark" : "settings.swipeactions.status.action.bookmark"
} }
} }
@ -39,4 +40,21 @@ public enum StatusAction : String, CaseIterable, Identifiable {
return isBookmarked ? "bookmark.fill" : "bookmark" return isBookmarked ? "bookmark.fill" : "bookmark"
} }
} }
public func color(themeTintColor: Color) -> Color {
switch self {
case .none:
return .gray
case .reply:
return .gray
case .quote:
return .gray
case .boost:
return themeTintColor
case .favorite:
return .yellow
case .bookmark:
return .pink
}
}
} }

View file

@ -455,11 +455,9 @@ public struct StatusRowView: View {
private var trailingSwipeActions: some View { private var trailingSwipeActions: some View {
if preferences.swipeActionsStatusTrailingRight != StatusAction.none { if preferences.swipeActionsStatusTrailingRight != StatusAction.none {
makeSwipeButton(action: preferences.swipeActionsStatusTrailingRight) makeSwipeButton(action: preferences.swipeActionsStatusTrailingRight)
.tint(theme.tintColor)
} }
if preferences.swipeActionsStatusTrailingLeft != StatusAction.none { if preferences.swipeActionsStatusTrailingLeft != StatusAction.none {
makeSwipeButton(action: preferences.swipeActionsStatusTrailingLeft) makeSwipeButton(action: preferences.swipeActionsStatusTrailingLeft)
.tint(.gray)
} }
} }
@ -467,11 +465,9 @@ public struct StatusRowView: View {
private var leadingSwipeActions: some View { private var leadingSwipeActions: some View {
if preferences.swipeActionsStatusLeadingLeft != StatusAction.none { if preferences.swipeActionsStatusLeadingLeft != StatusAction.none {
makeSwipeButton(action: preferences.swipeActionsStatusLeadingLeft) makeSwipeButton(action: preferences.swipeActionsStatusLeadingLeft)
.tint(theme.tintColor)
} }
if preferences.swipeActionsStatusLeadingRight != StatusAction.none { if preferences.swipeActionsStatusLeadingRight != StatusAction.none {
makeSwipeButton(action: preferences.swipeActionsStatusLeadingRight) makeSwipeButton(action: preferences.swipeActionsStatusLeadingRight)
.tint(.gray)
} }
} }
@ -518,10 +514,11 @@ public struct StatusRowView: View {
HapticManager.shared.fireHaptic(of: .notification(.success)) HapticManager.shared.fireHaptic(of: .notification(.success))
routerPath.presentedSheet = destination routerPath.presentedSheet = destination
} label: { } label: {
Text(action.displayName) Text(action.displayName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked))
Image(systemName: action.iconName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked)) Image(systemName: action.iconName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked))
.foregroundColor(.red) .environment(\.symbolVariants, .none)
} }
.tint(action.color(themeTintColor: theme.tintColor))
} }
@ViewBuilder @ViewBuilder
@ -532,8 +529,10 @@ public struct StatusRowView: View {
await task() await task()
} }
} label: { } label: {
Text(action.displayName) Text(action.displayName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked))
Image(systemName: action.iconName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked)) Image(systemName: action.iconName(isReblogged: viewModel.isReblogged, isFavorited: viewModel.isFavorited, isBookmarked: viewModel.isBookmarked))
.environment(\.symbolVariants, .none)
} }
.tint(action.color(themeTintColor: theme.tintColor))
} }
} }