feat: update poll tint color

This commit is contained in:
CMK 2022-06-14 13:16:54 +08:00
parent 2dc876a09a
commit 930c175ce3
2 changed files with 38 additions and 35 deletions

View File

@ -27,6 +27,8 @@ extension PollOptionView {
var observations = Set<NSKeyValueObservation>()
public var objects = Set<NSManagedObject>()
let layoutDidUpdate = PassthroughSubject<Void, Never>()
@Published public var userIdentifier: UserIdentifier?
@Published public var style: PollOptionView.Style?
@ -47,7 +49,7 @@ extension PollOptionView {
@Published public var voteState: VoteState = .hidden
@Published public var roundedBackgroundViewColor: UIColor = .clear
@Published public var primaryStripProgressViewTintColor: UIColor = Asset.Colors.brand.color
@Published public var primaryStripProgressViewTintColor: UIColor = Asset.Colors.brand.color.withAlphaComponent(0.8)
@Published public var secondaryStripProgressViewTintColor: UIColor = Asset.Colors.brand.color.withAlphaComponent(0.5)
@Published public var groupedAccessibilityLabel = ""
@ -180,6 +182,39 @@ extension PollOptionView.ViewModel {
}
.store(in: &disposeBag)
Publishers.CombineLatest(
$voteState,
layoutDidUpdate
)
.sink { voteState, _ in
guard case .plain = view.style else { return }
view.layoutIfNeeded()
switch voteState {
case .hidden:
view.optionTextField.textColor = Asset.Colors.Label.primary.color
view.optionTextField.layer.removeShadow()
case .reveal(_, let percentage, _):
if CGFloat(percentage) * view.roundedBackgroundView.frame.width > view.optionLabelMiddlePaddingView.frame.minX {
view.optionTextField.textColor = .white
view.optionTextField.layer.setupShadow(x: 0, y: 0, blur: 4, spread: 0)
} else {
view.optionTextField.textColor = Asset.Colors.Label.primary.color
view.optionTextField.layer.removeShadow()
}
if CGFloat(percentage) * view.roundedBackgroundView.frame.width > view.optionLabelMiddlePaddingView.frame.maxX {
view.optionPercentageLabel.textColor = .white
view.optionPercentageLabel.layer.setupShadow(x: 0, y: 0, blur: 4, spread: 0)
} else {
view.optionPercentageLabel.textColor = Asset.Colors.Label.primary.color
view.optionPercentageLabel.layer.removeShadow()
}
}
}
.store(in: &disposeBag)
bindAccessibility(view: view)
}
@ -196,4 +231,3 @@ extension PollOptionView.ViewModel {
.store(in: &disposeBag)
}
}

View File

@ -203,44 +203,13 @@ extension PollOptionView {
super.layoutSubviews()
updateCornerRadius()
viewModel.layoutDidUpdate.send()
}
public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
// func updateTextAppearance() {
// // guard let voteState = attribute?.voteState else {
// // pollOptionView.optionTextField.textColor = Asset.Colors.Label.primary.color
// // pollOptionView.optionTextField.layer.removeShadow()
// // return
// // }
// //
// // switch voteState {
// // case .hidden:
// // pollOptionView.optionTextField.textColor = Asset.Colors.Label.primary.color
// // pollOptionView.optionTextField.layer.removeShadow()
// // case .reveal(_, let percentage, _):
// // if CGFloat(percentage) * pollOptionView.voteProgressStripView.frame.width > pollOptionView.optionLabelMiddlePaddingView.frame.minX {
// // pollOptionView.optionTextField.textColor = .white
// // pollOptionView.optionTextField.layer.setupShadow(x: 0, y: 0, blur: 4, spread: 0)
// // } else {
// // pollOptionView.optionTextField.textColor = Asset.Colors.Label.primary.color
// // pollOptionView.optionTextField.layer.removeShadow()
// // }
// //
// // if CGFloat(percentage) * pollOptionView.voteProgressStripView.frame.width > pollOptionView.optionLabelMiddlePaddingView.frame.maxX {
// // pollOptionView.optionPercentageLabel.textColor = .white
// // pollOptionView.optionPercentageLabel.layer.setupShadow(x: 0, y: 0, blur: 4, spread: 0)
// // } else {
// // pollOptionView.optionPercentageLabel.textColor = Asset.Colors.Label.primary.color
// // pollOptionView.optionPercentageLabel.layer.removeShadow()
// // }
// // }
// }
}
viewModel.layoutDidUpdate.send()
}
}