@@ -21,11 +21,9 @@ open class DynamicIslandProgressIndicatorViewController: UIViewController {
21
21
22
22
@Clamped ( between: 0 ... 100 ) fileprivate var progress : Double {
23
23
didSet {
24
- precondition ( hasDynamicIsland,
25
- " Cannot show dynamic island progress animation on a device that does not support it! " )
26
- precondition ( !isProgressIndeterminate,
27
- " Cannot set progress manually when isProgressIndeterminate == true! " )
24
+ requiresIndeterminateProgress ( equalTo: false )
28
25
if isProgressIndicatorHidden {
26
+ requiresState ( equalTo: . ready)
29
27
showProgressIndicator ( )
30
28
state = . animating
31
29
}
@@ -52,6 +50,7 @@ open class DynamicIslandProgressIndicatorViewController: UIViewController {
52
50
53
51
/// Provides access to a configuration type to access the progress bar and show/hide progress.
54
52
public lazy var dynamicIslandProgressIndicatorConfiguration : DynamicIslandProgressIndicatorConfiguration = {
53
+ requiresDynamicIsland ( )
55
54
return . init( controller: self )
56
55
} ( )
57
56
@@ -80,17 +79,37 @@ open class DynamicIslandProgressIndicatorViewController: UIViewController {
80
79
open override func viewDidLoad( ) {
81
80
super. viewDidLoad ( )
82
81
83
- createAndAddDynamicIslandBorderLayers ( )
82
+ if hasDynamicIsland {
83
+ createAndAddDynamicIslandBorderLayers ( )
84
+ }
84
85
}
85
86
86
-
87
- fileprivate func showIndeterminateProgressAnimation( ) {
87
+ private func requiresDynamicIsland( ) {
88
88
precondition ( hasDynamicIsland,
89
89
" Cannot show dynamic island progress animation on a device that does not support it! " )
90
- precondition ( isProgressIndeterminate,
91
- " Cannot show indeterminate progress when isProgressIndeterminate == false! " )
92
- precondition ( state == . ready,
93
- " Cannot show animation because progress indicator is already animating! " )
90
+ }
91
+
92
+ private func requiresIndeterminateProgress( equalTo value: Bool ) {
93
+ precondition ( isProgressIndeterminate == value,
94
+ " isProgressIndeterminate must be set to ' \( value) '! " )
95
+ }
96
+
97
+ private func requiresState( equalTo value: State ) {
98
+ let message : String
99
+ switch ( value, state) {
100
+ case ( . ready, . animating) :
101
+ message = " Cannot show animation because progress indicator is already animating! "
102
+ // Handle other cases here if we require them.
103
+ default :
104
+ message = " "
105
+ }
106
+ precondition ( state == value, message)
107
+ }
108
+
109
+
110
+ fileprivate func showIndeterminateProgressAnimation( ) {
111
+ requiresIndeterminateProgress ( equalTo: true )
112
+ requiresState ( equalTo: . ready)
94
113
95
114
resetProgressIndicator ( )
96
115
showProgressIndicator ( )
0 commit comments