From ad345dacd81f7d941449b0070e76bf4221ebbddc Mon Sep 17 00:00:00 2001 From: Lekshmi S Date: Tue, 6 Oct 2020 13:06:31 +0530 Subject: [PATCH] Code changes as per review comments. --- MVMCoreUI/Atomic/Atoms/Views/Star.swift | 1 - MVMCoreUI/Atomic/Atoms/Views/Stars.swift | 17 ++++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Star.swift b/MVMCoreUI/Atomic/Atoms/Views/Star.swift index 2c532f46..6e712053 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Star.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Star.swift @@ -104,7 +104,6 @@ import Foundation } func setFrame(with size: CGFloat) { - progressBar.frame = CGRect(x: 0, y: 0, width: size, height: size) widthConstraint?.constant = size setNeedsDisplay() } diff --git a/MVMCoreUI/Atomic/Atoms/Views/Stars.swift b/MVMCoreUI/Atomic/Atoms/Views/Stars.swift index d7dba177..90a8e43a 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Stars.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Stars.swift @@ -18,6 +18,7 @@ open class Stars: View { } private var delegateObject: MVMCoreUIDelegateObject? private let itemSpacing: CGFloat = 3.0 + private var heightConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Lifecycle @@ -26,8 +27,9 @@ open class Stars: View { super.setupView() stack.translatesAutoresizingMaskIntoConstraints = false addSubview(stack) - stack.topAnchor.constraint(equalTo: topAnchor).isActive = true - bottomAnchor.constraint(equalTo: stack.bottomAnchor).isActive = true + NSLayoutConstraint.pinView(toSuperview: stack, useMargins: true) + heightConstraint = heightAnchor.constraint(equalToConstant: 30) + heightConstraint?.isActive = true stack.axis = .horizontal stack.spacing = itemSpacing } @@ -48,14 +50,13 @@ open class Stars: View { //------------------------------------------------------ func createStar() { if let starsModel = starsModel { - stack.subviews.forEach({$0.removeFromSuperview()}) let stars = starsModel.stars + let percentRequiredToFillStarFully = CGFloat(100/(starsModel.stars.count)) + let numberOfFilledStars = Int(starsModel.percent/percentRequiredToFillStarFully) for (index, starModel) in stars.enumerated() { let star = Star() //Fill the stars based on percentage. Ex: if there were 4 stars, 75 percent is 3 full stars - let percentRequiredToFillStarFully = CGFloat(100/(starsModel.stars.count)) - let numberOfFilledStars = Int(starsModel.percent/percentRequiredToFillStarFully) if index < numberOfFilledStars { starModel.percent = 100 } else if index == numberOfFilledStars { @@ -77,6 +78,12 @@ open class Stars: View { star.set(with: starModel, delegateObject, nil) stack.addArrangedSubview(star) } + heightConstraint?.constant = starsModel.size } } + + public override func reset() { + super.reset() + stack.subviews.forEach({$0.removeFromSuperview()}) + } }