From 213a063df3737389ebd641eca4fff647b725549e Mon Sep 17 00:00:00 2001 From: Abhishek Date: Mon, 28 Jun 2021 19:28:26 -0500 Subject: [PATCH] Move modern slider function to extension! --- .../ParentPanelController+ModernSlider.swift | 15 +++++++++++++++ Clocker/Panel/ParentPanelController.swift | 13 +------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Clocker/Panel/ParentPanelController+ModernSlider.swift b/Clocker/Panel/ParentPanelController+ModernSlider.swift index 5609c85..7edfa76 100644 --- a/Clocker/Panel/ParentPanelController+ModernSlider.swift +++ b/Clocker/Panel/ParentPanelController+ModernSlider.swift @@ -16,6 +16,21 @@ extension ParentPanelController: NSCollectionViewDataSource { } extension ParentPanelController { + func setupModernSliderIfNeccessary() { + if modernSlider != nil { + modernSlider.enclosingScrollView?.scrollerInsets = NSEdgeInsets(top: 0, left: 0, bottom: 10, right: 0) + modernSlider.enclosingScrollView?.backgroundColor = NSColor.clear + modernSlider.postsBoundsChangedNotifications = true + NotificationCenter.default.addObserver(self, + selector: #selector(collectionViewDidScroll(_:)), + name: NSView.boundsDidChangeNotification, + object: modernSlider.superview) + closestQuarterTimeRepresentation = setModernLabel() + let indexPaths: Set = Set([IndexPath(item: modernSlider.numberOfItems(inSection: 0) / 2, section: 0)]) + modernSlider.scrollToItems(at: indexPaths, scrollPosition: .centeredHorizontally) + } + } + @IBAction func goForward(_: NSButton) { navigateModernSliderToSpecificIndex(1) } diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 3a3305d..ef0929c 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -199,18 +199,7 @@ class ParentPanelController: NSWindowController { mainTableView.style = .fullWidth } - if modernSlider != nil { - modernSlider.enclosingScrollView?.scrollerInsets = NSEdgeInsets(top: 0, left: 0, bottom: 100, right: 0) - modernSlider.enclosingScrollView?.backgroundColor = NSColor.clear - modernSlider.postsBoundsChangedNotifications = true - NotificationCenter.default.addObserver(self, - selector: #selector(collectionViewDidScroll(_:)), - name: NSView.boundsDidChangeNotification, - object: modernSlider.superview) - closestQuarterTimeRepresentation = setModernLabel() - let indexPaths: Set = Set([IndexPath(item: modernSlider.numberOfItems(inSection: 0) / 2, section: 0)]) - modernSlider.scrollToItems(at: indexPaths, scrollPosition: .centeredHorizontally) - } + setupModernSliderIfNeccessary() if roundedDateView != nil { setupRoundedDateView()