added 2 new arrays to accept color changes on each carousel page
Signed-off-by: Jarrod Courtney <jarrod.courtney@verizon.com>
This commit is contained in:
parent
4f1f36186c
commit
ec584feae8
@ -104,6 +104,14 @@ open class BarsIndicatorView: CarouselIndicator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override var indicatorColors: [Color]? {
|
||||||
|
get { super.indicatorColors }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override var currentIndicatorColors: [Color]? {
|
||||||
|
get { super.currentIndicatorColors }
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Setup
|
// MARK: - Setup
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -250,6 +258,10 @@ open class BarsIndicatorView: CarouselIndicator {
|
|||||||
|
|
||||||
guard newIndex < totalCount else { return }
|
guard newIndex < totalCount else { return }
|
||||||
|
|
||||||
|
if let indicatorColors = indicatorColors, let currentIndicatorColors = currentIndicatorColors {
|
||||||
|
indicatorColor = indicatorColors[newIndex].uiColor
|
||||||
|
currentIndicatorColor = currentIndicatorColors[newIndex].uiColor
|
||||||
|
}
|
||||||
// Ensure the number of pages matches the number of bar references.
|
// Ensure the number of pages matches the number of bar references.
|
||||||
if (totalCount - barReferences.count) != 0 {
|
if (totalCount - barReferences.count) != 0 {
|
||||||
barReferences.forEach {
|
barReferences.forEach {
|
||||||
@ -263,9 +275,9 @@ open class BarsIndicatorView: CarouselIndicator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
barReferences[previousIndex].backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor
|
barReferences[previousIndex].backgroundColor = isEnabled ? indicatorColor : disabledIndicatorColor
|
||||||
|
barReferences[newIndex].backgroundColor = isEnabled ? currentIndicatorColor : disabledIndicatorColor
|
||||||
barReferences[previousIndex].constraint?.constant = IndicatorBar.unselectedHeight
|
barReferences[previousIndex].constraint?.constant = IndicatorBar.unselectedHeight
|
||||||
barReferences[previousIndex].layer.cornerRadius = IndicatorBar.unselectedCornerRadius
|
barReferences[previousIndex].layer.cornerRadius = IndicatorBar.unselectedCornerRadius
|
||||||
barReferences[newIndex].backgroundColor = isEnabled ? currentIndicatorColor : disabledIndicatorColor
|
|
||||||
barReferences[newIndex].constraint?.constant = IndicatorBar.selectedHeight
|
barReferences[newIndex].constraint?.constant = IndicatorBar.selectedHeight
|
||||||
barReferences[newIndex].layer.cornerRadius = IndicatorBar.selectedCornerRadius
|
barReferences[newIndex].layer.cornerRadius = IndicatorBar.selectedCornerRadius
|
||||||
layoutIfNeeded()
|
layoutIfNeeded()
|
||||||
|
|||||||
@ -98,6 +98,20 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var indicatorColors: [Color]? {
|
||||||
|
get {
|
||||||
|
guard let model = carouselIndicatorModel else { return nil }
|
||||||
|
return model.indicatorColors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public var currentIndicatorColors: [Color]? {
|
||||||
|
get {
|
||||||
|
guard let model = carouselIndicatorModel else { return nil }
|
||||||
|
return model.currentIndicatorColors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var accessibilityValueFormat: String? {
|
var accessibilityValueFormat: String? {
|
||||||
MVMCoreUIUtility.hardcodedString(withKey: (carouselIndicatorModel?.accessibilityHasSlidesInsteadOfPage ?? false) ? "MVMCoreUIPageControlslides_currentpage_index" : "MVMCoreUIPageControl_currentpage_index")
|
MVMCoreUIUtility.hardcodedString(withKey: (carouselIndicatorModel?.accessibilityHasSlidesInsteadOfPage ?? false) ? "MVMCoreUIPageControlslides_currentpage_index" : "MVMCoreUIPageControl_currentpage_index")
|
||||||
}
|
}
|
||||||
@ -210,11 +224,15 @@ open class CarouselIndicator: Control, CarouselPageControlProtocol {
|
|||||||
guard let model = model as? CarouselIndicatorModel else { return }
|
guard let model = model as? CarouselIndicatorModel else { return }
|
||||||
|
|
||||||
previousIndex = 0
|
previousIndex = 0
|
||||||
indicatorColor = model.inverted ? model.indicatorColor_inverted.uiColor : model.indicatorColor.uiColor
|
|
||||||
disabledIndicatorColor = model.disabledIndicatorColor.uiColor
|
|
||||||
currentIndex = model.currentIndex
|
currentIndex = model.currentIndex
|
||||||
isEnabled = model.enabled
|
isEnabled = model.enabled
|
||||||
|
|
||||||
|
if let indicatorColors = model.indicatorColors {
|
||||||
|
indicatorColor = indicatorColors[currentIndex].uiColor
|
||||||
|
}
|
||||||
|
indicatorColor = model.inverted ? model.indicatorColor_inverted.uiColor : model.indicatorColor.uiColor
|
||||||
|
disabledIndicatorColor = model.disabledIndicatorColor.uiColor
|
||||||
|
|
||||||
formatAccessibilityValue(index: currentIndex + 1, total: numberOfPages)
|
formatAccessibilityValue(index: currentIndex + 1, total: numberOfPages)
|
||||||
isHidden = model.hidesForSinglePage && numberOfPages <= 1
|
isHidden = model.hidesForSinglePage && numberOfPages <= 1
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,8 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
|
|||||||
public var indicatorColor: Color = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
public var indicatorColor: Color = Color(uiColor: VDSColor.elementsPrimaryOnlight)
|
||||||
public var indicatorColor_inverted: Color = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
public var indicatorColor_inverted: Color = Color(uiColor: VDSColor.elementsPrimaryOndark)
|
||||||
public var position: CGFloat?
|
public var position: CGFloat?
|
||||||
|
public var indicatorColors: [Color]? = nil
|
||||||
|
public var currentIndicatorColors: [Color]? = nil
|
||||||
|
|
||||||
/// Allows sendActions() to trigger even if index is already at min/max index.
|
/// Allows sendActions() to trigger even if index is already at min/max index.
|
||||||
public var alwaysSendAction = false
|
public var alwaysSendAction = false
|
||||||
@ -62,6 +64,8 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
|
|||||||
case indicatorColor
|
case indicatorColor
|
||||||
case position
|
case position
|
||||||
case inverted
|
case inverted
|
||||||
|
case indicatorColors
|
||||||
|
case currentIndicatorColors
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -76,6 +80,14 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
|
|||||||
moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName)
|
moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName)
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
|
|
||||||
|
if let colors = try typeContainer.decodeIfPresent([Color].self, forKey: .indicatorColors) {
|
||||||
|
self.indicatorColors = colors
|
||||||
|
}
|
||||||
|
|
||||||
|
if let currentColors = try typeContainer.decodeIfPresent([Color].self, forKey: .currentIndicatorColors) {
|
||||||
|
self.currentIndicatorColors = currentColors
|
||||||
|
}
|
||||||
|
|
||||||
if let currentIndex = try typeContainer.decodeIfPresent(Int.self, forKey: .currentIndex) {
|
if let currentIndex = try typeContainer.decodeIfPresent(Int.self, forKey: .currentIndex) {
|
||||||
self.currentIndex = currentIndex
|
self.currentIndex = currentIndex
|
||||||
}
|
}
|
||||||
@ -133,6 +145,8 @@ open class CarouselIndicatorModel: CarouselPagingModelProtocol, MoleculeModelPro
|
|||||||
try container.encode(disabledIndicatorColor, forKey: .disabledIndicatorColor)
|
try container.encode(disabledIndicatorColor, forKey: .disabledIndicatorColor)
|
||||||
try container.encode(indicatorColor, forKey: .indicatorColor)
|
try container.encode(indicatorColor, forKey: .indicatorColor)
|
||||||
try container.encodeIfPresent(position, forKey: .position)
|
try container.encodeIfPresent(position, forKey: .position)
|
||||||
|
try container.encode(indicatorColors, forKey: .indicatorColors)
|
||||||
|
try container.encode(currentIndicatorColors, forKey: .currentIndicatorColors)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func isEqual(to model: any ModelComparisonProtocol) -> Bool {
|
public func isEqual(to model: any ModelComparisonProtocol) -> Bool {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user