Digital ACT-191 ONEAPP-6830 story: did set color configurations and removed unused code

This commit is contained in:
vasavk 2024-03-20 23:14:04 +05:30
parent eb3d6b7a34
commit 11618e88a0

View File

@ -31,28 +31,9 @@ open class CarouselScrollbar: View {
super.init(coder: coder) super.init(coder: coder)
} }
/// TO Do: take three view containers with fixed sizes - track view, active track view, thumb view.
/// add pan gesture to background container
/// set variable width to thumb container based on inputs. add pan gesture to track.
/// Not applicable to touch or keyboard devices - set width to 8 for three views if is in active state
/// scrollbar track only changes color on the side of the scrollbar that was interacted with. Track color changes will apply to whatever state the scrollbar is in before becoming active. if hovered via mouse, the scrollbar height will be increased when active. For touch or keyboard devices, the scrollbar will be the same size as the default state when the active track color change is applied.
/// <CarouselScrollbar
// surface="light"
// numberOfSlides={12}
// layout="3UP"
// position={0}
// />
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Public Properties // MARK: - Public Properties
//-------------------------------------------------- //--------------------------------------------------
// Sizes are from InVision design specs.
internal var containerSize: CGSize { CGSize(width: 45, height: 44) }
// TO DO: to be remove
// open var numberOfSlides: Int? { didSet { setNeedsUpdate() } }
/// Used to set total number of slides within carousel /// Used to set total number of slides within carousel
open var numberOfSlides: Int? { open var numberOfSlides: Int? {
get { return _numberOfSlides } get { return _numberOfSlides }
@ -121,37 +102,23 @@ open class CarouselScrollbar: View {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
// Sizes are from InVision design specs.
internal var containerSize: CGSize { CGSize(width: 45, height: 44) }
private let trackViewWidth = 96 private let trackViewWidth = 96
private let trackViewHeight: CGFloat = 4 private let trackViewHeight: CGFloat = 4
private let minThumbWidth: Float = 16.0 private let minThumbWidth: Float = 16.0
private var thumbWidth: Float = 16.0 private var thumbWidth: Float = 16.0
private var actualThumbWidth: Float = 0.0 private var actualThumbWidth: Float = 0.0
private var _selectedLayout: Layout = .oneUP private var _selectedLayout: Layout = .oneUP
private var _numberOfSlides: Int? = 1 private var _numberOfSlides: Int? = 1
internal var cornerRadius: CGFloat = 4.0 internal var cornerRadius: CGFloat = 4.0
internal var leftOverlayWidth: NSLayoutConstraint?
internal var rightOverlayXPos: NSLayoutConstraint?
internal var rightOverlayTrailingConstraint: NSLayoutConstraint?
internal var heightConstraint: NSLayoutConstraint? internal var heightConstraint: NSLayoutConstraint?
internal var containerView: UIView = {
return UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
}()
/// Track view with fixed width /// Track view with fixed width
internal var trackView: UIView = { internal var trackView: UIView = {
return UIView().with { return UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
// $0.tag = 1
} }
}() }()
@ -175,10 +142,16 @@ open class CarouselScrollbar: View {
internal var thumbView: UIView = { internal var thumbView: UIView = {
return UIView().with { return UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
// $0.tag = 4
} }
}() }()
//--------------------------------------------------
// MARK: - Configuration
//--------------------------------------------------
private var thumbColorConfiguration = SurfaceColorConfiguration(VDSColor.interactiveScrollthumbOnlight , VDSColor.interactiveScrollthumbOndark)
private var trackColorConfiguration = SurfaceColorConfiguration(VDSColor.interactiveScrolltrackOnlight , VDSColor.interactiveScrolltrackOndark)
private var activeOverlayColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteWhite)
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
//-------------------------------------------------- //--------------------------------------------------
@ -197,23 +170,18 @@ open class CarouselScrollbar: View {
//Trackview //Trackview
trackView.frame = CGRectMake(20, 20, CGFloat(trackViewWidth), trackViewHeight) trackView.frame = CGRectMake(20, 20, CGFloat(trackViewWidth), trackViewHeight)
// trackView.backgroundColor = .blue
// trackView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:))))
// trackView.isUserInteractionEnabled = true
trackView.layer.cornerRadius = cornerRadius trackView.layer.cornerRadius = cornerRadius
addSubview(trackView) addSubview(trackView)
///Left active overlay width variable depends on thumb position ///Left active overlay
leftActiveOverlay.frame = CGRectMake(trackView.frame.origin.x, 20, CGFloat(trackViewWidth), trackViewHeight) leftActiveOverlay.frame = CGRectMake(trackView.frame.origin.x, 20, CGFloat(trackViewWidth), trackViewHeight)
// leftActiveOverlay.backgroundColor = .yellow
leftActiveOverlay.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))) leftActiveOverlay.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:))))
leftActiveOverlay.isUserInteractionEnabled = true leftActiveOverlay.isUserInteractionEnabled = true
leftActiveOverlay.layer.cornerRadius = cornerRadius leftActiveOverlay.layer.cornerRadius = cornerRadius
addSubview(leftActiveOverlay) addSubview(leftActiveOverlay)
///Right active overlay width variable depends on thumbView position & trailing positon of trackView ///Right active overlay
rightActiveOverlay.frame = CGRectMake(thumbView.frame.origin.x + thumbView.frame.size.width, 20, CGFloat(trackViewWidth), trackViewHeight) rightActiveOverlay.frame = CGRectMake(thumbView.frame.origin.x + thumbView.frame.size.width, 20, CGFloat(trackViewWidth), trackViewHeight)
// rightActiveOverlay.backgroundColor = .orange
rightActiveOverlay.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))) rightActiveOverlay.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:))))
rightActiveOverlay.isUserInteractionEnabled = true rightActiveOverlay.isUserInteractionEnabled = true
rightActiveOverlay.layer.cornerRadius = cornerRadius rightActiveOverlay.layer.cornerRadius = cornerRadius
@ -221,25 +189,16 @@ open class CarouselScrollbar: View {
//Thumbview //Thumbview
thumbView.frame = CGRectMake(20, 20, CGFloat(thumbWidth), trackViewHeight) thumbView.frame = CGRectMake(20, 20, CGFloat(thumbWidth), trackViewHeight)
// thumbView.backgroundColor = .green
thumbView.layer.cornerRadius = cornerRadius thumbView.layer.cornerRadius = cornerRadius
// thumbView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:))))
// thumbView.isUserInteractionEnabled = true
thumbView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action:(#selector(self.handleGesture(_:))))) thumbView.addGestureRecognizer(UIPanGestureRecognizer(target: self, action:(#selector(self.handleGesture(_:)))))
addSubview(thumbView) addSubview(thumbView)
updateFrames() updateFrames()
} }
open override func updateView() { open override func updateView() {
super.updateView() super.updateView()
// updateFrames() trackView.backgroundColor = trackColorConfiguration.getColor(surface)
//left active overlay origin - x, width thumbView.backgroundColor = thumbColorConfiguration.getColor(surface)
// leftActiveOverlay.leadingAnchor.constraint(equalTo: trackView.leadingAnchor).activate()
// leftActiveOverlay.trailingAnchor.constraint(equalTo: thumbView.leadingAnchor).activate()
//right active overlay origin - x, width, trailing position exact to trackView
// rightActiveOverlay.leadingAnchor.constraint(equalTo: thumbView.trailingAnchor).activate()
// rightActiveOverlay.trailingAnchor.constraint(equalTo: trackView.trailingAnchor).activate()
} }
open override func updateAccessibility() { open override func updateAccessibility() {
@ -255,33 +214,22 @@ open class CarouselScrollbar: View {
super.reset() super.reset()
} }
// open override func layoutSubviews() {
// super.layoutSubviews()
// setNeedsUpdate()
// }
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Methods // MARK: - Private Methods
//-------------------------------------------------- //--------------------------------------------------
@objc func handleTap(_ gestureRecognizer: UITapGestureRecognizer) { @objc func handleTap(_ gestureRecognizer: UITapGestureRecognizer) {
// handling code // handling code
let tag = gestureRecognizer.view?.tag let tag = gestureRecognizer.view?.tag
switch tag! { switch tag! {
// case 1 : case 2 :
// print("select first view") thumbView.frame.origin.x = thumbView.frame.origin.x - CGFloat(actualThumbWidth)
case 2 : updateFrames()
thumbView.frame.origin.x = thumbView.frame.origin.x - CGFloat(actualThumbWidth) case 3 :
updateFrames() thumbView.frame.origin.x = thumbView.frame.origin.x + CGFloat(actualThumbWidth)
// print("select second view") updateFrames()
case 3 : default:
thumbView.frame.origin.x = thumbView.frame.origin.x + CGFloat(actualThumbWidth) print("default")
updateFrames() }
// print("select third view")
// case 4 :
// print("select fourth view")
default:
print("default")
}
} }
@objc func handleGesture(_ sender: UIPanGestureRecognizer) { @objc func handleGesture(_ sender: UIPanGestureRecognizer) {
@ -306,46 +254,18 @@ open class CarouselScrollbar: View {
private func setThumbWidth() { private func setThumbWidth() {
let width = Float (trackViewWidth / (numberOfSlides ?? 1) * _selectedLayout.value) let width = Float (trackViewWidth / (numberOfSlides ?? 1) * _selectedLayout.value)
actualThumbWidth = width actualThumbWidth = (width > Float(trackViewWidth)) ? Float(trackViewWidth) : width
thumbWidth = width < minThumbWidth ? minThumbWidth : width thumbWidth = (width < Float(trackViewWidth) && width > minThumbWidth) ? width : ((width > Float(trackViewWidth)) ? Float(trackViewWidth) : minThumbWidth)
thumbView.frame.size.width = CGFloat(thumbWidth) thumbView.frame.size.width = CGFloat(thumbWidth)
thumbView.frame.origin.x = trackView.frame.origin.x thumbView.frame.origin.x = trackView.frame.origin.x
// print("trackViewWidth: \(trackViewWidth), numberOfSlides: \(String(describing: numberOfSlides)), tiles per set: \(_selectedLayout.value), actualThumbWidth: \(actualThumbWidth), thumbWidth: \(thumbWidth)")
//carousel position also to be update accordingly
updateFrames() updateFrames()
} }
//Known bug: when actual width is less than minimum width
// private func updateThumbFrame() {
//
// //right active overlay origin - x, width, trailing position exact to trackView
// // adjusting thumb position if it goes beyond trackView.
// let position1 = thumbView.frame.origin.x + thumbView.frame.size.width
// let position2 = trackView.frame.origin.x + trackView.frame.size.width
// if position1 > position2 {
// thumbView.frame.origin.x = position2 - thumbView.frame.size.width
// } else if thumbView.frame.origin.x < 0 {
// thumbView.frame.origin.x = trackView.frame.origin.x
// } else {
// rightActiveOverlay.frame.origin.x = position1
// rightActiveOverlay.frame.size.width = position2 - position1
// }
// DispatchQueue.main.asyncAfter(deadline: .now() + 2 , execute: {
// //left active overlay origin - x, width
// self.updateOverlay()
// })
// }
//
// private func updateOverlay() {
// //left active overlay origin - x, width
// leftActiveOverlay.frame.size.width = thumbView.frame.origin.x - trackView.frame.origin.x
// }
//
private func updateFrames() { private func updateFrames() {
//left active overlay origin - x, width //left active overlay origin - x, width
leftActiveOverlay.frame.size.width = thumbView.frame.origin.x - trackView.frame.origin.x leftActiveOverlay.frame.size.width = thumbView.frame.origin.x - trackView.frame.origin.x
//right active overlay origin - x, width, trailing position exact to trackView //right active overlay origin - x, width
let position1 = thumbView.frame.origin.x + thumbView.frame.size.width let position1 = thumbView.frame.origin.x + thumbView.frame.size.width
let position2 = trackView.frame.origin.x + trackView.frame.size.width let position2 = trackView.frame.origin.x + trackView.frame.size.width
rightActiveOverlay.frame.origin.x = position1 rightActiveOverlay.frame.origin.x = position1
@ -353,29 +273,3 @@ open class CarouselScrollbar: View {
} }
} }
//private func updateFrames() {
// //right active overlay origin - x, width, trailing position exact to trackView
// let position1 = thumbView.frame.origin.x + thumbView.frame.size.width
// let position2 = trackView.frame.origin.x + trackView.frame.size.width
// rightActiveOverlay.frame.origin.x = position1
// rightActiveOverlay.frame.size.width = position2 - position1
////right active overlay origin - x, width, trailing position exact to trackView
//// adjusting thumb position if it goes beyond trackView.
//let position1 = thumbView.frame.origin.x + thumbView.frame.size.width
//let position2 = trackView.frame.origin.x + trackView.frame.size.width
//if position1 > position2 {
// thumbView.frame.origin.x = position2 - thumbView.frame.size.width
//} else if thumbView.frame.origin.x < 0 {
// thumbView.frame.origin.x = trackView.frame.origin.x
//} else {
// rightActiveOverlay.frame.origin.x = position1
// rightActiveOverlay.frame.size.width = position2 - position1
//}