Digital ACT-191 ONEAPP-6830 story: Interaction type: Drag scrollbar thumb
This commit is contained in:
parent
f7ef52251b
commit
51a00f9b68
@ -44,7 +44,7 @@ open class CarouselScrollbar: View {
|
|||||||
_numberOfSlides = 1
|
_numberOfSlides = 1
|
||||||
}
|
}
|
||||||
setThumbWidth()
|
setThumbWidth()
|
||||||
setThumb(position)
|
scrollThumbToPosition(position)
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ open class CarouselScrollbar: View {
|
|||||||
_selectedLayout = .oneUP
|
_selectedLayout = .oneUP
|
||||||
}
|
}
|
||||||
setThumbWidth()
|
setThumbWidth()
|
||||||
setThumb(position)
|
scrollThumbToPosition(position)
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ open class CarouselScrollbar: View {
|
|||||||
} else {
|
} else {
|
||||||
_position = 1
|
_position = 1
|
||||||
}
|
}
|
||||||
setThumb(position)
|
scrollThumbToPosition(position)
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,6 +123,7 @@ open class CarouselScrollbar: View {
|
|||||||
internal var heightConstraint: NSLayoutConstraint?
|
internal var heightConstraint: NSLayoutConstraint?
|
||||||
internal var totalPositions: Int? = 1
|
internal var totalPositions: Int? = 1
|
||||||
internal var _position: Int? = 1
|
internal var _position: Int? = 1
|
||||||
|
internal var trayOriginalCenter: CGPoint!
|
||||||
|
|
||||||
private let trackViewWidth = 96
|
private let trackViewWidth = 96
|
||||||
private let trackViewHeight: CGFloat = 4
|
private let trackViewHeight: CGFloat = 4
|
||||||
@ -212,7 +213,7 @@ open class CarouselScrollbar: View {
|
|||||||
//Thumbview
|
//Thumbview
|
||||||
thumbView.frame = CGRectMake(20, 20, CGFloat(thumbWidth), trackViewHeight)
|
thumbView.frame = CGRectMake(20, 20, CGFloat(thumbWidth), trackViewHeight)
|
||||||
thumbView.layer.cornerRadius = cornerRadius
|
thumbView.layer.cornerRadius = cornerRadius
|
||||||
thumbView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action:(#selector(self.handleGesture(_:)))))
|
thumbView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action:(#selector(self.onScrubberDrag(_:)))))
|
||||||
addSubview(thumbView)
|
addSubview(thumbView)
|
||||||
updateActiveOverlays()
|
updateActiveOverlays()
|
||||||
}
|
}
|
||||||
@ -249,23 +250,17 @@ open class CarouselScrollbar: View {
|
|||||||
updateActiveOverlays()
|
updateActiveOverlays()
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func handleGesture(_ sender: UIPanGestureRecognizer) {
|
@objc func onScrubberDrag(_ sender: UIPanGestureRecognizer) {
|
||||||
|
let translation = sender.translation(in: thumbView)
|
||||||
switch sender.state {
|
if sender.state == UIGestureRecognizer.State.began {
|
||||||
case .began:
|
trayOriginalCenter = thumbView.center
|
||||||
print("began")
|
} else if sender.state == UIGestureRecognizer.State.changed {
|
||||||
break
|
let movePositions = Int (ceil (Double(translation.x) / Double(actualThumbWidth)))
|
||||||
case .changed:
|
setThumb(at: (position ?? 1) + movePositions)
|
||||||
print("changed")
|
}
|
||||||
break
|
else if sender.state == UIGestureRecognizer.State.cancelled || sender.state == UIGestureRecognizer.State.ended {
|
||||||
case .cancelled:
|
let movePositions = Int (ceil (Double(translation.x) / Double(actualThumbWidth)))
|
||||||
print("cancelled")
|
position = (position ?? 1) + movePositions
|
||||||
break
|
|
||||||
case .ended:
|
|
||||||
print("ended")
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,8 +327,14 @@ open class CarouselScrollbar: View {
|
|||||||
private func checkPositions() {
|
private func checkPositions() {
|
||||||
totalPositions = Int (ceil (Double(numberOfSlides ?? 1) / Double(_selectedLayout.value)))
|
totalPositions = Int (ceil (Double(numberOfSlides ?? 1) / Double(_selectedLayout.value)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func scrollThumbToPosition(_ position: Int?) {
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) { [weak self] in
|
||||||
|
self?.setThumb(at: position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func setThumb(_ position: Int?) {
|
private func setThumb(at position: Int?) {
|
||||||
thumbView.frame.origin.x = CGFloat(Float((position ?? 1) - 1) * actualThumbWidth) + trackView.frame.origin.x
|
thumbView.frame.origin.x = CGFloat(Float((position ?? 1) - 1) * actualThumbWidth) + trackView.frame.origin.x
|
||||||
updateActiveOverlays()
|
updateActiveOverlays()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user