RCTRootView.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/RCTBridge.h>
  9. @protocol RCTRootViewDelegate;
  10. /**
  11. * This enum is used to define size flexibility type of the root view.
  12. * If a dimension is flexible, the view will recalculate that dimension
  13. * so the content fits. Recalculations are performed when the root's frame,
  14. * size flexibility mode or content size changes. After a recalculation,
  15. * rootViewDidChangeIntrinsicSize method of the RCTRootViewDelegate will be called.
  16. */
  17. typedef NS_ENUM(NSInteger, RCTRootViewSizeFlexibility) {
  18. RCTRootViewSizeFlexibilityNone = 0,
  19. RCTRootViewSizeFlexibilityWidth = 1 << 0,
  20. RCTRootViewSizeFlexibilityHeight = 1 << 1,
  21. RCTRootViewSizeFlexibilityWidthAndHeight = RCTRootViewSizeFlexibilityWidth | RCTRootViewSizeFlexibilityHeight,
  22. };
  23. /**
  24. * This notification is sent when the first subviews are added to the root view
  25. * after the application has loaded. This is used to hide the `loadingView`, and
  26. * is a good indicator that the application is ready to use.
  27. */
  28. #if defined(__cplusplus)
  29. extern "C"
  30. #else
  31. extern
  32. #endif
  33. NS_ASSUME_NONNULL_BEGIN
  34. NSString *const RCTContentDidAppearNotification;
  35. /**
  36. * Native view used to host React-managed views within the app. Can be used just
  37. * like any ordinary UIView. You can have multiple RCTRootViews on screen at
  38. * once, all controlled by the same JavaScript application.
  39. */
  40. @interface RCTRootView : UIView
  41. /**
  42. * - Designated initializer -
  43. */
  44. - (instancetype)initWithBridge:(RCTBridge *)bridge
  45. moduleName:(NSString *)moduleName
  46. initialProperties:(nullable NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
  47. /**
  48. * - Convenience initializer -
  49. * A bridge will be created internally.
  50. * This initializer is intended to be used when the app has a single RCTRootView,
  51. * otherwise create an `RCTBridge` and pass it in via `initWithBridge:moduleName:`
  52. * to all the instances.
  53. */
  54. - (instancetype)initWithBundleURL:(NSURL *)bundleURL
  55. moduleName:(NSString *)moduleName
  56. initialProperties:(nullable NSDictionary *)initialProperties
  57. launchOptions:(nullable NSDictionary *)launchOptions;
  58. /**
  59. * The name of the JavaScript module to execute within the
  60. * specified scriptURL (required). Setting this will not have
  61. * any immediate effect, but it must be done prior to loading
  62. * the script.
  63. */
  64. @property (nonatomic, copy, readonly) NSString *moduleName;
  65. /**
  66. * The bridge used by the root view. Bridges can be shared between multiple
  67. * root views, so you can use this property to initialize another RCTRootView.
  68. */
  69. @property (nonatomic, strong, readonly) RCTBridge *bridge;
  70. /**
  71. * The properties to apply to the view. Use this property to update
  72. * application properties and rerender the view. Initialized with
  73. * initialProperties argument of the initializer.
  74. *
  75. * Set this property only on the main thread.
  76. */
  77. @property (nonatomic, copy, readwrite, nullable) NSDictionary *appProperties;
  78. /**
  79. * The size flexibility mode of the root view.
  80. */
  81. @property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
  82. /*
  83. * The minimum size of the root view, defaults to CGSizeZero.
  84. */
  85. @property (nonatomic, assign) CGSize minimumSize;
  86. /**
  87. * The delegate that handles intrinsic size updates.
  88. */
  89. @property (nonatomic, weak, nullable) id<RCTRootViewDelegate> delegate;
  90. /**
  91. * The backing view controller of the root view.
  92. */
  93. @property (nonatomic, weak, nullable) UIViewController *reactViewController;
  94. /**
  95. * The React-managed contents view of the root view.
  96. */
  97. @property (nonatomic, strong, readonly) UIView *contentView;
  98. /**
  99. * A view to display while the JavaScript is loading, so users aren't presented
  100. * with a blank screen. By default this is nil, but you can override it with
  101. * (for example) a UIActivityIndicatorView or a placeholder image.
  102. */
  103. @property (nonatomic, strong, nullable) UIView *loadingView;
  104. /**
  105. * When set, any touches on the RCTRootView that are not matched up to any of the child
  106. * views will be passed to siblings of the RCTRootView. See -[UIView hitTest:withEvent:]
  107. * for details on iOS hit testing.
  108. *
  109. * Enable this to support a semi-transparent RN view that occupies the whole screen but
  110. * has visible content below it that the user can interact with.
  111. *
  112. * The default value is NO.
  113. */
  114. @property (nonatomic, assign) BOOL passThroughTouches;
  115. /**
  116. * Timings for hiding the loading view after the content has loaded. Both of
  117. * these values default to 0.25 seconds.
  118. */
  119. @property (nonatomic, assign) NSTimeInterval loadingViewFadeDelay;
  120. @property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration;
  121. @end
  122. @interface RCTRootView (Deprecated)
  123. /**
  124. * The intrinsic size of the root view's content. This is set right before the
  125. * `rootViewDidChangeIntrinsicSize` method of `RCTRootViewDelegate` is called.
  126. * This property is deprecated and will be removed in next releases.
  127. * Use UIKit `intrinsicContentSize` property instead.
  128. */
  129. @property (readonly, nonatomic, assign) CGSize intrinsicSize __deprecated_msg("Use `intrinsicContentSize` instead.");
  130. /**
  131. * This methods is deprecated and will be removed soon.
  132. * To interrupt a React Native gesture recognizer, use the standard
  133. * `UIGestureRecognizer` negotiation process.
  134. * See `UIGestureRecognizerDelegate` for more details.
  135. */
  136. - (void)cancelTouches;
  137. @end
  138. NS_ASSUME_NONNULL_END