From 4d42f4374ea2c05dae563d10040e71721a871cb0 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sun, 31 Mar 2024 13:49:19 -0400 Subject: [PATCH] Two changes - Animate forwards / backwards button alpha value when we are scrolling the modern slider - Get rid of minutes in the time scroller text when the minutes == 0 (to show +03h instead of +03:00h) --- Clocker/Panel/PanelController.swift | 2 ++ .../ParentPanelController+ModernSlider.swift | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Clocker/Panel/PanelController.swift b/Clocker/Panel/PanelController.swift index f34c64c..1525785 100644 --- a/Clocker/Panel/PanelController.swift +++ b/Clocker/Panel/PanelController.swift @@ -95,6 +95,8 @@ class PanelController: ParentPanelController { sliderDatePicker.dateValue = Date() closestQuarterTimeRepresentation = findClosestQuarterTimeApproximation() modernSliderLabel.stringValue = "Time Scroller" + goForwardButton.alphaValue = 0 + goBackwardsButton.alphaValue = 0 resetModernSliderButton.isHidden = true if modernSlider != nil { diff --git a/Clocker/Panel/ParentPanelController+ModernSlider.swift b/Clocker/Panel/ParentPanelController+ModernSlider.swift index 1640e68..cda2dff 100644 --- a/Clocker/Panel/ParentPanelController+ModernSlider.swift +++ b/Clocker/Panel/ParentPanelController+ModernSlider.swift @@ -80,14 +80,30 @@ extension ParentPanelController { strongSelf.resetModernSliderButton.animator().isHidden = hidden }) } + + private func showAccessoryButtonsIfNeccesary(_ hide: Bool) { + NSAnimationContext.runAnimationGroup({ context in + context.duration = 0.5 + context.timingFunction = CAMediaTimingFunction(name: hide ? CAMediaTimingFunctionName.easeOut : CAMediaTimingFunctionName.easeIn) + goForwardButton.animator().alphaValue = hide ? 0.0 : 1.0 + goBackwardsButton.animator().alphaValue = hide ? 0.0 : 1.0 + }, completionHandler: nil) + } @IBAction func resetModernSlider(_: NSButton) { closestQuarterTimeRepresentation = findClosestQuarterTimeApproximation() modernSliderLabel.stringValue = "Time Scroller" - animateButton(true) if modernSlider != nil { let indexPaths: Set = Set([IndexPath(item: modernSlider.numberOfItems(inSection: 0) / 2, section: 0)]) - modernSlider.scrollToItems(at: indexPaths, scrollPosition: .centeredHorizontally) + NSAnimationContext.runAnimationGroup({ context in + context.duration = 0.5 + context.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn) + modernSlider.animator().scrollToItems(at: indexPaths, scrollPosition: .centeredHorizontally) + }, completionHandler: { [weak self] in + guard let strongSelf = self else { return } + strongSelf.animateButton(true) + strongSelf.showAccessoryButtonsIfNeccesary(true) + }) } } @@ -112,6 +128,7 @@ extension ParentPanelController { let newPoint = NSPoint(x: changedOrigin.x + contentView.frame.width / 2, y: changedOrigin.y) let indexPath = modernSlider.indexPathForItem(at: newPoint) if let correctIndexPath = indexPath?.item, currentCenterIndexPath != correctIndexPath { + showAccessoryButtonsIfNeccesary(false) currentCenterIndexPath = correctIndexPath let minutesToAdd = setDefaultDateLabel(correctIndexPath) setTimezoneDatasourceSlider(sliderValue: minutesToAdd) @@ -146,7 +163,7 @@ extension ParentPanelController { let remainder = (index % (centerPoint + 1)) let nextDate = Calendar.current.date(byAdding: .minute, value: remainder * 15, to: closestQuarterTimeRepresentation ?? Date())! let minutes = minutesToHoursAndMinutes(remainder * 15) - modernSliderLabel.stringValue = "+\(minutes.hours):\(minutes.leftMinutes)h" + modernSliderLabel.stringValue = minutes.leftMinutes != 0 ? "+\(minutes.hours):\(minutes.leftMinutes)h" : "+\(minutes.hours)h" if resetModernSliderButton.isHidden { animateButton(false) } @@ -157,7 +174,7 @@ extension ParentPanelController { let previousDate = Calendar.current.date(byAdding: .minute, value: -1 * remainder * 15, to: closestQuarterTimeRepresentation ?? Date())! modernSliderLabel.stringValue = timezoneFormattedStringRepresentation(previousDate) let minutes = minutesToHoursAndMinutes(-1 * remainder * 15) - modernSliderLabel.stringValue = "\(minutes.hours):\(minutes.leftMinutes)h" + modernSliderLabel.stringValue = minutes.leftMinutes != 0 ? "\(minutes.hours):\(minutes.leftMinutes)h" : "\(minutes.hours)h" if resetModernSliderButton.isHidden { animateButton(false) }