BBASMComponent.h
12 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
//
// BBASMPageViewControllerProtocol.h
// BBAMNP
//
// Created by baidu on 2019/1/29.
//
#import <Foundation/Foundation.h>
#import "BBASMComponentTouchDelegate.h"
NS_ASSUME_NONNULL_BEGIN
@protocol BBASMRenderBaseViewControllerProtocol, BBASMRenderBaseControllerUIProtocol, BBASMComponentManagerProtocol, BBAFullscreenPopGestureProtocol, BBASMSlaveWebViewControllerProtocol;
/**
* SWAN Page Container
*/
# define BBASMPageContainer UIViewController <BBASMRenderBaseViewControllerProtocol, BBASMRenderBaseControllerUIProtocol, BBASMComponentManagerProtocol>
/**
*
* SWAN Page Container Lifecycle Delegate
*/
@protocol BBASMPageLifeCycleDelegate
@optional
/**
* @brief Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set
* @param BBASMPage SWAN Page Container
*/
- (void)mPageViewDidLoad:(BBASMPageContainer *)BBASMPage;
/**
* @brief Called when the view is about to made visible. Default does nothing
* @param BBASMPage SWAN Page Container
* @param animated Transparent pass viewController parameter animated
*/
- (void)BBASMPage:(BBASMPageContainer *)BBASMPage viewWillAppear:(BOOL)animated;
/**
* @brief Called when the view has been fully transitioned onto the screen. Default does nothing
* Equivalent BBASMSlaveWebViewControllerViewDidAppear notication
* @param BBASMPage SWAN Page Container
* @param animated Transparent pass viewController parameter animated
*/
- (void)BBASMPage:(BBASMPageContainer *)BBASMPage viewDidAppear:(BOOL)animated;
/**
* @brief Called when the view is dismissed, covered or otherwise hidden. Default does nothing
* Equivalent BBASMSlaveWebViewControllerViewWillDisappear notication
* @param BBASMPage SWAN Page Container
* @param animated Transparent pass viewController parameter animated
*/
- (void)BBASMPage:(BBASMPageContainer *)BBASMPage viewWillDisappear:(BOOL)animated;
/**
* @brief Called after the view was dismissed, covered or otherwise hidden. Default does nothing
* @param BBASMPage SWAN Page Container
* @param animated Transparent pass viewController parameter animated
*/
- (void)BBASMPage:(BBASMPageContainer *)BBASMPage viewDidDisappear:(BOOL)animated;
/**
* @brief Called just before the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a nop.
* @param BBASMPage SWAN Page Container
*/
- (void)smPageViewWillLayoutSubviews:(BBASMPageContainer *)BBASMPage;
/**
* @brief alled just after the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a nop.
* @param BBASMPage SWAN Page Container
*/
- (void)smPageViewDidLayoutSubviews:(BBASMPageContainer *)BBASMPage;
/**
* @brief Called when the parent application receives a memory warning. On iOS 6.0 it will no longer clear the view by default.
*
* @param BBASMPage SWAN Page Container
*/
- (void)smPageDidReceiveMemoryWarning:(BBASMPageContainer *)BBASMPage;
/**
* @brief Called when the viewCtroller's back method is invoked
*
* @param BBASMPage SWAN Page Container
*/
- (void)bbasmPageBack:(BBASMPageContainer *)BBASMPage;
/**
* @brief Called when som specially dom's node updateed
*
* @param BBASMPage BBASMPage
* @param nodeId nodeId
*/
- (void)smPage:(BBASMPageContainer *)BBASMPage didUpdateDomNode:(NSString *)nodeId;
/**
* @brief Called when webView's scrollView contentOffset updateed
*
* @param BBASMPage BBASMPage
*/
- (void)didChangeedContentOffset:(BBASMPageContainer *)BBASMPage;
/// @brief Called when webView's scrollView frame changed
/// @param page BBASMPage
/// @param isLandspace isLandspace
- (void)page:(BBASMPageContainer *)page didChangeedFrame:(BOOL)isLandspace;
@end
@protocol BBASMPageRotationProtocol <NSObject>
@optional
/**
* @brief Transparently pass the ViewController method - (BOOL)shouldAutorotate call
*
* @param BBASMPage SWAN Page Container
* @return YES Support autorotate
*/
- (BOOL)pageShouldAutorotate:(BBASMPageContainer *)BBASMPage;
/**
* @brief Transparently pass the ViewController method - (UIInterfaceOrientationMask)supportedInterfaceOrientations call
*
* @param BBASMPage SWAN Page Container
* @return UIInterfaceOrientationMask
*/
- (UIInterfaceOrientationMask)pageSupportedInterfaceOrientations:(BBASMPageContainer *)BBASMPage;
/**
* This method is called when the view controller's view's size is changed by its parent (i.e. for the root view controller when its window rotates or is resized).
* If you override this method, you should either call super to propagate the change to children or manually forward the change to children.
*/
- (void)BBASMPage:(BBASMPageContainer *)BBASMPage viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);
@end
@protocol BBASMPageLayoutSupportProtocol <NSObject>
@optional
/**
* Transparently pass the ViewController method - (void)viewSafeAreaInsetsDidChange call
*/
- (void)bbasmPageViewSafeAreaInsetsDidChange:(BBASMPageContainer *)BBASMPage API_AVAILABLE(ios(11.0), tvos(11.0));
@end
@class WKWebView;
/**
* Touch
*/
@protocol BBASMPageTouchProtocol <NSObject>
@optional
/**
* @brief Transparently pass the view method - hitTest: withEvent: call
*
* @param BBASMPage BBASMPage
* @param webView webView
* @param point point
* @param event event
* @param view webView hitTest返回的view
* @return view
*/
- (UIView *)BBASMPage:(BBASMPageContainer *)BBASMPage
webView:(WKWebView *)webView
hitTest:(CGPoint)point
withEvent:(UIEvent *)event
hitedView:(UIView *)view;
@end
/**
* UIAPPlicationNotification
*/
@protocol BBASMApplicationNotificationProtocol <NSObject>
@optional
/**
* @brief Called when application will enterForeground
*
* @param notification NSNotification
*/
- (void)handleApplicationWillEnterForeground:(NSNotification *)notification;
/**
* @brief Called when application did enterBackground
*
* @param notification NSNotification
*/
- (void)handleApplicationDidEnterBackground:(NSNotification *)notification;
@end
@protocol BBASMNSObjectProtocol <NSObject>
@optional
/**
* @brief Called when the viewCtroller's delloc method is invoked
*
* @param BBASMPage SWAN Page Container
*/
- (void)bbasmPageDealloc:(BBASMPageContainer *)BBASMPage;
@end
@protocol BBASMComponentViewProtocol <NSObject>
@optional
/**
* @brief 清除引用关系
*
*/
- (void)clearReference;
/**
* @brief 父视图frame发生变化
*
*/
- (void)updateFrameIfSuperViewFrameChange;
@end
extern NSString * const kBBASMComponentInfoKeyGesture;
@protocol BBASMComponentInfoProtocol <NSObject>
/// frame
@property (assign, nonatomic) CGRect frame;
/// slaveId
@property (copy, nonatomic) NSString *slaveId;
/// 组件Id
@property (copy, nonatomic) NSString *componentId;
/// 组件名称
@property (copy, nonatomic) NSString *componentName;
/// 所属appId
@property (copy, nonatomic) NSString *appId;
/// parentId
@property (copy, nonatomic) NSString *parentId;
/// 是否响应手势 touch longTap
@property (assign, nonatomic) BOOL isEnableGesture;
/// 是否禁止滚动
@property (assign, nonatomic) BOOL isDisableScroll;
@end
@protocol BBASMComponentContainerProtocol <NSObject>
/// 容器ID 前端生成
@property (nonatomic, copy) NSString *containerId;
/// 容器视图 WKWebView 解析div生成的scrollView
@property (nonatomic, weak) UIScrollView *scrollView;
///相对于dom 根节点的frame
@property (nonatomic, assign) CGRect frameRelativeDom;
@end
@protocol BBASMComponentProtocol<NSObject>
@required;
/// 组件信息
@property (strong, nonatomic) id<BBASMComponentInfoProtocol> componentInfo;
///是否需要同层渲染
@property (assign, nonatomic) BOOL needPeerRendering;
/// 是否在dom节点中
@property (nonatomic, assign) BOOL innerWebView;
///根视图
@property (nonatomic, strong) UIView *componentRootView;
///组件视图
@property (nonatomic, strong) UIView<BBASMComponentViewProtocol> *componentView;
///顶层视图
@property (nonatomic, strong) UIView *componentTopView;
///初始父视图
@property (nonatomic, strong) UIView *parentView;
@optional
/**
* @brief 获取当前组件触摸代理对象
*
* @return id<BBASMComponentTouchDelegate>
*/
- (id<BBASMComponentTouchDelegate>)componentTouchInput;
@end
/**
容器上 组件变化协议
*/
@protocol BBASMComponentChangeProtocol<NSObject>
@optional
/**
* @brief 新增组件
*
* @param page 容器
* @param component 组件
*/
- (void)BBASMPage:(BBASMPageContainer *)page didAddComponent:(id<BBASMComponentProtocol>)component;
/**
* @brief 更新组件
*
* @param page 容器
* @param component 组件
*/
- (void)BBASMPage:(BBASMPageContainer *)page didUpdateComponent:(id<BBASMComponentProtocol>)component;
/**
* @brief 删除组件
*
* @param page 容器
* @param componentID 组件id
*/
- (void)BBASMPage:(BBASMPageContainer *)page didRemoveComponent:(NSString *)componentID;
@end
@protocol BBASMContainerViewDelegate <NSObject>
@optional
/**
* @brief 从window上移出
*
* @param aView aView
*/
- (void)didRemoveFromWindow:(UIView *)aView;
- (void)didRemoveFromSuperView:(UIView *)aView;
@end
/**
* SWAN组件
*
* 1个小程序 对应多个SWANViewController 一个SWANViewController可以拥有多个BBASMComponent
*
* 一个SWAN组件应有如下能力:
* 1、能响应viewController的生命周期---BBASMPageLifeCycleDelegate
* 2、能响应全屏右滑返回手势---BBAFullscreenPopGestureProtocol
* 3、能响应BBASMWorkBoxManager的生命周期---BBASMNotificationDef/BBASMApplicationNotificationProtocol
* 4、能响应NSObject类的生命周期---BBASMNSObjectProtocol
* 5、能响应屏幕旋转---BBASMPageRotationProtocol
* 6、能响应自动布局---BBASMPageLayoutSupportProtocol
* 7、能响应容器上组件的改变---BBASMComponentChangeProtocol
*/
#define BBASMComponentProtocols BBASMPageLifeCycleDelegate, \
BBAFullscreenPopGestureProtocol, \
BBASMNSObjectProtocol, \
BBASMComponentProtocol, \
BBASMPageRotationProtocol, \
BBASMPageLayoutSupportProtocol, \
BBASMApplicationNotificationProtocol,\
BBASMComponentChangeProtocol,\
BBASMPageTouchProtocol,\
BBASMContainerViewDelegate
typedef id<BBASMComponentProtocols> BBASMComponent;
/**
* 小程序组件管理协议
*/
@protocol BBASMComponentManagerProtocol <NSObject>
#pragma mark - 组件管理
/**
* @brief 添加组件
*
* @param aComponent 组件实例
* @return YES 添加成功 NO 添加失败
*/
- (BOOL)addBBASMComponent:(BBASMComponent)aComponent;
/**
* @brief 移除组件
*
* @param aComponent aComponent 组件实例
* @return YES 移除成功 NO 移除失败
*/
- (BOOL)removeBBASMComponent:(BBASMComponent)aComponent;
/**
* @brief 根据组件ID移除组件
*
* @param aComponentID 组件ID
* @return YES 移除成功 NO 移除失败
*/
- (BOOL)removeBBASMComponentForID:(NSString *)aComponentID;
/**
* @brief 根据ID 查找 BBASMComponent
*
* @param aComponentID aComponentID 组件ID
* @return 根据ID 查找 BBASMComponent
*/
- (BBASMComponent)BBASMComponent:(NSString *)aComponentID;
/**
* @brief 获取当前页面所有的swan 组件
*
* @return 获取当前页面所有的swan 组件
*/
- (NSArray<BBASMComponent> *)allBBASMComponents;
/**
* @brief 根据容器ID 查找容器
*
* @param containerID 容器ID
* @return 容器
*/
- (nullable id<BBASMComponentContainerProtocol>)containerForID:(NSString *)containerID;
/**
* @brief 保存容器
*
* @param container 容器
* @param containerID containerID
*/
- (void)setContainer:(id<BBASMComponentContainerProtocol>)container
forID:(NSString *)containerID;
/**
* @brief 容器属性发生变化 例如frame
*
* @param containerID containerID
*/
- (void)containerUpdateed:(NSString *)containerID;
/**
* @brief 外部更新组件
*
* @param aComponent 组件
*/
- (void)componentUpdate:(BBASMComponent)aComponent;
/**
* @brief 获取所有的容器
*
* @return NSArray<id<BBASMComponentContainerProtocol>>*
*/
- (NSArray<id<BBASMComponentContainerProtocol>> *)allContainers;
@end
NS_ASSUME_NONNULL_END