// // QXUserGiftWallView.m // QXLive // // Created by 启星 on 2025/5/21. // #import "QXUserGiftWallView.h" #import "QXGiftCell.h" #import "QXMineNetwork.h" @interface QXUserGiftWallView() @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView); @property (nonatomic, strong) NSMutableArray* dataArray; @end @implementation QXUserGiftWallView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake((SCREEN_WIDTH-16*2-12*3)/4, ScaleWidth(119)); layout.minimumLineSpacing = 12; layout.minimumInteritemSpacing = 12; layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16); layout.scrollDirection = UICollectionViewScrollDirectionVertical; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; [self.collectionView registerNib:[UINib nibWithNibName:@"QXGiftCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXGiftCell"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsHorizontalScrollIndicator = NO; self.collectionView.bounces = NO; self.collectionView.pagingEnabled = NO; self.collectionView.backgroundColor = RGB16(0xf6f6f6); [self addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(12); make.top.mas_equalTo(12); make.height.mas_equalTo(ScaleWidth(76)); make.right.mas_equalTo(-12); }]; } return self; } - (instancetype)initWithOffsetY:(CGFloat)offsety { self = [self initWithFrame:CGRectZero]; self.collectionView.contentOffset = CGPointMake(0, offsety); return self; } - (void)layoutSubviews { [super layoutSubviews]; self.collectionView.frame = self.bounds; } -(void)setUser_id:(NSString *)user_id{ _user_id = user_id; [self getGiftWall]; } -(void)getGiftWall{ MJWeakSelf [QXMineNetwork userGiftWallithUserId:self.user_id successBlock:^(NSArray * _Nonnull lightList, NSArray * _Nonnull grayList) { [weakSelf.dataArray removeAllObjects]; [weakSelf.dataArray addObjectsFromArray:lightList]; [weakSelf.dataArray addObjectsFromArray:grayList]; [weakSelf.collectionView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } #pragma mark - UITableViewDataSource, UITableViewDelegate -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.dataArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXGiftCell" forIndexPath:indexPath]; cell.cellType = QXGiftCellTypeGiftWall; cell.giftWall = self.dataArray[indexPath.row]; return cell; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (self.scrollCallback != nil) { self.scrollCallback(scrollView); } if (self.listScrollCallback != nil) { self.listScrollCallback(scrollView); } } #pragma mark - JXPagingViewListViewDelegate - (UIScrollView *)listScrollView { return self.collectionView; } - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback { self.scrollCallback = callback; } - (UIView *)listView { return self; } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } @end