From 39a4c5040b2896ef36fbc0bbe66056ac7f56437d Mon Sep 17 00:00:00 2001 From: vasavk Date: Thu, 21 Mar 2024 17:29:10 +0530 Subject: [PATCH] Digital ACT-191 ONEAPP-6830 story: minor changes --- .../CarouselScrollbar/CarouselScrollbar.swift | 55 ++++++++----------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift b/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift index 84c3739f..b0337120 100644 --- a/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift +++ b/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift @@ -135,21 +135,11 @@ open class CarouselScrollbar: View { private let activeOpacity: Float = 0.15 private let defaultOpacity: Float = 1 - internal var containerView = View().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - internal var trackView = View().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - internal var leftActiveOverlay = View().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - internal var rightActiveOverlay = View().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - internal var thumbView = View().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } + internal var containerView = View() + internal var trackView = View() + internal var leftActiveOverlay = View() + internal var rightActiveOverlay = View() + internal var thumbView = View() internal var rightActiveOverlayLayer: CALayer = CALayer() internal var leftActiveOverlayLayer: CALayer = CALayer() @@ -293,6 +283,25 @@ open class CarouselScrollbar: View { rightActiveOverlayLayer.frame = .init(origin: .init(x: 0, y: 20), size: .init(width: rightActiveOverlay.frame.size.width, height: trackViewHeight)) } + private func checkPositions() { + totalPositions = Int (ceil (Double(numberOfSlides ?? 1) / Double(_selectedLayout.value))) + } + + private func scrollThumbToPosition(_ position: Int?) { + setThumb(at: position) + onScrubberDidChange?(position ?? 1) + } + + private func setThumb(at position: Int?) { + UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveLinear, animations: { + self.thumbView.frame.origin.x = CGFloat(Float((position ?? 1) - 1) * self.computedWidth) + self.trackView.frame.origin.x + self.updateActiveOverlays() + }) + } + + //-------------------------------------------------- + // MARK: - Gesture Methods + //-------------------------------------------------- // Drag scrollbar thumb to move it to the left or right. // Upon releases of drag, the scrollbar thumb snaps to the closest full position and the scrollbar returns to original size without delay. @objc func onScrubberDrag(_ sender: UIPanGestureRecognizer) { @@ -344,20 +353,4 @@ open class CarouselScrollbar: View { } }) } - - private func checkPositions() { - totalPositions = Int (ceil (Double(numberOfSlides ?? 1) / Double(_selectedLayout.value))) - } - - private func scrollThumbToPosition(_ position: Int?) { - setThumb(at: position) - onScrubberDidChange?(position ?? 1) - } - - private func setThumb(at position: Int?) { - UIView.animate(withDuration: 0.1, delay: 0.0, options: .curveLinear, animations: { - self.thumbView.frame.origin.x = CGFloat(Float((position ?? 1) - 1) * self.computedWidth) + self.trackView.frame.origin.x - self.updateActiveOverlays() - }) - } }