RCTComponentViewProtocol.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/RCTPrimitives.h>
  9. #import <react/core/EventEmitter.h>
  10. #import <react/core/LayoutMetrics.h>
  11. #import <react/core/Props.h>
  12. #import <react/core/State.h>
  13. #import <react/uimanager/ComponentDescriptorProvider.h>
  14. NS_ASSUME_NONNULL_BEGIN
  15. /*
  16. * Bitmask for all types of possible updates performing during mounting.
  17. */
  18. typedef NS_OPTIONS(NSInteger, RNComponentViewUpdateMask) {
  19. RNComponentViewUpdateMaskNone = 0,
  20. RNComponentViewUpdateMaskProps = 1 << 0,
  21. RNComponentViewUpdateMaskEventEmitter = 1 << 1,
  22. RNComponentViewUpdateMaskState = 1 << 3,
  23. RNComponentViewUpdateMaskLayoutMetrics = 1 << 4,
  24. RNComponentViewUpdateMaskAll = RNComponentViewUpdateMaskProps | RNComponentViewUpdateMaskEventEmitter |
  25. RNComponentViewUpdateMaskState | RNComponentViewUpdateMaskLayoutMetrics
  26. };
  27. /*
  28. * Represents a `UIView` instance managed by React.
  29. * All methods are non-@optional.
  30. * `UIView+ComponentViewProtocol` category provides default implementation
  31. * for all of them.
  32. */
  33. @protocol RCTComponentViewProtocol <NSObject>
  34. /*
  35. * Returns a `ComponentDescriptorProvider` of a particular `ComponentDescriptor` which this component view
  36. * represents.
  37. */
  38. + (facebook::react::ComponentDescriptorProvider)componentDescriptorProvider;
  39. /*
  40. * Returns a list of supplemental `ComponentDescriptorProvider`s (with do not have `ComponentView` counterparts) that
  41. * require for this component view.
  42. */
  43. + (std::vector<facebook::react::ComponentDescriptorProvider>)supplementalComponentDescriptorProviders;
  44. /*
  45. * Called for mounting (attaching) a child component view inside `self`
  46. * component view.
  47. * Receiver must add `childComponentView` as a subview.
  48. */
  49. - (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index;
  50. /*
  51. * Called for unmounting (detaching) a child component view from `self`
  52. * component view.
  53. * Receiver must remove `childComponentView` as a subview.
  54. */
  55. - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index;
  56. /*
  57. * Called for updating component's props.
  58. * Receiver must update native view props accordingly changed props.
  59. */
  60. - (void)updateProps:(facebook::react::Props::Shared const &)props
  61. oldProps:(facebook::react::Props::Shared const &)oldProps;
  62. /*
  63. * Called for updating component's state.
  64. * Receiver must update native view according to changed state.
  65. */
  66. - (void)updateState:(facebook::react::State::Shared const &)state
  67. oldState:(facebook::react::State::Shared const &)oldState;
  68. /*
  69. * Called for updating component's event handlers set.
  70. * Receiver must cache `eventEmitter` object inside and use it for emitting
  71. * events when needed.
  72. */
  73. - (void)updateEventEmitter:(facebook::react::EventEmitter::Shared const &)eventEmitter;
  74. /*
  75. * Called for updating component's layout metrics.
  76. * Receiver must update `UIView` layout-related fields (such as `frame`,
  77. * `bounds`, `layer.zPosition`, and so on) accordingly.
  78. */
  79. - (void)updateLayoutMetrics:(facebook::react::LayoutMetrics const &)layoutMetrics
  80. oldLayoutMetrics:(facebook::react::LayoutMetrics const &)oldLayoutMetrics;
  81. /*
  82. * Called when receiving a command
  83. */
  84. - (void)handleCommand:(NSString const *)commandName args:(NSArray const *)args;
  85. /*
  86. * Called right after all update methods were called for a particular component view.
  87. * Useful for performing updates that require knowledge of several independent aspects of the compound mounting change
  88. * (e.g. props *and* layout constraints).
  89. */
  90. - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask;
  91. /*
  92. * Called right after the component view is moved to a recycle pool.
  93. * Receiver must reset any local state and release associated
  94. * non-reusable resources.
  95. */
  96. - (void)prepareForRecycle;
  97. /**
  98. * Read the last props used to update the view.
  99. */
  100. - (facebook::react::SharedProps)props;
  101. @end
  102. NS_ASSUME_NONNULL_END