Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #2283: Added New Haptic Feedback Behavior (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhreis authored Feb 11, 2020
1 parent aee8ee1 commit 7615af0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
4 changes: 1 addition & 3 deletions BraveRewardsUI/Ads/AdsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ public class AdsViewController: UIViewController {
// }
// adView.openSwipeButton.isHighlighted = tx > actionTriggerThreshold
if tx < -actionTriggerThreshold && !adView.dislikeSwipeButton.isHighlighted {
let impact = UIImpactFeedbackGenerator(style: .medium)
impact.prepare()
impact.impactOccurred()
UIImpactFeedbackGenerator(style: .medium).bzzt()
}
adView.dislikeSwipeButton.isHighlighted = tx < -actionTriggerThreshold
adView.adContentButton.transform.tx = min(0, tx)
Expand Down
4 changes: 1 addition & 3 deletions BraveRewardsUI/Tipping/TippingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ extension TippingViewController.View: UIScrollViewDelegate {
}, completion: nil)
})

let feedback = UIImpactFeedbackGenerator(style: .medium)
feedback.prepare()
feedback.impactOccurred()
UIImpactFeedbackGenerator(style: .medium).bzzt()
}
} else {
if isPassedDismissalThreshold {
Expand Down
4 changes: 4 additions & 0 deletions Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@
5D6DDEFE2141B6A1001FF0AE /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEF62141B6A0001FF0AE /* Preferences.swift */; };
5D6DDF0021428CF0001FF0AE /* DAUTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D6DDEFF21428CF0001FF0AE /* DAUTests.swift */; };
5D7001C222249F7B00E576FB /* ShortNameToFileMapping.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D7001BA22249F7A00E576FB /* ShortNameToFileMapping.json */; };
5D88BB7E23ED014E001096F3 /* ImpactFeedbackGeneratorExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D88BB7D23ED014E001096F3 /* ImpactFeedbackGeneratorExtensions.swift */; };
5D8AE6AF230C76B60096C845 /* AppearanceExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D8AE6AE230C76B60096C845 /* AppearanceExtensions.swift */; };
5DB474F1237F4CC9007B7652 /* ntp-data.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DB474F0237F4CC9007B7652 /* ntp-data.json */; };
5DE5250D218CE92C000DFAA6 /* block-ads.json in Resources */ = {isa = PBXBuildFile; fileRef = 5DE52508218CE92B000DFAA6 /* block-ads.json */; };
Expand Down Expand Up @@ -2087,6 +2088,7 @@
5D6DDEF62141B6A0001FF0AE /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
5D6DDEFF21428CF0001FF0AE /* DAUTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DAUTests.swift; sourceTree = "<group>"; };
5D7001BA22249F7A00E576FB /* ShortNameToFileMapping.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = ShortNameToFileMapping.json; sourceTree = "<group>"; };
5D88BB7D23ED014E001096F3 /* ImpactFeedbackGeneratorExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImpactFeedbackGeneratorExtensions.swift; sourceTree = "<group>"; };
5D8AE6AE230C76B60096C845 /* AppearanceExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceExtensions.swift; sourceTree = "<group>"; };
5DB474F0237F4CC9007B7652 /* ntp-data.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "ntp-data.json"; sourceTree = "<group>"; };
5DE52508218CE92B000DFAA6 /* block-ads.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "block-ads.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4496,6 +4498,7 @@
E65075761E37F7AB006961AC /* NSFileManagerExtensions.swift */,
E65075781E37F7AB006961AC /* ScannerExtensions.swift */,
E650757A1E37F7AB006961AC /* URLExtensions.swift */,
5D88BB7D23ED014E001096F3 /* ImpactFeedbackGeneratorExtensions.swift */,
E650757B1E37F7AB006961AC /* URLProtectionSpaceExtensions.swift */,
E650757C1E37F7AB006961AC /* SetExtensions.swift */,
E650757D1E37F7AB006961AC /* StringExtensions.swift */,
Expand Down Expand Up @@ -5834,6 +5837,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5D88BB7E23ED014E001096F3 /* ImpactFeedbackGeneratorExtensions.swift in Sources */,
E65075991E37F7AB006961AC /* Cancellable.swift in Sources */,
E65075BE1E37F7AB006961AC /* TimeConstants.swift in Sources */,
E65075B21E37F7AB006961AC /* Functions.swift in Sources */,
Expand Down
15 changes: 5 additions & 10 deletions Client/Frontend/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1723,8 +1723,7 @@ extension BrowserViewController: TopToolbarDelegate {
tab.switchUserAgent()
}))

let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.impactOccurred()
UIImpactFeedbackGenerator(style: .heavy).bzzt()
if UIDevice.current.userInterfaceIdiom == .pad {
alert.popoverPresentationController?.sourceView = self.view
alert.popoverPresentationController?.sourceRect = self.view.convert(button.frame, from: button.superview)
Expand Down Expand Up @@ -1927,8 +1926,7 @@ extension BrowserViewController: ToolbarDelegate {
}

func tabToolbarDidLongPressBack(_ tabToolbar: ToolbarProtocol, button: UIButton) {
let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.impactOccurred()
UIImpactFeedbackGenerator(style: .heavy).bzzt()
showBackForwardList()
}

Expand Down Expand Up @@ -2003,14 +2001,12 @@ extension BrowserViewController: ToolbarDelegate {
addTabAlertActions().forEach(alertController.addAction)
alertController.popoverPresentationController?.sourceView = sourceView
alertController.popoverPresentationController?.sourceRect = button.frame
let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.impactOccurred()
UIImpactFeedbackGenerator(style: .heavy).bzzt()
present(alertController, animated: true)
}

func tabToolbarDidLongPressForward(_ tabToolbar: ToolbarProtocol, button: UIButton) {
let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.impactOccurred()
UIImpactFeedbackGenerator(style: .heavy).bzzt()
showBackForwardList()
}

Expand Down Expand Up @@ -2042,8 +2038,7 @@ extension BrowserViewController: ToolbarDelegate {
controller.addAction(UIAlertAction(title: Strings.cancelButtonTitle, style: .cancel, handler: nil), accessibilityIdentifier: "toolbarTabButtonLongPress.cancel")
controller.popoverPresentationController?.sourceView = toolbar ?? topToolbar
controller.popoverPresentationController?.sourceRect = button.frame
let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.impactOccurred()
UIImpactFeedbackGenerator(style: .heavy).bzzt()
present(controller, animated: true, completion: nil)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,13 @@ class FavoritesViewController: UIViewController, Themeable {
alert.popoverPresentationController?.permittedArrowDirections = [.down, .up]
alert.addAction(UIAlertAction(title: Strings.close, style: .cancel, handler: nil))

UIImpactFeedbackGenerator(style: .medium).bzzt()
present(alert, animated: true, completion: nil)
}

@objc private func showSponsoredSite() {
guard let url = background?.sponsor?.logo.destinationUrl else { return }
UIImpactFeedbackGenerator(style: .medium).bzzt()
delegate?.didSelect(input: url)
}

Expand Down
2 changes: 2 additions & 0 deletions Client/Frontend/Browser/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class TabManager: NSObject {
}

assert(tab === selectedTab, "Expected tab is selected")

UIImpactFeedbackGenerator(style: .light).bzzt()
selectedTab?.createWebview()
selectedTab?.lastExecutedTime = Date.now()

Expand Down
15 changes: 15 additions & 0 deletions Shared/Extensions/ImpactFeedbackGeneratorExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

import UIKit

extension UIImpactFeedbackGenerator {
@discardableResult
public func bzzt() -> Self {
self.prepare()
self.impactOccurred()
// Returned in case wanted for retaining to re-impact
return self
}
}

0 comments on commit 7615af0

Please # to comment.