Skip to content

Commit

Permalink
增加复用list的功能列表
Browse files Browse the repository at this point in the history
  • Loading branch information
jingcheng1988 committed Sep 13, 2022
1 parent 1d8f2a7 commit c8c4dc7
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 6 deletions.
Binary file not shown.
16 changes: 14 additions & 2 deletions GaiaXiOSDemo/GaiaXiOSDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
8D5D29AE276AD6A1005FD699 /* recommend.json in Resources */ = {isa = PBXBuildFile; fileRef = 8D5D29A9276AD6A1005FD699 /* recommend.json */; };
8D5D29AF276AD6A1005FD699 /* uper-top.json in Resources */ = {isa = PBXBuildFile; fileRef = 8D5D29AA276AD6A1005FD699 /* uper-top.json */; };
8D5D29B0276AD6A1005FD699 /* uper.json in Resources */ = {isa = PBXBuildFile; fileRef = 8D5D29AB276AD6A1005FD699 /* uper.json */; };
8D7570F828D0AF2A004AF92D /* RecycleListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7570F528D0AF2A004AF92D /* RecycleListViewController.m */; };
8D7570F928D0AF2A004AF92D /* RecycleTemplateListCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D7570F728D0AF2A004AF92D /* RecycleTemplateListCell.m */; };
8D88D4C22788349F004F1614 /* GaiaXJSONRPCConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D88D4C12788349F004F1614 /* GaiaXJSONRPCConstants.m */; };
8D88D4C5278834AF004F1614 /* GaiaXSocketRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D88D4C3278834AF004F1614 /* GaiaXSocketRequest.m */; };
8D88D4C927883574004F1614 /* GaiaXPreviewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D88D4C827883574004F1614 /* GaiaXPreviewViewController.m */; };
Expand Down Expand Up @@ -72,6 +74,10 @@
8D5D29AA276AD6A1005FD699 /* uper-top.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "uper-top.json"; sourceTree = "<group>"; };
8D5D29AB276AD6A1005FD699 /* uper.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = uper.json; sourceTree = "<group>"; };
8D678A4628066EC40036A7D0 /* GaiaXiOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = GaiaXiOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8D7570F428D0AF29004AF92D /* RecycleListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecycleListViewController.h; sourceTree = "<group>"; };
8D7570F528D0AF2A004AF92D /* RecycleListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RecycleListViewController.m; sourceTree = "<group>"; };
8D7570F628D0AF2A004AF92D /* RecycleTemplateListCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecycleTemplateListCell.h; sourceTree = "<group>"; };
8D7570F728D0AF2A004AF92D /* RecycleTemplateListCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RecycleTemplateListCell.m; sourceTree = "<group>"; };
8D88D4C02788349F004F1614 /* GaiaXJSONRPCConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GaiaXJSONRPCConstants.h; sourceTree = "<group>"; };
8D88D4C12788349F004F1614 /* GaiaXJSONRPCConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GaiaXJSONRPCConstants.m; sourceTree = "<group>"; };
8D88D4C3278834AF004F1614 /* GaiaXSocketRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GaiaXSocketRequest.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -141,6 +147,10 @@
8D57F1D627733F0B00FF8CC3 /* ListViewController.m */,
8D57F1D82773412700FF8CC3 /* TemplateListCell.h */,
8D57F1D92773412700FF8CC3 /* TemplateListCell.m */,
8D7570F428D0AF29004AF92D /* RecycleListViewController.h */,
8D7570F528D0AF2A004AF92D /* RecycleListViewController.m */,
8D7570F628D0AF2A004AF92D /* RecycleTemplateListCell.h */,
8D7570F728D0AF2A004AF92D /* RecycleTemplateListCell.m */,
);
path = Render;
sourceTree = "<group>";
Expand Down Expand Up @@ -384,6 +394,8 @@
files = (
8D88D4C22788349F004F1614 /* GaiaXJSONRPCConstants.m in Sources */,
8D2180E12771AAA5001401C8 /* NestViewController.m in Sources */,
8D7570F828D0AF2A004AF92D /* RecycleListViewController.m in Sources */,
8D7570F928D0AF2A004AF92D /* RecycleTemplateListCell.m in Sources */,
8D88D4C927883574004F1614 /* GaiaXPreviewViewController.m in Sources */,
8DB52186275A0DCF00EB8126 /* ViewController.m in Sources */,
8D57F1DA2773412700FF8CC3 /* TemplateListCell.m in Sources */,
Expand Down Expand Up @@ -620,7 +632,7 @@
"-weak_framework",
"\"XCTest\"",
);
PRODUCT_BUNDLE_IDENTIFIER = com.alibaba.GaiaXiOSDemo.zjc1;
PRODUCT_BUNDLE_IDENTIFIER = com.alibaba.GaiaXiOSDemo.zjc1233;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "GaiaXiOSDemo/GaiaXiOSDemo-Bridging-Header.h";
Expand Down Expand Up @@ -688,7 +700,7 @@
"-weak_framework",
"\"XCTest\"",
);
PRODUCT_BUNDLE_IDENTIFIER = com.alibaba.GaiaXiOSDemo.zjc1;
PRODUCT_BUNDLE_IDENTIFIER = com.alibaba.GaiaXiOSDemo.zjc1233;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OBJC_BRIDGING_HEADER = "GaiaXiOSDemo/GaiaXiOSDemo-Bridging-Header.h";
Expand Down
Binary file not shown.
27 changes: 27 additions & 0 deletions GaiaXiOSDemo/GaiaXiOSDemo/Render/RecycleListViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// RecycleListViewController.h
// GaiaXiOSDemo
//
// Copyright (c) 2021, Alibaba Group Holding Limited.
//
// Licensed 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 <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface RecycleListViewController : UIViewController

