123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- //
- // YMPersonalPageGiftWallView.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/14.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMPersonalPageGiftWallView.h"
- #import "YMPersonalPageViewModel.h"
- #import "YMPersonalPageGiftWallCell.h"
- #import "CHTCollectionViewWaterfallLayout.h"
- @interface YMPersonalPageGiftWallView ()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout,CHTCollectionViewDelegateWaterfallLayout>
- /// 个人主页VM
- @property (nonatomic, strong) YMPersonalPageViewModel *viewModel;
- /// 个人主页礼物墙标签
- @property (nonatomic, strong) UILabel *personalPageGiftWallLb;
- /// 动态排版
- @property (nonatomic, strong) CHTCollectionViewWaterfallLayout *giftWallLayout;
- /// 动态容器列表
- @property (nonatomic, strong) UICollectionView *giftWallCollectionView;
- @end
- @implementation YMPersonalPageGiftWallView
- - (void)ym_setupViews{
-
- [self addSubview:self.personalPageGiftWallLb];
- [self addSubview:self.giftWallCollectionView];
- [self setNeedsUpdateConstraints];
- [self updateConstraintsIfNeeded];
- }
- - (void)updateConstraints{
-
- [self.personalPageGiftWallLb mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self).offset(adapt(10));
- make.left.equalTo(self).offset(adapt(20));
- }];
-
- [self.giftWallCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.personalPageGiftWallLb.mas_bottom).offset(adapt(20));
- make.left.equalTo(self).offset(adapt(20));
- make.right.equalTo(self).offset(adapt(-20));
- make.bottom.equalTo(self).offset(adapt(-10));
- }];
-
- [super updateConstraints];
- }
- - (void)ym_bindViewModel:(YMPersonalPageViewModel *)viewModel{
- if (!viewModel) {
- return;
- }
-
- _viewModel = viewModel;
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.giftWallCollectionView reloadData];
- [self.giftWallCollectionView layoutIfNeeded];
- //刷新高度
- CGFloat giftWallCollectionViewHeight = self.giftWallCollectionView.collectionViewLayout.collectionViewContentSize.height;
- [self.giftWallCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(giftWallCollectionViewHeight);
- }];
- }];
-
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.viewModel.giftWallDataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- YMPersonalPageGiftWallCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YMPersonalPageGiftWallCell class]) forIndexPath:indexPath];
- [cell ym_bindViewModel:self.viewModel.giftWallDataArray[indexPath.item]];
- return cell;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
- UICollectionReusableView *reusableView = nil;
- reusableView.backgroundColor = [UIColor clearColor];
- return reusableView;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
- return CGSizeZero;
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
- return CGSizeZero;
- }
- #pragma mark - UICollectionViewDelegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
-
- }
- #pragma mark - CHTCollectionViewDelegateWaterfallLayout
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake(adapt(60), adapt(100));
- }
- - (UILabel *)personalPageGiftWallLb{
- if (!_personalPageGiftWallLb) {
- _personalPageGiftWallLb = [[UILabel alloc]init];
- _personalPageGiftWallLb.font = LCBoldFont(17);
- _personalPageGiftWallLb.textColor = HexColorFromRGB(0x000000);
- _personalPageGiftWallLb.textAlignment = NSTextAlignmentLeft;
- _personalPageGiftWallLb.text = @"TA的礼物";
- }
- return _personalPageGiftWallLb;
- }
- - (CHTCollectionViewWaterfallLayout *)giftWallLayout{
- if (!_giftWallLayout) {
- _giftWallLayout = [[CHTCollectionViewWaterfallLayout alloc] init];
- _giftWallLayout.columnCount = 5;
- _giftWallLayout.sectionInset = UIEdgeInsetsZero;
- }
- return _giftWallLayout;
- }
- - (UICollectionView *)giftWallCollectionView{
- if (!_giftWallCollectionView) {
- _giftWallCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.giftWallLayout];
- _giftWallCollectionView.delegate = self;
- _giftWallCollectionView.dataSource = self;
- _giftWallCollectionView.userInteractionEnabled = NO;
- _giftWallCollectionView.showsVerticalScrollIndicator = NO;
- _giftWallCollectionView.showsHorizontalScrollIndicator = NO;
- _giftWallCollectionView.backgroundColor = UIColor.whiteColor;
- [_giftWallCollectionView registerClass:[YMPersonalPageGiftWallCell class] forCellWithReuseIdentifier:NSStringFromClass([YMPersonalPageGiftWallCell class])];
- }
- return _giftWallCollectionView;
- }
- @end
|