@@ -6,6 +6,8 @@ public final class MessageViewController: UIViewController {
66 public var regularTintColor : UIColor = . black
77 // Image tint color for `.notFound` state.
88 public var errorTintColor : UIColor = . red
9+ // Customizable state messages.
10+ public var messages = StateMessageProvider ( )
911
1012 // MARK: - UI properties
1113
@@ -23,9 +25,9 @@ public final class MessageViewController: UIViewController {
2325 // Constraints that are activated when the view is used for loading animation and error messages.
2426 private lazy var expandedConstraints : [ NSLayoutConstraint ] = self . makeExpandedConstraints ( )
2527
26- var state : State = . scanning {
28+ var status = Status ( state : . scanning) {
2729 didSet {
28- handleStateUpdate ( )
30+ handleStatusUpdate ( )
2931 }
3032 }
3133
@@ -36,7 +38,7 @@ public final class MessageViewController: UIViewController {
3638 view. addSubview ( blurView)
3739 blurView. contentView. addSubviews ( textLabel, imageView, borderView)
3840 setupSubviews ( )
39- handleStateUpdate ( )
41+ handleStatusUpdate ( )
4042 }
4143
4244 public override func viewDidLayoutSubviews( ) {
@@ -58,7 +60,7 @@ public final class MessageViewController: UIViewController {
5860 - Parameter style: The current blur style.
5961 */
6062 private func animate( blurStyle: UIBlurEffectStyle ) {
61- guard state == . processing else { return }
63+ guard status . state == . processing else { return }
6264
6365 UIView . animate (
6466 withDuration: 2.0 ,
@@ -78,7 +80,7 @@ public final class MessageViewController: UIViewController {
7880 - Parameter angle: Rotation angle.
7981 */
8082 private func animate( borderViewAngle: CGFloat ) {
81- guard state == . processing else {
83+ guard status . state == . processing else {
8284 borderView. transform = . identity
8385 return
8486 }
@@ -117,12 +119,12 @@ public final class MessageViewController: UIViewController {
117119
118120 // MARK: - State handling
119121
120- private func handleStateUpdate ( ) {
122+ private func handleStatusUpdate ( ) {
121123 borderView. isHidden = true
122124 borderView. layer. removeAllAnimations ( )
123- textLabel. text = state . text
125+ textLabel. text = status . text ?? messages . makeText ( for : status . state )
124126
125- switch state {
127+ switch status . state {
126128 case . scanning, . unauthorized:
127129 textLabel. font = UIFont . boldSystemFont ( ofSize: 14 )
128130 textLabel. numberOfLines = 3
@@ -141,7 +143,7 @@ public final class MessageViewController: UIViewController {
141143 imageView. tintColor = errorTintColor
142144 }
143145
144- if state == . scanning || state == . unauthorized {
146+ if status . state == . scanning || status . state == . unauthorized {
145147 expandedConstraints. deactivate ( )
146148 collapsedConstraints. activate ( )
147149 } else {
0 commit comments