@end

NS_ASSUME_NONNULL_END
131 changes: 131 additions & 0 deletions GaiaXiOSDemo/GaiaXiOSDemo/Render/RecycleListViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// RecycleListViewController.m
// GaiaXiOSDemo
//
// Copyright (c) 2021, Alibaba Group Holding Limited.
//
// Licensed 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 "RecycleListViewController.h"
#import <GaiaXiOS/GaiaXiOS.h>
#import "GaiaXHelper.h"
#import "RecycleTemplateListCell.h"

@interface RecycleListViewController ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>{
CGFloat _itemWidth;
}

@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) NSMutableArray *heights;
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation RecycleListViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.collectionView];
_itemWidth = self.view.frame.size.width;

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//处理数据
[self processTemplateInfo];

dispatch_async(dispatch_get_main_queue(), ^{
//刷新UI
[self.collectionView reloadData];
});
});
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.dataArray.count;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = [self.heights[indexPath.item] floatValue];
return CGSizeMake(_itemWidth, height);
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
//重用标识
RecycleTemplateListCell *cell = (RecycleTemplateListCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

//数据绑定
GXTemplateData *data = [self.dataArray objectAtIndex:indexPath.item];
[cell setupData:data];

return cell;
}


#pragma mark - data

- (void)processTemplateInfo{
GXTemplateItem *item = [[GXTemplateItem alloc] init];
item.templateId = @"gx-subscribe-item";
item.bizId = [GaiaXHelper bizId];


for (int i = 0; i < 10; i++) {
//data
GXTemplateData *data = [[GXTemplateData alloc] init];
data.data = [GaiaXHelper jsonWithFileName:@"subscribe-item"];

//高度
CGFloat height = [TheGXTemplateEngine sizeWithTemplateItem:item measureSize:CGSizeMake(_itemWidth, NAN) data:data].height;
[self.heights addObject:@(height)];

//data
[self.dataArray addObject:data];
}
}

#pragma mark - lazy load

- (UICollectionView *)collectionView{
if (!_collectionView) {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
flowLayout.minimumInteritemSpacing = 10;

_collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:RecycleTemplateListCell.class forCellWithReuseIdentifier:@"cell"];
}
return _collectionView;
}

- (NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}

- (NSMutableArray *)heights{
if (!_heights) {
_heights = [NSMutableArray array];
}
return _heights;
}


@end
32 changes: 32 additions & 0 deletions GaiaXiOSDemo/GaiaXiOSDemo/Render/RecycleTemplateListCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// RecycleTemplateListCell.h
// GaiaXiOSDemo
//
// Copyright (c) 2021, Alibaba Group Holding Limited.
//
// Licensed 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 <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@class GXTemplateData;
@interface RecycleTemplateListCell : UICollectionViewCell

@property (nonatomic, strong) UIView *templateView;

- (void)setupData:(GXTemplateData *)data;

@end

NS_ASSUME_NONNULL_END
43 changes: 43 additions & 0 deletions GaiaXiOSDemo/GaiaXiOSDemo/Render/RecycleTemplateListCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// RecycleTemplateListCell.m
// GaiaXiOSDemo
//
// Copyright (c) 2021, Alibaba Group Holding Limited.
//
// Licensed 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 "RecycleTemplateListCell.h"
#import <GaiaXiOS/GaiaXiOS.h>
#import "GaiaXHelper.h"


@implementation RecycleTemplateListCell

- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
GXTemplateItem *item = [[GXTemplateItem alloc] init];
item.templateId = @"gx-subscribe-item";
item.bizId = [GaiaXHelper bizId];
_templateView = [TheGXTemplateEngine creatViewByTemplateItem:item measureSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, NAN)];
[self.contentView addSubview:_templateView];
}
return self;
}

- (void)setupData:(GXTemplateData *)data{
//绑定数据
[TheGXTemplateEngine bindData:data onView:_templateView];
_templateView.backgroundColor = [UIColor greenColor];
}

@end
11 changes: 9 additions & 2 deletions GaiaXiOSDemo/GaiaXiOSDemo/Resource/en.lproj/FunctionList.plist
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@
<string>EventViewController</string>
</dict>
<dict>
<key>New item</key>
<dict>
<key>title</key>
<string>Template List</string>
<key>class</key>
<string>ListViewController</string>
</dict>
<key>title</key>
<string>Template List</string>
<string>Recycle Template List</string>
<key>class</key>
<string>ListViewController</string>
<string>RecycleListViewController</string>
</dict>
</array>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@
<string>EventViewController</string>
</dict>
<dict>
<key>New item</key>
<dict>
<key>title</key>
<string>模板列表</string>
<key>class</key>
<string>ListViewController</string>
</dict>
<key>title</key>
<string>模板列表</string>
<string>复用模板列表</string>
<key>class</key>
<string>ListViewController</string>
<string>RecycleListViewController</string>
</dict>
</array>
</plist>

0 comments on commit c8c4dc7

Please sign in to comment.