|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the BSD-style license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | + * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | + */ |
| 9 | + |
| 10 | +#import <Foundation/Foundation.h> |
| 11 | + |
| 12 | +#import <React/RCTSurfaceStage.h> |
| 13 | + |
| 14 | +NS_ASSUME_NONNULL_BEGIN |
| 15 | + |
| 16 | +@class RCTBridge; |
| 17 | +@class RCTSurfaceView; |
| 18 | +@protocol RCTSurfaceDelegate; |
| 19 | + |
| 20 | +/** |
| 21 | + * RCTSurface instance represents React Native-powered piece of a user interface |
| 22 | + * which can be a full-screen app, separate modal view controller, |
| 23 | + * or even small widget. |
| 24 | + * It is called "Surface". |
| 25 | + * |
| 26 | + * The RCTSurface instance is completely thread-safe by design; |
| 27 | + * it can be created on any thread, and any its method can be called from |
| 28 | + * any thread (if the opposite is not mentioned explicitly). |
| 29 | + * |
| 30 | + * The primary goals of the RCTSurface are: |
| 31 | + * * ability to measure and layout the surface in a thread-safe |
| 32 | + * and synchronous manner; |
| 33 | + * * ability to create a UIView instance on demand (later); |
| 34 | + * * ability to communicate the current stage of the surface granularly. |
| 35 | + */ |
| 36 | +@interface RCTSurface : NSObject |
| 37 | + |
| 38 | +@property (atomic, readonly) RCTSurfaceStage stage; |
| 39 | +@property (atomic, readonly) RCTBridge *bridge; |
| 40 | +@property (atomic, readonly) NSString *moduleName; |
| 41 | +@property (atomic, readonly) NSNumber *rootViewTag; |
| 42 | + |
| 43 | +@property (atomic, readwrite, weak, nullable) id<RCTSurfaceDelegate> delegate; |
| 44 | + |
| 45 | +@property (atomic, copy, readwrite) NSDictionary *properties; |
| 46 | + |
| 47 | +- (instancetype)initWithBridge:(RCTBridge *)bridge |
| 48 | + moduleName:(NSString *)moduleName |
| 49 | + initialProperties:(NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER; |
| 50 | + |
| 51 | +#pragma mark - Dealing with UIView representation, the Main thread only access |
| 52 | + |
| 53 | +/** |
| 54 | + * Creates (if needed) and returns `UIView` instance which represents the Surface. |
| 55 | + * The Surface will cache and *retain* this object. |
| 56 | + * Returning the UIView instance does not mean that the Surface is ready |
| 57 | + * to execute and layout. It can be just a handler which Surface will use later |
| 58 | + * to mount the actual views. |
| 59 | + * RCTSurface does not control (or influence in any way) the size or origin |
| 60 | + * of this view. Some superview (or another owner) must use other methods |
| 61 | + * of this class to setup proper layout and interop interactions with UIKit |
| 62 | + * or another UI framework. |
| 63 | + * This method must be called only from the main queue. |
| 64 | + */ |
| 65 | +- (RCTSurfaceView *)view; |
| 66 | + |
| 67 | +#pragma mark - Layout: Setting the size constrains |
| 68 | + |
| 69 | +/** |
| 70 | + * Sets `minimumSize` and `maximumSize` layout constraints for the Surface. |
| 71 | + */ |
| 72 | +- (void)setMinimumSize:(CGSize)minimumSize |
| 73 | + maximumSize:(CGSize)maximumSize; |
| 74 | + |
| 75 | +/** |
| 76 | + * Previously set `minimumSize` layout constraint. |
| 77 | + * Defaults to `{0, 0}`. |
| 78 | + */ |
| 79 | +@property (atomic, assign, readonly) CGSize minimumSize; |
| 80 | + |
| 81 | +/** |
| 82 | + * Previously set `maximumSize` layout constraint. |
| 83 | + * Defaults to `{INFINITY, INFINITY}`. |
| 84 | + */ |
| 85 | +@property (atomic, assign, readonly) CGSize maximumSize; |
| 86 | + |
| 87 | + |
| 88 | +/** |
| 89 | + * Simple shortcut to `-[RCTSurface setMinimumSize:size maximumSize:size]`. |
| 90 | + */ |
| 91 | +- (void)setSize:(CGSize)size; |
| 92 | + |
| 93 | +#pragma mark - Layout: Measuring |
| 94 | + |
| 95 | +/** |
| 96 | + * Measures the Surface with given constraints. |
| 97 | + * This method does not cause any side effects on the surface object. |
| 98 | + */ |
| 99 | +- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize |
| 100 | + maximumSize:(CGSize)maximumSize; |
| 101 | + |
| 102 | +/** |
| 103 | + * Return the current size of the root view based on (but not clamp by) current |
| 104 | + * size constraints. |
| 105 | + */ |
| 106 | +@property (atomic, assign, readonly) CGSize intrinsicSize; |
| 107 | + |
| 108 | +#pragma mark - Synchronous waiting |
| 109 | + |
| 110 | +/** |
| 111 | + * Synchronously blocks the current thread up to given `timeout` until |
| 112 | + * the Surface will not have given `stage`. |
| 113 | + * Do nothing, if called from the main or `UIManager` queue. |
| 114 | + */ |
| 115 | +- (BOOL)synchronouslyWaitForStage:(RCTSurfaceStage)stage timeout:(NSTimeInterval)timeout; |
| 116 | + |
| 117 | +@end |
| 118 | + |
| 119 | +NS_ASSUME_NONNULL_END |
0 commit comments