RCTSurfaceHostingView.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/RCTSurfaceDelegate.h>
  9. #import <React/RCTSurfaceSizeMeasureMode.h>
  10. #import <React/RCTSurfaceStage.h>
  11. @class RCTBridge;
  12. @class RCTSurface;
  13. typedef UIView *_Nullable (^RCTSurfaceHostingViewActivityIndicatorViewFactory)(void);
  14. NS_ASSUME_NONNULL_BEGIN
  15. /**
  16. * UIView subclass which providers interoperability between UIKit and
  17. * Surface regarding layout and life-cycle.
  18. * This class can be used as easy-to-use general purpose integration point
  19. * of ReactNative-powered experiences in UIKit based apps.
  20. */
  21. @interface RCTSurfaceHostingView : UIView <RCTSurfaceDelegate>
  22. /**
  23. * Create an instance of RCTSurface to be hosted.
  24. */
  25. + (RCTSurface *)createSurfaceWithBridge:(RCTBridge *)bridge
  26. moduleName:(NSString *)moduleName
  27. initialProperties:(NSDictionary *)initialProperties;
  28. /**
  29. * Designated initializer.
  30. * Instanciates a view with given Surface object.
  31. * Note: The view retains the surface object.
  32. */
  33. - (instancetype)initWithSurface:(RCTSurface *)surface
  34. sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode NS_DESIGNATED_INITIALIZER;
  35. /**
  36. * Convenience initializer.
  37. * Instanciates a Surface object with given `bridge`, `moduleName`, and
  38. * `initialProperties`, and then use it to instanciate a view.
  39. */
  40. - (instancetype)initWithBridge:(RCTBridge *)bridge
  41. moduleName:(NSString *)moduleName
  42. initialProperties:(NSDictionary *)initialProperties
  43. sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode;
  44. /**
  45. * Surface object which is currently using to power the view.
  46. * Read-only.
  47. */
  48. @property (nonatomic, strong, readonly) RCTSurface *surface;
  49. /**
  50. * Size measure mode which are defining relationship between UIKit and ReactNative
  51. * layout approaches.
  52. * Defaults to `RCTSurfaceSizeMeasureModeWidthAtMost | RCTSurfaceSizeMeasureModeHeightAtMost`.
  53. */
  54. @property (nonatomic, assign) RCTSurfaceSizeMeasureMode sizeMeasureMode;
  55. /**
  56. * Activity indicator factory.
  57. * A hosting view may use this block to instantiate and display custom activity
  58. * (loading) indicator (aka "spinner") when it needed.
  59. * Defaults to `nil` (no activity indicator).
  60. */
  61. @property (nonatomic, copy, nullable) RCTSurfaceHostingViewActivityIndicatorViewFactory activityIndicatorViewFactory;
  62. @end
  63. NS_ASSUME_NONNULL_END