GIDTimedLoader.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2023 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import <TargetConditionals.h>
  18. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  19. /// An enumeration detailing the states of the timed loader.
  20. typedef NS_ENUM(NSUInteger, GIDTimedLoaderAnimationStatus) {
  21. /// The timed loader has not started.
  22. GIDTimedLoaderAnimationStatusNotStarted,
  23. /// The timed loader's activity indicator is animating.
  24. GIDTimedLoaderAnimationStatusAnimating,
  25. /// The timed loader's activity indicator has stopped animating.
  26. GIDTimedLoaderAnimationStatusStopped,
  27. };
  28. /// The minimum animation duration time for the timed loader's activity indicator.
  29. extern CFTimeInterval const kGIDTimedLoaderMinAnimationDuration;
  30. /// The maximum delay to wait before the time loader will display the loading activity indicator.
  31. extern CFTimeInterval const kGIDTimedLoaderMaxDelayBeforeAnimating;
  32. @class UIViewController;
  33. NS_ASSUME_NONNULL_BEGIN
  34. /// A type used to manage the presentation of a load screen for at least
  35. /// `kGIDTimedLoaderMinAnimationDuration` to prevent flashing.
  36. ///
  37. /// `GIDTimedLoader` will also only show its loading screen until
  38. /// `kGIDTimedLoaderMaxDelayBeforeAnimating` has expired.
  39. @interface GIDTimedLoader : NSObject
  40. /// Created this timed loading controller with the provided presenting view controller, which will
  41. /// be used for presenting hte loading view controller with the activity indicator.
  42. - (instancetype)initWithPresentingViewController:(UIViewController *)presentingViewController;
  43. - (instancetype)init NS_UNAVAILABLE;
  44. /// Tells the controller to start keeping track of loading time.
  45. - (void)startTiming;
  46. /// Tells the controller to stop keeping track of loading time.
  47. ///
  48. /// @param completion The block to invoke upon successfully stopping.
  49. /// @note Use the completion parameter to, for example, present the UI that should be shown after
  50. /// the work has completed.
  51. - (void)stopTimingWithCompletion:(void (^)(void))completion;
  52. @property(nonatomic) GIDTimedLoaderAnimationStatus animationStatus;
  53. @end
  54. NS_ASSUME_NONNULL_END
  55. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST