RCTActivityIndicatorViewManager.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import "RCTActivityIndicatorViewManager.h"
  8. #import "RCTActivityIndicatorView.h"
  9. #import "RCTConvert.h"
  10. @implementation RCTConvert (UIActivityIndicatorView)
  11. // NOTE: It's pointless to support UIActivityIndicatorViewStyleGray
  12. // as we can set the color to any arbitrary value that we want to
  13. RCT_ENUM_CONVERTER(
  14. UIActivityIndicatorViewStyle,
  15. (@{
  16. @"large" : @(UIActivityIndicatorViewStyleWhiteLarge),
  17. @"small" : @(UIActivityIndicatorViewStyleWhite),
  18. }),
  19. UIActivityIndicatorViewStyleWhiteLarge,
  20. integerValue)
  21. @end
  22. @implementation RCTActivityIndicatorViewManager
  23. RCT_EXPORT_MODULE()
  24. - (UIView *)view
  25. {
  26. return [RCTActivityIndicatorView new];
  27. }
  28. RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
  29. RCT_EXPORT_VIEW_PROPERTY(hidesWhenStopped, BOOL)
  30. RCT_CUSTOM_VIEW_PROPERTY(size, UIActivityIndicatorViewStyle, UIActivityIndicatorView)
  31. {
  32. /*
  33. Setting activityIndicatorViewStyle overrides the color, so restore the original color
  34. after setting the indicator style.
  35. */
  36. UIColor *oldColor = view.color;
  37. view.activityIndicatorViewStyle =
  38. json ? [RCTConvert UIActivityIndicatorViewStyle:json] : defaultView.activityIndicatorViewStyle;
  39. view.color = oldColor;
  40. }
  41. RCT_CUSTOM_VIEW_PROPERTY(animating, BOOL, UIActivityIndicatorView)
  42. {
  43. BOOL animating = json ? [RCTConvert BOOL:json] : [defaultView isAnimating];
  44. if (animating != [view isAnimating]) {
  45. if (animating) {
  46. [view startAnimating];
  47. } else {
  48. [view stopAnimating];
  49. }
  50. }
  51. }
  52. @end