From 0ccbab53f3004c9dbfbaba2ee012799f815151e0 Mon Sep 17 00:00:00 2001 From: Abhishek Date: Sat, 26 Jun 2021 21:30:54 -0500 Subject: [PATCH] Tweaks. --- Clocker/Clocker/en.lproj/Panel.xib | 8 +++--- .../ClockerUnitTests/ClockerUnitTests.swift | 4 +-- .../ParentPanelController+ModernSlider.swift | 8 ------ Clocker/Panel/ParentPanelController.swift | 13 ++------- .../Panel/Rate Controller/ReviewView.swift | 27 +++++++++++++++++++ 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Clocker/Clocker/en.lproj/Panel.xib b/Clocker/Clocker/en.lproj/Panel.xib index 791dfae..0c73dd4 100755 --- a/Clocker/Clocker/en.lproj/Panel.xib +++ b/Clocker/Clocker/en.lproj/Panel.xib @@ -262,7 +262,7 @@ - + @@ -336,7 +336,7 @@ - + @@ -413,7 +413,7 @@ - + @@ -461,7 +461,7 @@ - + diff --git a/Clocker/ClockerUnitTests/ClockerUnitTests.swift b/Clocker/ClockerUnitTests/ClockerUnitTests.swift index ce56fda..903932b 100644 --- a/Clocker/ClockerUnitTests/ClockerUnitTests.swift +++ b/Clocker/ClockerUnitTests/ClockerUnitTests.swift @@ -130,10 +130,10 @@ class ClockerUnitTests: XCTestCase { // The below test might fail outside California or if DST is active! // CI is calibrated to be on LA timezone! func testTimeDifference() { - XCTAssertTrue(operations.timeDifference() == ", 11h 30m ahead", "Difference was unexpectedly: \(operations.timeDifference())") + XCTAssertTrue(operations.timeDifference() == ", 10h 30m ahead", "Difference was unexpectedly: \(operations.timeDifference())") XCTAssertTrue(californiaOperations.timeDifference() == ", 2h behind", "Difference was unexpectedly: \(californiaOperations.timeDifference())") XCTAssertTrue(floridaOperations.timeDifference() == ", an hour ahead", "Difference was unexpectedly: \(floridaOperations.timeDifference())") - XCTAssertTrue(aucklandOperations.timeDifference() == ", 19h ahead", "Difference was unexpectedly: \(aucklandOperations.timeDifference())") + XCTAssertTrue(aucklandOperations.timeDifference() == ", 17h ahead", "Difference was unexpectedly: \(aucklandOperations.timeDifference())") XCTAssertTrue(omahaOperations.timeDifference() == "", "Difference was unexpectedly: \(omahaOperations.timeDifference())") } diff --git a/Clocker/Panel/ParentPanelController+ModernSlider.swift b/Clocker/Panel/ParentPanelController+ModernSlider.swift index c1fcbbb..8a328d1 100644 --- a/Clocker/Panel/ParentPanelController+ModernSlider.swift +++ b/Clocker/Panel/ParentPanelController+ModernSlider.swift @@ -29,14 +29,6 @@ extension ParentPanelController { } } - @objc func scrollViewWillStartLiveScroll(_: NSNotification) { - modernSliderIsScrolling = true - } - - @objc func scrollViewDidEndLiveScroll(_: NSNotification) { - modernSliderIsScrolling = false - } - @discardableResult public func setModernLabel(_ shouldUpdate: Bool = false) -> Date { let defaultParameters = minuteFromCalendar() diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 72accbc..2e92ea6 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -89,10 +89,9 @@ class ParentPanelController: NSWindowController { // Modern Slider public var currentCenterIndexPath: Int = -1 public var closestQuarterTimeRepresentation: Date? - public var modernSliderIsScrolling: Bool = false @IBOutlet var modernSlider: NSCollectionView! @IBOutlet var modernSliderLabel: NSTextField! - @IBOutlet var modernContainerView: NSView! + @IBOutlet var modernContainerView: ModernSliderContainerView! var defaultPreferences: [Data] { return DataStore.shared().timezones() @@ -204,14 +203,6 @@ class ParentPanelController: NSWindowController { modernSlider.enclosingScrollView?.scrollerInsets = NSEdgeInsets(top: 0, left: 0, bottom: 100, right: 0) modernSlider.delegate = self modernSlider.postsBoundsChangedNotifications = true - NotificationCenter.default.addObserver(self, - selector: #selector(scrollViewWillStartLiveScroll(_:)), - name: NSScrollView.willStartLiveScrollNotification, - object: modernSlider.enclosingScrollView) - NotificationCenter.default.addObserver(self, - selector: #selector(scrollViewDidEndLiveScroll(_:)), - name: NSScrollView.didEndLiveScrollNotification, - object: modernSlider.enclosingScrollView) NotificationCenter.default.addObserver(self, selector: #selector(collectionViewDidScroll(_:)), name: NSView.boundsDidChangeNotification, @@ -601,7 +592,7 @@ class ParentPanelController: NSWindowController { if let futureSliderCell = futureSlider.cell as? CustomSliderCell, futureSliderCell.tracking == true { return } - if modernSlider.isHidden == false, modernSliderIsScrolling { + if modernSlider.isHidden == false, modernContainerView.currentlyInFocus { return } let dataOperation = TimezoneDataOperations(with: model) diff --git a/Clocker/Panel/Rate Controller/ReviewView.swift b/Clocker/Panel/Rate Controller/ReviewView.swift index 7c0abac..93f953a 100644 --- a/Clocker/Panel/Rate Controller/ReviewView.swift +++ b/Clocker/Panel/Rate Controller/ReviewView.swift @@ -33,3 +33,30 @@ class ReviewView: NSView { addTrackingArea(trackingArea) } } + +class ModernSliderContainerView: NSView { + private var trackingArea: NSTrackingArea? + public var currentlyInFocus = false + + override func mouseEntered(with event: NSEvent) { + super.mouseEntered(with: event) + currentlyInFocus = true + } + + override func mouseExited(with event: NSEvent) { + super.mouseExited(with: event) + currentlyInFocus = false + } + + override func updateTrackingAreas() { + super.updateTrackingAreas() + + if let trackingArea = self.trackingArea { + removeTrackingArea(trackingArea) + } + + let options: NSTrackingArea.Options = [.mouseEnteredAndExited, .activeAlways] + let trackingArea = NSTrackingArea(rect: bounds, options: options, owner: self, userInfo: nil) + addTrackingArea(trackingArea) + } +}