UIView+React.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/RCTComponent.h>
  9. #import <yoga/YGEnums.h>
  10. @class RCTShadowView;
  11. @interface UIView (React) <RCTComponent>
  12. /**
  13. * RCTComponent interface.
  14. */
  15. - (NSArray<UIView *> *)reactSubviews NS_REQUIRES_SUPER;
  16. - (UIView *)reactSuperview NS_REQUIRES_SUPER;
  17. - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex NS_REQUIRES_SUPER;
  18. - (void)removeReactSubview:(UIView *)subview NS_REQUIRES_SUPER;
  19. /**
  20. * The native id of the view, used to locate view from native codes
  21. */
  22. @property (nonatomic, copy) NSString *nativeID;
  23. /**
  24. * Determines whether or not a view should ignore inverted colors or not. Used to set
  25. * UIView property accessibilityIgnoresInvertColors in iOS 11+.
  26. */
  27. @property (nonatomic, assign) BOOL shouldAccessibilityIgnoresInvertColors;
  28. /**
  29. * Layout direction of the view.
  30. * Internally backed to `semanticContentAttribute` property.
  31. * Defaults to `LeftToRight` in case of ambiguity.
  32. */
  33. @property (nonatomic, assign) UIUserInterfaceLayoutDirection reactLayoutDirection;
  34. /**
  35. * Yoga `display` style property. Can be `flex` or `none`.
  36. * Defaults to `flex`.
  37. * May be used to temporary hide the view in a very efficient way.
  38. */
  39. @property (nonatomic, assign) YGDisplay reactDisplay;
  40. /**
  41. * The z-index of the view.
  42. */
  43. @property (nonatomic, assign) NSInteger reactZIndex;
  44. /**
  45. * Subviews sorted by z-index. Note that this method doesn't do any caching (yet)
  46. * and sorts all the views each call.
  47. */
  48. - (NSArray<UIView *> *)reactZIndexSortedSubviews;
  49. /**
  50. * Updates the subviews array based on the reactSubviews. Default behavior is
  51. * to insert the sortedReactSubviews into the UIView.
  52. */
  53. - (void)didUpdateReactSubviews;
  54. /**
  55. * Called each time props have been set.
  56. * The default implementation does nothing.
  57. */
  58. - (void)didSetProps:(NSArray<NSString *> *)changedProps;
  59. /**
  60. * Used by the UIIManager to set the view frame.
  61. * May be overridden to disable animation, etc.
  62. */
  63. - (void)reactSetFrame:(CGRect)frame;
  64. /**
  65. * This method finds and returns the containing view controller for the view.
  66. */
  67. - (UIViewController *)reactViewController;
  68. /**
  69. * This method attaches the specified controller as a child of the
  70. * the owning view controller of this view. Returns NO if no view
  71. * controller is found (which may happen if the view is not currently
  72. * attached to the view hierarchy).
  73. */
  74. - (void)reactAddControllerToClosestParent:(UIViewController *)controller;
  75. /**
  76. * Focus manipulation.
  77. */
  78. - (void)reactFocus;
  79. - (void)reactFocusIfNeeded;
  80. - (void)reactBlur;
  81. /**
  82. * Useful properties for computing layout.
  83. */
  84. @property (nonatomic, readonly) UIEdgeInsets reactBorderInsets;
  85. @property (nonatomic, readonly) UIEdgeInsets reactPaddingInsets;
  86. @property (nonatomic, readonly) UIEdgeInsets reactCompoundInsets;
  87. @property (nonatomic, readonly) CGRect reactContentFrame;
  88. /**
  89. * The (sub)view which represents this view in terms of accessibility.
  90. * ViewManager will apply all accessibility properties directly to this view.
  91. * May be overridden in view subclass which needs to be accessiblitywise
  92. * transparent in favour of some subview.
  93. * Defaults to `self`.
  94. */
  95. @property (nonatomic, readonly) UIView *reactAccessibilityElement;
  96. /**
  97. * Accessibility properties
  98. */
  99. @property (nonatomic, copy) NSString *accessibilityRole;
  100. @property (nonatomic, copy) NSDictionary<NSString *, id> *accessibilityState;
  101. @property (nonatomic, copy) NSArray<NSDictionary *> *accessibilityActions;
  102. @property (nonatomic, copy) NSDictionary *accessibilityValueInternal;
  103. /**
  104. * Used in debugging to get a description of the view hierarchy rooted at
  105. * the current view.
  106. */
  107. - (NSString *)react_recursiveDescription;
  108. @end