RCTComponent.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <CoreGraphics/CoreGraphics.h>
  8. #import <Foundation/Foundation.h>
  9. /**
  10. * These block types can be used for mapping input event handlers from JS to view
  11. * properties. Unlike JS method callbacks, these can be called multiple times.
  12. */
  13. typedef void (^RCTDirectEventBlock)(NSDictionary *body);
  14. typedef void (^RCTBubblingEventBlock)(NSDictionary *body);
  15. /**
  16. * Logical node in a tree of application components. Both `ShadowView` and
  17. * `UIView` conforms to this. Allows us to write utilities that reason about
  18. * trees generally.
  19. */
  20. @protocol RCTComponent <NSObject>
  21. @property (nonatomic, copy) NSNumber *reactTag;
  22. @property (nonatomic, copy) NSNumber *rootTag;
  23. - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex;
  24. - (void)removeReactSubview:(id<RCTComponent>)subview;
  25. - (NSArray<id<RCTComponent>> *)reactSubviews;
  26. - (id<RCTComponent>)reactSuperview;
  27. - (NSNumber *)reactTagAtPoint:(CGPoint)point;
  28. // View/ShadowView is a root view
  29. - (BOOL)isReactRootView;
  30. /**
  31. * Called each time props have been set.
  32. * Not all props have to be set - React can set only changed ones.
  33. * @param changedProps String names of all set props.
  34. */
  35. - (void)didSetProps:(NSArray<NSString *> *)changedProps;
  36. /**
  37. * Called each time subviews have been updated
  38. */
  39. - (void)didUpdateReactSubviews;
  40. @end
  41. // TODO: this is kinda dumb - let's come up with a
  42. // better way of identifying root React views please!
  43. static inline BOOL RCTIsReactRootView(NSNumber *reactTag)
  44. {
  45. return reactTag.integerValue % 10 == 1;
  46. }