From fbf1c30b7cb8b993fa81fdc299ebef5f42ec28bb Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Tue, 24 Jan 2023 09:19:53 +0100 Subject: [PATCH] Add haptic feedback on more buttons fix #315 --- IceCubesApp/App/IceCubesApp.swift | 3 +++ .../Sources/AppAccount/AppAccountsSelectorView.swift | 7 +++++++ .../DesignSystem/Views/StatusEditorToolbarItem.swift | 5 +++++ Packages/Timeline/Sources/Timeline/TimelineFilter.swift | 4 ++-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/IceCubesApp/App/IceCubesApp.swift b/IceCubesApp/App/IceCubesApp.swift index 555026d7..493e2825 100644 --- a/IceCubesApp/App/IceCubesApp.swift +++ b/IceCubesApp/App/IceCubesApp.swift @@ -29,6 +29,8 @@ struct IceCubesApp: App { @State private var popToRootTab: Tab = .other @State private var sideBarLoadedTabs: Set = Set() + private let feedbackGenerator = UISelectionFeedbackGenerator() + private var availableTabs: [Tab] { appAccountsManager.currentClient.isAuth ? Tab.loggedInTabs() : Tab.loggedOutTab() } @@ -127,6 +129,7 @@ struct IceCubesApp: App { } } selectedTab = newTab + feedbackGenerator.selectionChanged() })) { ForEach(availableTabs) { tab in tab.makeContentView(popToRootTab: $popToRootTab) diff --git a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift index e160c36f..855675cc 100644 --- a/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift +++ b/Packages/AppAccount/Sources/AppAccount/AppAccountsSelectorView.swift @@ -9,6 +9,8 @@ public struct AppAccountsSelectorView: View { @ObservedObject var routerPath: RouterPath @State private var accountsViewModel: [AppAccountViewModel] = [] + + let feedbackGenerator = UIImpactFeedbackGenerator() private let accountCreationEnabled: Bool private let avatarSize: AvatarView.Size @@ -20,6 +22,8 @@ public struct AppAccountsSelectorView: View { self.routerPath = routerPath self.accountCreationEnabled = accountCreationEnabled self.avatarSize = avatarSize + + feedbackGenerator.prepare() } public var body: some View { @@ -38,6 +42,7 @@ public struct AppAccountsSelectorView: View { } } .onAppear { + feedbackGenerator.impactOccurred(intensity: 0.3) refreshAccounts() } .onChange(of: currentAccount.account?.id) { _ in @@ -66,6 +71,8 @@ public struct AppAccountsSelectorView: View { } else { appAccounts.currentAccount = viewModel.appAccount } + + feedbackGenerator.impactOccurred(intensity: 0.7) } label: { HStack { if viewModel.account?.id == currentAccount.account?.id { diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/StatusEditorToolbarItem.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/StatusEditorToolbarItem.swift index e94d0de0..1b2fc775 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/StatusEditorToolbarItem.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/StatusEditorToolbarItem.swift @@ -7,7 +7,9 @@ public extension View { func statusEditorToolbarItem(routerPath: RouterPath, visibility: Models.Visibility) -> some ToolbarContent { ToolbarItem(placement: .navigationBarTrailing) { Button { + let feedback = UISelectionFeedbackGenerator() routerPath.presentedSheet = .newStatusEditor(visibility: visibility) + feedback.selectionChanged() } label: { Image(systemName: "square.and.pencil") } @@ -17,7 +19,9 @@ public extension View { public struct StatusEditorToolbarItem: ToolbarContent { @EnvironmentObject private var routerPath: RouterPath + let visibility: Models.Visibility + let feedbackGenerator = UISelectionFeedbackGenerator() public init(visibility: Models.Visibility) { self.visibility = visibility @@ -27,6 +31,7 @@ public struct StatusEditorToolbarItem: ToolbarContent { ToolbarItem(placement: .navigationBarTrailing) { Button { routerPath.presentedSheet = .newStatusEditor(visibility: visibility) + feedbackGenerator.selectionChanged() } label: { Image(systemName: "square.and.pencil") } diff --git a/Packages/Timeline/Sources/Timeline/TimelineFilter.swift b/Packages/Timeline/Sources/Timeline/TimelineFilter.swift index 10e72c86..ddfe3331 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineFilter.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineFilter.swift @@ -10,7 +10,7 @@ public enum TimelineFilter: Hashable, Equatable { case remoteLocal(server: String) public func hash(into hasher: inout Hasher) { - hasher.combine(title()) + hasher.combine(title) } public static func availableTimeline(client: Client) -> [TimelineFilter] { @@ -20,7 +20,7 @@ public enum TimelineFilter: Hashable, Equatable { return [.home, .local, .federated, .trending] } - public func title() -> String { + public var title: String { switch self { case .federated: return "Federated"