/
RCTUIManager.h
219 lines (181 loc) · 7.19 KB
/
RCTUIManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTInvalidating.h>
#import <React/RCTRootView.h>
#import <React/RCTViewManager.h>
/**
* UIManager queue
*/
RCT_EXTERN dispatch_queue_t RCTGetUIManagerQueue(void);
/**
* Default name for the UIManager queue
*/
RCT_EXTERN char *const RCTUIManagerQueueName;
/**
* Check if we are currently on UIManager queue.
*/
RCT_EXTERN BOOL RCTIsUIManagerQueue(void);
/**
* Convenience macro for asserting that we're running on UIManager queue.
*/
#define RCTAssertUIManagerQueue() RCTAssert(RCTIsUIManagerQueue(), \
@"This function must be called on the UIManager queue")
/**
* Posted right before re-render happens. This is a chance for views to invalidate their state so
* next render cycle will pick up updated views and layout appropriately.
*/
RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification;
/**
* Posted whenever a new root view is registered with RCTUIManager. The userInfo property
* will contain a RCTUIManagerRootViewKey with the registered root view.
*/
RCT_EXTERN NSString *const RCTUIManagerDidRegisterRootViewNotification;
/**
* Posted whenever a root view is removed from the RCTUIManager. The userInfo property
* will contain a RCTUIManagerRootViewKey with the removed root view.
*/
RCT_EXTERN NSString *const RCTUIManagerDidRemoveRootViewNotification;
/**
* Key for the root view property in the above notifications
*/
RCT_EXTERN NSString *const RCTUIManagerRootViewKey;
@class RCTUIManagerObserverCoordinator;
/**
* The RCTUIManager is the module responsible for updating the view hierarchy.
*/
@interface RCTUIManager : NSObject <RCTBridgeModule, RCTInvalidating>
/**
* Register a root view with the RCTUIManager.
*/
- (void)registerRootView:(UIView *)rootView;
/**
* Gets the view name associated with a reactTag.
*/
- (NSString *)viewNameForReactTag:(NSNumber *)reactTag;
/**
* Gets the view associated with a reactTag.
*/
- (UIView *)viewForReactTag:(NSNumber *)reactTag;
/**
* Gets the shadow view associated with a reactTag.
*/
- (RCTShadowView *)shadowViewForReactTag:(NSNumber *)reactTag;
/**
* Set the available size (`availableSize` property) for a root view.
* This might be used in response to changes in external layout constraints.
* This value will be directly trasmitted to layout engine and defines how big viewport is;
* this value does not affect root node size style properties.
* Can be considered as something similar to `setSize:forView:` but applicable only for root view.
*/
- (void)setAvailableSize:(CGSize)availableSize forRootView:(UIView *)rootView;
/**
* Set the size of a view. This might be in response to a screen rotation
* or some other layout event outside of the React-managed view hierarchy.
*/
- (void)setSize:(CGSize)size forView:(UIView *)view;
/**
* Set the natural size of a view, which is used when no explicit size is set.
* Use `UIViewNoIntrinsicMetric` to ignore a dimension.
* The `size` must NOT include padding and border.
*/
- (void)setIntrinsicContentSize:(CGSize)size forView:(UIView *)view;
/**
* Update the background color of a view. The source of truth for
* backgroundColor is the shadow view, so if to update backgroundColor from
* native code you will need to call this method.
*/
- (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view;
/**
* Schedule a block to be executed on the UI thread. Useful if you need to execute
* view logic after all currently queued view updates have completed.
*/
- (void)addUIBlock:(RCTViewManagerUIBlock)block;
/**
* Schedule a block to be executed on the UI thread. Useful if you need to execute
* view logic before all currently queued view updates have completed.
*/
- (void)prependUIBlock:(RCTViewManagerUIBlock)block;
/**
* Used by native animated module to bypass the process of updating the values through the shadow
* view hierarchy. This method will directly update native views, which means that updates for
* layout-related propertied won't be handled properly.
* Make sure you know what you're doing before calling this method :)
*/
- (void)synchronouslyUpdateViewOnUIThread:(NSNumber *)reactTag
viewName:(NSString *)viewName
props:(NSDictionary *)props;
/**
* Given a reactTag from a component, find its root view, if possible.
* Otherwise, this will give back nil.
*
* @param reactTag the component tag
* @param completion the completion block that will hand over the rootView, if any.
*
*/
- (void)rootViewForReactTag:(NSNumber *)reactTag withCompletion:(void (^)(UIView *view))completion;
/**
* Finds a view that is tagged with {@param nativeId} as its nativeID prop
* with the associated {@param rootTag} root tag view hierarchy. Returns the
* view if found, nil otherwise.
*
* @param nativeID the id reference to native component relative to root view.
* @param rootTag the react tag of root view hierarchy from which to find the view.
*/
- (UIView *)viewForNativeID:(NSString *)nativeID withRootTag:(NSNumber *)rootTag;
/**
* The view that is currently first responder, according to the JS context.
*/
+ (UIView *)JSResponder;
/**
* Normally, UI changes are not applied until the complete batch of method
* invocations from JavaScript to native has completed.
*
* Setting this to YES will flush UI changes sooner, which could potentially
* result in inconsistent UI updates.
*
* The default is NO (recommended).
*/
@property (atomic, assign) BOOL unsafeFlushUIChangesBeforeBatchEnds;
/**
* In some cases we might want to trigger layout from native side.
* React won't be aware of this, so we need to make sure it happens.
*/
- (void)setNeedsLayout;
/**
* Dedicated object for subscribing for UIManager events.
* See `RCTUIManagerObserver` protocol for more details.
*/
@property (atomic, retain, readonly) RCTUIManagerObserverCoordinator *observerCoordinator;
@end
@interface RCTUIManager (Deprecated)
/**
* This method is deprecated and will be removed in next releases.
* Use `setSize:forView:` or `setIntrinsicContentSize:forView:` instead.
* Only frames with `origin` equals {0, 0} are supported.
*/
- (void)setFrame:(CGRect)frame forView:(UIView *)view
__deprecated_msg("Use `setSize:forView:` or `setIntrinsicContentSize:forView:` instead.");
/**
* This method is deprecated and will be removed in next releases.
* Use `registerRootView:` instead. There is no need to specify `sizeFlexibility` anymore.
*/
- (void)registerRootView:(UIView *)rootView withSizeFlexibility:(RCTRootViewSizeFlexibility)sizeFlexibility
__deprecated_msg("Use `registerRootView:` instead.");
@end
/**
* This category makes the current RCTUIManager instance available via the
* RCTBridge, which is useful for RCTBridgeModules or RCTViewManagers that
* need to access the RCTUIManager.
*/
@interface RCTBridge (RCTUIManager)
@property (nonatomic, readonly) RCTUIManager *uiManager;
@end