From edf1a478f755a5e7e2f74793895fac023b60f7fb Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Fri, 28 Feb 2020 10:16:40 -0500 Subject: [PATCH] adjusting --- .../CarouselIndicator/CarouselIndicator.swift | 4 + .../CarouselIndicatorModel.swift | 85 +++++++++++++------ .../IndicatorViews/BarsIndicatorView.swift | 5 +- MVMCoreUI/Organisms/Carousel.swift | 5 +- 4 files changed, 68 insertions(+), 31 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift index a5e00d84..ecf6089b 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicator.swift @@ -173,6 +173,7 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { get { return _currentIndicatorColor } set (newColor) { _currentIndicatorColor = newColor + carouselIndicatorModel?.currentIndicatorColor = Color(uiColor: newColor) if isBarIndicator() { if let barIndicator = indicatorView as? BarsIndicatorView { @@ -235,6 +236,9 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol { let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeLeft)) let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(swipeRight)) + leftSwipe.direction = .left + rightSwipe.direction = .right + addGestureRecognizer(tap) addGestureRecognizer(leftSwipe) addGestureRecognizer(rightSwipe) diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift index 70c685a1..2e9c6c77 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/CarouselIndicatorModel.swift @@ -14,27 +14,26 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol { // MARK: - Properties //-------------------------------------------------- - public var backgroundColor: Color? - public static var identifier: String { return "carouselIndicator" } + public var backgroundColor: Color? public var moleculeName: String? - public var type: String? = "hybrid" + public var type: String = "hybrid" public var hybridThreshold: Int = 5 public var barsColor: Color? public var currentBarColor: Color? - public var currentIndex: Int? = 0 - public var numberOfPages: Int? = 0 - public var alwaysSendEvent: Bool? = false - public var isAnimated: Bool? = true - public var hidesForSinglePage: Bool? = false - public var accessibilityHasSlidesInsteadOfPage: Bool? = false - public var isEnabled: Bool? = false - public var disabledIndicatorColor: Color? = Color(uiColor: .mvmCoolGray3) - public var indicatorTintColor: Color? = Color(uiColor: .mvmBlack) - public var currentIndicatorColor: Color? = Color(uiColor: .mvmBlack) + public var currentIndex: Int = 0 + public var numberOfPages: Int = 0 + public var alwaysSendEvent: Bool = false + public var isAnimated: Bool = true + public var hidesForSinglePage: Bool = false + public var accessibilityHasSlidesInsteadOfPage: Bool = false + public var isEnabled: Bool = false + public var disabledIndicatorColor: Color = Color(uiColor: .mvmCoolGray3) + public var indicatorTintColor: Color = Color(uiColor: .mvmBlack) + public var currentIndicatorColor: Color = Color(uiColor: .mvmBlack) public var position: Float? //-------------------------------------------------- @@ -70,20 +69,56 @@ public class CarouselIndicatorModel: CarouselPagingModelProtocol { currentBarColor = try typeContainer.decodeIfPresent(Color.self, forKey: .currentBarColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) barsColor = try typeContainer.decodeIfPresent(Color.self, forKey: .barsColor) - type = try typeContainer.decodeIfPresent(String.self, forKey: .type) ?? "hybrid" - hybridThreshold = try typeContainer.decodeIfPresent(Int.self, forKey: .hybridThreshold) ?? 5 barsColor = try typeContainer.decodeIfPresent(Color.self, forKey: .barsColor) currentBarColor = try typeContainer.decodeIfPresent(Color.self, forKey: .currentBarColor) - currentIndex = try typeContainer.decodeIfPresent(Int.self, forKey: .currentIndex) ?? 0 - numberOfPages = try typeContainer.decodeIfPresent(Int.self, forKey: .numberOfPages) ?? 0 - alwaysSendEvent = try typeContainer.decodeIfPresent(Bool.self, forKey: .alwaysSendEvent) ?? false - isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) ?? true - hidesForSinglePage = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidesForSinglePage) ?? false - accessibilityHasSlidesInsteadOfPage = try typeContainer.decodeIfPresent(Bool.self, forKey: .accessibilityHasSlidesInsteadOfPage) ?? false - isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) ?? false - disabledIndicatorColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledIndicatorColor) ?? Color(uiColor: .mvmCoolGray3) - indicatorTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .indicatorTintColor) ?? Color(uiColor: .mvmBlack) - currentIndicatorColor = try typeContainer.decodeIfPresent(Color.self, forKey: .currentIndicatorColor) ?? Color(uiColor: .mvmBlack) + + if let type = try typeContainer.decodeIfPresent(String.self, forKey: .type) { + self.type = type + } + + if let hybridThreshold = try typeContainer.decodeIfPresent(Int.self, forKey: .hybridThreshold) { + self.hybridThreshold = hybridThreshold + } + + if let currentIndex = try typeContainer.decodeIfPresent(Int.self, forKey: .currentIndex) { + self.currentIndex = currentIndex + } + + if let numberOfPages = try typeContainer.decodeIfPresent(Int.self, forKey: .numberOfPages) { + self.numberOfPages = numberOfPages + } + + if let alwaysSendEvent = try typeContainer.decodeIfPresent(Bool.self, forKey: .alwaysSendEvent) { + self.alwaysSendEvent = alwaysSendEvent + } + + if let isAnimated = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAnimated) { + self.isAnimated = isAnimated + } + + if let hidesForSinglePage = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidesForSinglePage) { + self.hidesForSinglePage = hidesForSinglePage + } + + if let accessibilityHasSlidesInsteadOfPage = try typeContainer.decodeIfPresent(Bool.self, forKey: .accessibilityHasSlidesInsteadOfPage) { + self.accessibilityHasSlidesInsteadOfPage = accessibilityHasSlidesInsteadOfPage + } + + if let isEnabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .isEnabled) { + self.isEnabled = isEnabled + } + + if let disabledIndicatorColor = try typeContainer.decodeIfPresent(Color.self, forKey: .disabledIndicatorColor) { + self.disabledIndicatorColor = disabledIndicatorColor + } + + if let indicatorTintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .indicatorTintColor) { + self.indicatorTintColor = indicatorTintColor + } + + if let currentIndicatorColor = try typeContainer.decodeIfPresent(Color.self, forKey: .currentIndicatorColor) { + self.currentIndicatorColor = currentIndicatorColor + } } public func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/BarsIndicatorView.swift b/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/BarsIndicatorView.swift index cd34003a..43e7655d 100644 --- a/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/BarsIndicatorView.swift +++ b/MVMCoreUI/Atoms/Views/CarouselIndicator/IndicatorViews/BarsIndicatorView.swift @@ -69,10 +69,9 @@ open class BarsIndicatorView: View, IndicatorViewProtocol { isUserInteractionEnabled = false heightAnchor.constraint(equalToConstant: 4).isActive = true - stackView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true - stackView.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor).isActive = true - trailingAnchor.constraint(greaterThanOrEqualTo: stackView.trailingAnchor).isActive = true + stackView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true + trailingAnchor.constraint(equalTo: stackView.trailingAnchor).isActive = true } //-------------------------------------------------- diff --git a/MVMCoreUI/Organisms/Carousel.swift b/MVMCoreUI/Organisms/Carousel.swift index b20c1fb3..861642c2 100644 --- a/MVMCoreUI/Organisms/Carousel.swift +++ b/MVMCoreUI/Organisms/Carousel.swift @@ -226,8 +226,9 @@ open class Carousel: View { open func addPaging(view: (UIView & CarouselPageControlProtocol)?, position: CGFloat) { pagingView?.removeFromSuperview() + bottomPin?.isActive = false + guard var pagingView = view else { - bottomPin?.isActive = false bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) bottomPin?.isActive = true return @@ -236,8 +237,6 @@ open class Carousel: View { addSubview(pagingView) pagingView.centerXAnchor.constraint(equalTo: collectionView.centerXAnchor).isActive = true collectionView.bottomAnchor.constraint(equalTo: pagingView.bottomAnchor, constant: position).isActive = true - bottomAnchor.constraint(greaterThanOrEqualTo: pagingView.bottomAnchor).isActive = true - bottomPin?.isActive = false bottomPin = bottomAnchor.constraint(equalTo: collectionView.bottomAnchor) bottomPin?.priority = .defaultLow bottomPin?.isActive = true