英文 | 扩展阅读 | Extended Reading |
HybridPageKit是一个针对新闻类App高性能、易扩展、组件化的通用内容页实现框架。
基于扩展阅读中关于内容页架构和性能的探索。
//In your Podfile
pod "HybridPageKit", :testspecs => ["HybridPageKitTests"]
...
//In your Cartfile
git "https://github.com/dequan1331/HybridPageKit.git" "master"
强烈建议阅读[iOS新闻类App内容页技术探索](https://dequan1331.github.io/)
{
//内容HTML
"articleContent": "<!DOCTYPE html><html><head></head><body><P>TEXTTEXTTEXTTEXTTEXTTEXT</P><P></P><P>TEXTTEXTTEXTTEXTTEXTTEXT</P><P></P><P>TEXTTEXTTEXTTEXTTEXTTEXT</P><P></P><P>The End</P></body></html>",
//内容HTML中的非文字组件数据
"articleAttributes": {
"IMG_0": {
"url": "http://127.0.0.1:8080?type=3",
"width": "340",
"height": "200"
},
"IMG_1": {
"url": "http://127.0.0.1:8080?type=3",
"width": "340",
"height": "200"
},
"IMG_2": {
"url": "http://127.0.0.1:8080?type=3",
"width": "340",
"height": "200"
},
},
//扩展区域中的组件数据
"articleRelateNews": {
"index":"1",
"newsArray" : [
"扩展阅读区 - RelateNews - 1",
"扩展阅读区 - RelateNews - 2",
"扩展阅读区 - RelateNews - 3",
"扩展阅读区 - RelateNews - 4",
],
},
//扩展区域中的组件数据
"articleComment": {
"index":"2",
"commentArray" : [
"相关评论区 - Comment - 1",
"相关评论区 - Comment - 2",
"相关评论区 - Comment - 3",
"相关评论区 - Comment - 4",
],
},
}
//Model实现HPKModelProtocol协议
@interface VideoModel : NSObject<HPKModelProtocol>
...
IMP_HPKModelProtocol(@"");
//View实现HPKModelProtocol协议
@interface VideoView : UIImageView<HPKViewProtocol>
...
IMP_HPKViewProtocol()
@interface VideoController : NSObject<HPKControllerProtocol>
...
- (nullable NSArray<Class> *)supportComponentModelClass {
return @[[VideoModel class]];
}
...
- (nullable Class)reusableComponentViewClassWithModel:(HPKModel *)componentModel {
return [VideoView class];
}
...
- (void)scrollViewWillDisplayComponentView:(HPKView *)componentView
componentModel:(HPKModel *)componentModel {
...
}
- (void)controllerViewDidDisappear {
...
}
...
_componentHandler = [[HPKPageHandler alloc] initWithViewController:self componentsControllers:@[VideoController ...];
...
[_componentHandler handleSingleScrollView:[[UIScrollView alloc] initWithFrame:self.view.bounds]];
...
[_componentHandler layoutWithComponentModels:@[VideoModel ...]];
...
// in page viewController
...
_componentHandler = [[HPKPageHandler alloc] initWithViewController:self componentsControllers:@[VideoController ...];
...
[_componentHandler handleHybridPageWithContainerScrollView:[[UIScrollView alloc] initWithFrame:self.view.bounds] defaultWebViewClass:[HPKWebViewSubClass class] defaultWebViewIndex:1 webComponentDomClass:@"domClass" webComponentIndexKey:@"domAttrIndex"];
...
[_componentHandler layoutWithWebComponentModels:@[WebVideoModel ...]];
...
[_componentHandler layoutWithComponentModels:@[VideoModel ...];
...
All source code is licensed under the MIT License.