RCTUIManagerObserverCoordinator.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 <UIKit/UIKit.h>
  8. #import <React/RCTViewManager.h>
  9. typedef dispatch_block_t RCTUIManagerMountingBlock;
  10. /**
  11. * Allows hooking into UIManager internals. This can be used to execute code at
  12. * specific points during the view updating process.
  13. * New observers must not be added inside observer handlers.
  14. * The particular order of handler invocation is not guaranteed.
  15. * All observer handlers are called on UIManager queue.
  16. */
  17. @protocol RCTUIManagerObserver <NSObject>
  18. @optional
  19. /**
  20. * Called just before the UIManager layout views.
  21. * It allows performing some operation for components which contain custom
  22. * layout logic right before regular Yoga based layout. So, for instance,
  23. * some components which have own React-independent state can compute and cache
  24. * own intrinsic content size (which will be used by Yoga) at this point.
  25. */
  26. - (void)uiManagerWillPerformLayout:(RCTUIManager *)manager;
  27. /**
  28. * Called just after the UIManager layout views.
  29. * It allows performing custom layout logic right after regular Yoga based layout.
  30. * So, for instance, this can be used for computing final layout for a component,
  31. * since it has its final frame set by Yoga at this point.
  32. */
  33. - (void)uiManagerDidPerformLayout:(RCTUIManager *)manager;
  34. /**
  35. * Called before flushing UI blocks at the end of a batch.
  36. * This is called from the UIManager queue. Can be used to add UI operations in that batch.
  37. */
  38. - (void)uiManagerWillPerformMounting:(RCTUIManager *)manager;
  39. /**
  40. * Called right before flushing UI blocks and allows to intercept the mounting process.
  41. * Return `YES` to cancel default execution of the `block` (and perform the
  42. * execution later).
  43. */
  44. - (BOOL)uiManager:(RCTUIManager *)manager performMountingWithBlock:(RCTUIManagerMountingBlock)block;
  45. /**
  46. * Called just after flushing UI blocks.
  47. * This is called from the UIManager queue.
  48. */
  49. - (void)uiManagerDidPerformMounting:(RCTUIManager *)manager;
  50. @end
  51. /**
  52. * Simple helper which take care of RCTUIManager's observers.
  53. */
  54. @interface RCTUIManagerObserverCoordinator : NSObject <RCTUIManagerObserver>
  55. /**
  56. * Add a UIManagerObserver. See the `RCTUIManagerObserver` protocol for more info.
  57. * References to observers are held weakly.
  58. * This method can be called safely from any queue.
  59. */
  60. - (void)addObserver:(id<RCTUIManagerObserver>)observer;
  61. /**
  62. * Remove a `UIManagerObserver`.
  63. * This method can be called safely from any queue.
  64. */
  65. - (void)removeObserver:(id<RCTUIManagerObserver>)observer;
  66. @end