-
Notifications
You must be signed in to change notification settings - Fork 328
/
JGProgressHUD.h
310 lines (256 loc) · 12.8 KB
/
JGProgressHUD.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
//
// JGProgressHUD.h
// JGProgressHUD
//
// Created by Jonas Gessner on 20.7.14.
// Copyright (c) 2014 Jonas Gessner. All rights reserved.
//
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wquoted-include-in-framework-header"
#import "JGProgressHUD-Defines.h"
#import "JGProgressHUDShadow.h"
#import "JGProgressHUDAnimation.h"
#import "JGProgressHUDFadeAnimation.h"
#import "JGProgressHUDFadeZoomAnimation.h"
#import "JGProgressHUDIndicatorView.h"
#import "JGProgressHUDErrorIndicatorView.h"
#import "JGProgressHUDSuccessIndicatorView.h"
#import "JGProgressHUDRingIndicatorView.h"
#import "JGProgressHUDPieIndicatorView.h"
#import "JGProgressHUDIndeterminateIndicatorView.h"
#pragma clang diagnostic pop
@protocol JGProgressHUDDelegate;
/**
A HUD to indicate progress, success, error, warnings or other notifications to the user.
@discussion @c JGProgressHUD respects its @c layoutMargins when positioning the HUD view. Additionally, on iOS 11 if @c insetsLayoutMarginsFromSafeArea is set to @c YES (default) the @c layoutMargins additionally contain the @c safeAreaInsets.
@note Remember to call every method from the main thread! UIKit => main thread!
@attention You may not add JGProgressHUD to a view which has an alpha value < 1.0 or to a view which is a subview of a view with an alpha value < 1.0.
*/
@interface JGProgressHUD : UIView
/**
Designated initializer.
@param style The appearance style of the HUD.
*/
- (instancetype __nonnull)initWithStyle:(JGProgressHUDStyle)style;
/**
Convenience initializer.
@param style The appearance style of the HUD.
*/
+ (instancetype __nonnull)progressHUDWithStyle:(JGProgressHUDStyle)style;
/**
Convenience initializer. The HUD will dynamically change its style based on whether dark mode is enabled or not. When dark mode is on, the style will be JGProgressHUDStyleDark, when dark mode is off the style will be JGProgressHUDStyleExtraLight.
*/
- (instancetype __nonnull)initWithAutomaticStyle;
/**
Convenience initializer. The HUD will dynamically change its style based on whether dark mode is enabled or not. When dark mode is on, the style will be JGProgressHUDStyleDark, when dark mode is off the style will be JGProgressHUDStyleExtraLight.
*/
+ (instancetype __nonnull)progressHUDWithAutomaticStyle;
/**
The appearance style of the HUD.
@b Default: JGProgressHUDStyleExtraLight.
*/
@property (nonatomic, assign) JGProgressHUDStyle style;
/** The view in which the HUD is presented. */
@property (nonatomic, weak, readonly, nullable) UIView *targetView;
/**
The delegate of the HUD.
@sa JGProgressHUDDelegate.
*/
@property (nonatomic, weak, nullable) id <JGProgressHUDDelegate> delegate;
/** The actual HUD view visible on screen. You may add animations to this view. */
@property (nonatomic, strong, readonly, nonnull) UIView *HUDView;
/**
The content view inside the @c HUDView. If you want to add additional views to the HUD you should add them as subview to the @c contentView.
*/
@property (nonatomic, strong, readonly, nonnull) UIView *contentView;
/**
The label used to present text on the HUD. Set the @c text or @c attributedText property of this label to change the displayed text. You may not change the label's @c frame or @c bounds.
*/
@property (nonatomic, strong, readonly, nonnull) UILabel *textLabel;
/**
The label used to present detail text on the HUD. Set the @c text or @c attributedText property of this label to change the displayed text. You may not change the label's @c frame or @c bounds.
*/
@property (nonatomic, strong, readonly, nonnull) UILabel *detailTextLabel;
/**
The indicator view. You can assign a custom subclass of @c JGProgressHUDIndicatorView to this property or one of the default indicator views (if you do so, you should assign it before showing the HUD). This value is optional.
@b Default: JGProgressHUDIndeterminateIndicatorView.
*/
@property (nonatomic, strong, nullable) JGProgressHUDIndicatorView *indicatorView;
/**
The shadow cast by the @c HUDView. This value is optional. Setting this to @c nil means no shadow is cast by the HUD.
@b Default: nil.
*/
@property (nonatomic, strong, nullable) JGProgressHUDShadow *shadow;
/**
The position of the HUD inside the hosting view's frame, or inside the specified frame.
@b Default: JGProgressHUDPositionCenter
*/
@property (nonatomic, assign) JGProgressHUDPosition position;
/**
The animation used for showing and dismissing the HUD.
@b Default: JGProgressHUDFadeAnimation.
*/
@property (nonatomic, strong, nonnull) JGProgressHUDAnimation *animation;
#if TARGET_OS_IOS
/**
Interaction type of the HUD. Determines whether touches should be let through to the views behind the HUD.
@sa JGProgressHUDInteractionType.
@b Default: JGProgressHUDInteractionTypeBlockAllTouches.
*/
@property (nonatomic, assign) JGProgressHUDInteractionType interactionType;
#endif
/**
Parallax mode for the HUD. This setting determines whether the HUD should have a parallax (@c UIDeviceMotion) effect. This effect is controlled by device motion on iOS and remote touchpad panning gestures on tvOS.
@sa JGProgressHUDParallaxMode.
@b Default: JGProgressHUDParallaxModeDevice.
*/
@property (nonatomic, assign) JGProgressHUDParallaxMode parallaxMode;
#if TARGET_OS_TV
/**
When this property is set to @c YES the HUD will try to become focused, which prevents interactions with the @c targetView. If set to @c NO the HUD will not become focused and interactions with @c targetView remain possible. Default: @c YES.
*/
@property (nonatomic, assign) BOOL wantsFocus;
#endif
/**
If the HUD should always have the same width and height.
@b Default: NO.
*/
@property (nonatomic, assign) BOOL square;
/**
Internally @c JGProgressHUD uses an @c UIVisualEffectView with a @c UIBlurEffect. A second @c UIVisualEffectView can be added on top of that with a @c UIVibrancyEffect which amplifies and adjusts the color of content layered behind the view, allowing content placed inside the contentView to become more vivid. This flag sets whether the @c UIVibrancyEffect should be used. Using the vibrancy effect can sometimes, depending on the contents of the display, result in a weird look (especially on iOS < 9.3).
@b Default: NO.
*/
@property (nonatomic, assign) BOOL vibrancyEnabled;
/**
The radius used for rounding the four corners of the HUD view.
@b Default: 10.0.
*/
@property (nonatomic, assign) CGFloat cornerRadius;
/**
Insets the contents of the HUD.
@b Default: (20, 20, 20, 20).
*/
@property (nonatomic, assign) UIEdgeInsets contentInsets;
/**
@return Whether the HUD is visible on screen.
*/
@property (nonatomic, assign, readonly, getter = isVisible) BOOL visible;
/**
The progress to display using the @c progressIndicatorView. A change of this property is not animated. Use the @c setProgress:animated: method for an animated progress change.
@b Default: 0.0.
*/
@property (nonatomic, assign) float progress;
/**
Adjusts the current progress shown by the receiver, optionally animating the change.
The current progress is represented by a floating-point value between 0.0 and 1.0, inclusive, where 1.0 indicates the completion of the task. The default value is 0.0. Values less than 0.0 and greater than 1.0 are pinned to those limits.
@param progress The new progress value.
@param animated YES if the change should be animated, NO if the change should happen immediately.
*/
- (void)setProgress:(float)progress animated:(BOOL)animated;
/**
Specifies a minimum time that the HUD will be on-screen. Useful to prevent the HUD from flashing quickly on the screen when indeterminate tasks complete more quickly than expected.
@b Default: 0.0.
*/
@property (nonatomic, assign) NSTimeInterval minimumDisplayTime;
/**
Determines whether Voice Over announcements should be made upon displaying the HUD (if Voice Over is active).
@b Default: YES
*/
@property (nonatomic, assign) BOOL voiceOverEnabled;
#if TARGET_OS_IOS
/**
A block to be invoked when the HUD view is tapped.
@note The interaction type of the HUD must be @c JGProgressHUDInteractionTypeBlockTouchesOnHUDView or @c JGProgressHUDInteractionTypeBlockAllTouches, otherwise this block won't be fired.
*/
@property (nonatomic, copy, nullable) void (^tapOnHUDViewBlock)(JGProgressHUD *__nonnull HUD);
/**
A block to be invoked when the area outside of the HUD view is tapped.
@note The interaction type of the HUD must be @c JGProgressHUDInteractionTypeBlockAllTouches, otherwise this block won't be fired.
*/
@property (nonatomic, copy, nullable) void (^tapOutsideBlock)(JGProgressHUD *__nonnull HUD);
#endif
/**
Shows the HUD animated. You should preferably show the HUD in a UIViewController's view. The HUD will be repositioned in response to rotation and keyboard show/hide notifications.
@param view The view to show the HUD in. The frame of the @c view will be used to calculate the position of the HUD.
*/
- (void)showInView:(UIView *__nonnull)view;
/**
Shows the HUD. You should preferably show the HUD in a UIViewController's view. The HUD will be repositioned in response to rotation and keyboard show/hide notifications.
@param view The view to show the HUD in. The frame of the @c view will be used to calculate the position of the HUD.
@param animated If the HUD should show with an animation.
*/
- (void)showInView:(UIView *__nonnull)view animated:(BOOL)animated;
/**
Shows the HUD after a delay. You should preferably show the HUD in a UIViewController's view. The HUD will be repositioned in response to rotation and keyboard show/hide notifications.
You may call @c dismiss to stop the HUD from appearing before the delay has passed.
@param view The view to show the HUD in. The frame of the @c view will be used to calculate the position of the HUD.
@param animated If the HUD should show with an animation.
@param delay The delay until the HUD will be shown.
*/
- (void)showInView:(UIView *__nonnull)view animated:(BOOL)animated afterDelay:(NSTimeInterval)delay;
/** Dismisses the HUD animated. If the HUD is currently not visible this method does nothing. */
- (void)dismiss;
/**
Dismisses the HUD. If the HUD is currently not visible this method does nothing.
@param animated If the HUD should dismiss with an animation.
*/
- (void)dismissAnimated:(BOOL)animated;
/**
Dismisses the HUD animated after a delay. If the HUD is currently not visible this method does nothing.
@param delay The delay until the HUD will be dismissed.
*/
- (void)dismissAfterDelay:(NSTimeInterval)delay;
/**
Dismisses the HUD after a delay. If the HUD is currently not visible this method does nothing.
@param delay The delay until the HUD will be dismissed.
@param animated If the HUD should dismiss with an animation.
*/
- (void)dismissAfterDelay:(NSTimeInterval)delay animated:(BOOL)animated;
/**
Dismisses the HUD after a delay and runs a block upon completion. If the HUD is currently not visible this method does nothing.
@param delay The delay until the HUD will be dismissed.
@param animated If the HUD should dismiss with an animation.
@param dismissCompletion The block to execute after the HUD was dismissed.
*/
- (void)dismissAfterDelay:(NSTimeInterval)delay animated:(BOOL)animated completion:(void (^_Nullable)(void))dismissCompletion;
/**
Schedules the given block to be executed when this HUD disapears. If the HUD is currently not visible this method does nothing.
@param dismissCompletion The block to execute after the HUD was dismissed. Multiple calls to this method cause the different blocks to be executed in FIFO order.
*/
- (void)performAfterDismiss:(void (^_Nonnull)(void))dismissCompletion;
@end
@interface JGProgressHUD (HUDManagement)
/**
@param view The view to return all visible progress HUDs for.
@return All visible progress HUDs in the view.
*/
+ (NSArray<JGProgressHUD *> *__nonnull)allProgressHUDsInView:(UIView *__nonnull)view;
/**
@param view The view to return all visible progress HUDs for.
@return All visible progress HUDs in the view and its subviews.
*/
+ (NSArray<JGProgressHUD *> *__nonnull)allProgressHUDsInViewHierarchy:(UIView *__nonnull)view;
@end
@protocol JGProgressHUDDelegate <NSObject>
@optional
/**
Called before the HUD will appear.
@param view The view in which the HUD is presented.
*/
- (void)progressHUD:(JGProgressHUD *__nonnull)progressHUD willPresentInView:(UIView *__nonnull)view;
/**
Called after the HUD appeared.
@param view The view in which the HUD is presented.
*/
- (void)progressHUD:(JGProgressHUD *__nonnull)progressHUD didPresentInView:(UIView *__nonnull)view;
/**
Called before the HUD will disappear.
@param view The view in which the HUD is presented and will be dismissed from.
*/
- (void)progressHUD:(JGProgressHUD *__nonnull)progressHUD willDismissFromView:(UIView *__nonnull)view;
/**
Called after the HUD has disappeared.
@param view The view in which the HUD was presented and was be dismissed from.
*/
- (void)progressHUD:(JGProgressHUD *__nonnull)progressHUD didDismissFromView:(UIView *__nonnull)view;
@end