WXComponentManager.h
7.46 KB
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#import <CoreGraphics/CoreGraphics.h>
#import <Foundation/Foundation.h>
#import "WXDisplayLinkManager.h"
@class WXBridgeMethod;
@class WXSDKInstance;
@class WXComponent;
#ifdef __cplusplus
extern "C" {
#endif
void WXPerformBlockOnComponentThread(void (^block)(void));
void WXPerformBlockSyncOnComponentThread(void (^block)(void));
#ifdef __cplusplus
}
#endif
@interface WXComponentManager : NSObject <WXDisplayLinkClient>
@property (nonatomic, readonly, weak) WXSDKInstance *weexInstance;
@property (nonatomic, readonly, assign) BOOL isValid;
/**
* @abstract initialize with weex instance
**/
- (instancetype)initWithWeexInstance:(WXSDKInstance *)weexInstance;
/**
* @abstract return the component thread
**/
+ (NSThread *)componentThread;
/**
* @abstract starting component tasks
**/
- (void)startComponentTasks;
/**
* @abstract tell the component manager that instance root view's frame has been changed
**/
- (void)rootViewFrameDidChange:(CGRect)frame;
///--------------------------------------
/// @name Component Tree Building
///--------------------------------------
/**
* @abstract create root component
**/
- (void)createBody:(NSString*)ref
type:(NSString*)type
styles:(NSDictionary*)styles
attributes:(NSDictionary*)attributes
events:(NSArray*)events
renderObject:(void*)renderObject;
/**
* @abstract add a component to its parent
**/
- (void)addComponent:(NSString*)ref
type:(NSString*)type
parentRef:(NSString*)parentRef
styles:(NSDictionary*)styles
attributes:(NSDictionary*)attributes
events:(NSArray*)events
index:(NSInteger)index
renderObject:(void*)renderObject;
/**
* @abstract move component
**/
- (void)moveComponent:(NSString *)ref toSuper:(NSString *)superRef atIndex:(NSInteger)index;
/**
* @abstract remove component
**/
- (void)removeComponent:(NSString *)ref;
/**
* @abstract notify that a component tree is built and trigger layout,
may be called several times rendering a page.
**/
- (void)appendTreeCreateFinish:(NSString*)ref;
/**
* @abstract return component for specific ref, must be called on component thread by calling WXPerformBlockOnComponentThread
*/
- (WXComponent *)componentForRef:(NSString *)ref;
/**
* @abstract return root component
*/
- (WXComponent *)componentForRoot;
/**
* @abstract number of components created, must be called on component thread by calling WXPerformBlockOnComponentThread
*/
- (NSUInteger)numberOfComponents;
/**
* @abstract add an existing component to references look-up map
*/
- (void)addComponent:(WXComponent *)component toIndexDictForRef:(NSString *)ref;
///--------------------------------------
/// @name Updating
///--------------------------------------
/**
* @abstract update styles
**/
- (void)updateStyles:(NSDictionary *)styles forComponent:(NSString *)ref;
/**
* @abstract update pseudo class styles
**/
- (void)updatePseudoClassStyles:(NSDictionary *)styles forComponent:(NSString *)ref;
/**
* @abstract update attributes
**/
- (void)updateAttributes:(NSDictionary *)attributes forComponent:(NSString *)ref;
/**
* @abstract quick check that if a component has non transition properties
**/
- (BOOL)isTransitionNoneOfComponent:(NSString*)ref; // for quick access
/**
* @abstract check if component with @ref has any style in @styles which is animated
**/
- (BOOL)hasTransitionPropertyInStyles:(NSDictionary*)styles forComponent:(NSString*)ref;
/**
* @abstract layout a component with frame output by weex core layout engine
**/
- (void)layoutComponent:(WXComponent*)component frame:(CGRect)frame isRTL:(BOOL)isRTL innerMainSize:(CGFloat)innerMainSize;
/**
* @abstract layout a component on platform side
**/
- (void)layoutComponent:(WXComponent*)component;
/**
* @abstract add event
**/
- (void)addEvent:(NSString *)event toComponent:(NSString *)ref;
/**
* @abstract remove event
**/
- (void)removeEvent:(NSString *)event fromComponent:(NSString *)ref;
/**
* @abstract scroll to specific component
**/
- (void)scrollToComponent:(NSString *)ref options:(NSDictionary *)options;
///--------------------------------------
/// @name Life Cycle
///--------------------------------------
/**
* @abstract called when all doms are created
**/
- (void)createFinish;
/**
* @abstract called when all doms are refreshed
**/
- (void)refreshFinish;
/**
* @abstract called when all doms are updated
**/
- (void)updateFinish;
/**
* @abstract called when all doms are created and layout finished
**/
- (void)renderFinish;
/**
* @abstract called when render failed
**/
- (void)renderFailed:(NSError *)error;
/**
* @abstract unload
**/
- (void)unload;
/**
* @abstract invalidate component management, this can be called on main thread.
**/
- (void)invalidate;
///--------------------------------------
/// @name Fixed
///--------------------------------------
/**
* @abstract add a component which has a fixed position
*
* @param fixComponent the fixed component to add
*/
- (void)addFixedComponent:(WXComponent *)fixComponent;
/**
* @abstract remove a component which has a fixed position
*
* @param fixComponent the fixed component to remove
*/
- (void)removeFixedComponent:(WXComponent *)fixComponent;
/**
* @abstract add a task to UI thread
**/
- (void)_addUITask:(void (^)(void))block;
/**
* @abstract execute a task to UI thread
**/
- (void)executePrerenderUITask:(NSString *)url;
/**
* @param styles a NSDictionary value, styles which will resolve
* @param component a WXComponent value, the target which you want to resolve
* @param isUpdateStyles a BOOL value, YES will udpate the component style property, NO will notifiy the lifeStyle of compoenent to handle, default value is NO.
* @abstract handleStyle will be add to a queue to be executed every frame, but handleStyleOnMainThread will switch to main thread and execute imediately, you can call this for your execution time sequence.
*/
- (void)handleStyleOnMainThread:(NSDictionary*)styles forComponent:(WXComponent *)component isUpdateStyles:(BOOL)isUpdateStyles;
///--------------------------------------
/// @name Enumerating
///--------------------------------------
/**
* Enumerate components using breadth-first search algorithm,
must be called on component thread by calling WXPerformBlockOnComponentThread
*/
- (void)enumerateComponentsUsingBlock:(void (^)(WXComponent *, BOOL *stop))block;
#pragma mark batch mark
/**
a start native batch tag for a group of UI operations, company with performBatchEnd
@see performBatchEnd
*/
- (void)performBatchBegin;
/**
an end native batch tag for a group of UI operations, company with performBatchBegin
@see performBatchBegin
*/
- (void)performBatchEnd;
@end