-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jingcheng1988
committed
Sep 13, 2022
1 parent
1d8f2a7
commit c8c4dc7
Showing
9 changed files
with
265 additions
and
6 deletions.
There are no files selected for viewing
Binary file modified
BIN
+1.71 KB
(100%)
GaiaXiOS/GaiaXiOS.xcworkspace/xcuserdata/zhangjc.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+29.4 KB
(100%)
...mo/GaiaXiOSDemo.xcworkspace/xcuserdata/zhangjc.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
27 changes: 27 additions & 0 deletions
27
GaiaXiOSDemo/GaiaXiOSDemo/Render/RecycleListViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
131
GaiaXiOSDemo/GaiaXiOSDemo/Render/RecycleListViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
GaiaXiOSDemo/GaiaXiOSDemo/Render/RecycleTemplateListCell.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
43
GaiaXiOSDemo/GaiaXiOSDemo/Render/RecycleTemplateListCell.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters