Browse Source

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)
master
Abhishek Banthia 9 months ago
parent
commit
4d42f4374e
  1. 2
      Clocker/Panel/PanelController.swift
  2. 25
      Clocker/Panel/ParentPanelController+ModernSlider.swift

2
Clocker/Panel/PanelController.swift

@ -95,6 +95,8 @@ class PanelController: ParentPanelController {
sliderDatePicker.dateValue = Date() sliderDatePicker.dateValue = Date()
closestQuarterTimeRepresentation = findClosestQuarterTimeApproximation() closestQuarterTimeRepresentation = findClosestQuarterTimeApproximation()
modernSliderLabel.stringValue = "Time Scroller" modernSliderLabel.stringValue = "Time Scroller"
goForwardButton.alphaValue = 0
goBackwardsButton.alphaValue = 0
resetModernSliderButton.isHidden = true resetModernSliderButton.isHidden = true
if modernSlider != nil { if modernSlider != nil {

25
Clocker/Panel/ParentPanelController+ModernSlider.swift

@ -81,13 +81,29 @@ extension ParentPanelController {
}) })
} }
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) { @IBAction func resetModernSlider(_: NSButton) {
closestQuarterTimeRepresentation = findClosestQuarterTimeApproximation() closestQuarterTimeRepresentation = findClosestQuarterTimeApproximation()
modernSliderLabel.stringValue = "Time Scroller" modernSliderLabel.stringValue = "Time Scroller"
animateButton(true)
if modernSlider != nil { if modernSlider != nil {
let indexPaths: Set<IndexPath> = Set([IndexPath(item: modernSlider.numberOfItems(inSection: 0) / 2, section: 0)]) let indexPaths: Set<IndexPath> = 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 newPoint = NSPoint(x: changedOrigin.x + contentView.frame.width / 2, y: changedOrigin.y)
let indexPath = modernSlider.indexPathForItem(at: newPoint) let indexPath = modernSlider.indexPathForItem(at: newPoint)
if let correctIndexPath = indexPath?.item, currentCenterIndexPath != correctIndexPath { if let correctIndexPath = indexPath?.item, currentCenterIndexPath != correctIndexPath {
showAccessoryButtonsIfNeccesary(false)
currentCenterIndexPath = correctIndexPath currentCenterIndexPath = correctIndexPath
let minutesToAdd = setDefaultDateLabel(correctIndexPath) let minutesToAdd = setDefaultDateLabel(correctIndexPath)
setTimezoneDatasourceSlider(sliderValue: minutesToAdd) setTimezoneDatasourceSlider(sliderValue: minutesToAdd)
@ -146,7 +163,7 @@ extension ParentPanelController {
let remainder = (index % (centerPoint + 1)) let remainder = (index % (centerPoint + 1))
let nextDate = Calendar.current.date(byAdding: .minute, value: remainder * 15, to: closestQuarterTimeRepresentation ?? Date())! let nextDate = Calendar.current.date(byAdding: .minute, value: remainder * 15, to: closestQuarterTimeRepresentation ?? Date())!
let minutes = minutesToHoursAndMinutes(remainder * 15) 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 { if resetModernSliderButton.isHidden {
animateButton(false) animateButton(false)
} }
@ -157,7 +174,7 @@ extension ParentPanelController {
let previousDate = Calendar.current.date(byAdding: .minute, value: -1 * remainder * 15, to: closestQuarterTimeRepresentation ?? Date())! let previousDate = Calendar.current.date(byAdding: .minute, value: -1 * remainder * 15, to: closestQuarterTimeRepresentation ?? Date())!
modernSliderLabel.stringValue = timezoneFormattedStringRepresentation(previousDate) modernSliderLabel.stringValue = timezoneFormattedStringRepresentation(previousDate)
let minutes = minutesToHoursAndMinutes(-1 * remainder * 15) 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 { if resetModernSliderButton.isHidden {
animateButton(false) animateButton(false)
} }

Loading…
Cancel
Save