瀏覽代碼

fix: 修复包裹面板展开时底部按钮状态不对的问题

陈文艺 5 月之前
父節點
當前提交
dc2d12f139

+ 1 - 1
MiMoLive/Classes/Live/MOShowLiveVC.m

@@ -6463,7 +6463,7 @@ static int mainRTMJoinNum = 0;
     }
     
     [self.liveView.canvasBottomOffset setConstant:offset];
-    [UIView animateWithDuration:0.2 animations:^{
+    [UIView animateWithDuration:0.3 animations:^{
         [self.liveView layoutIfNeeded];
     }];
 }

+ 0 - 3
MiMoLive/Classes/Live/View/LiveingView/GiftListView/MOGiftListBagView/MOBagCollectionView.h

@@ -31,7 +31,6 @@ NS_ASSUME_NONNULL_BEGIN
 @property (nonatomic, assign) NSInteger giftNum;//当前礼物选中的送礼数量
 @property (nonatomic, strong) MOEffect *selectSkin;//当前选中的皮肤
 @property (nonatomic, strong) NSIndexPath *selectIndexPath;//选中的Cell
-@property (nonatomic, copy) void(^selectCellBlock)(MOGiftlist *selectGiftMode);//选中Cell的回调
 
 @property (nonatomic, copy) void(^theFirstGiftBlock)(void);//第一个礼物锁定态
 
@@ -40,8 +39,6 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)toDeleteBagGiftWith:(MOGiftlist *)giftModel Num:(NSInteger)num;
 - (void)toUpdataBagGiftWith:(MOGiftlist *)giftModel;
 
-- (void)listWillAppear;
-
 - (void)toUpdataTheSelectIndexPathCell;//更新相应Cell的显示
 
 /// 1秒触发一次

+ 18 - 32
MiMoLive/Classes/Live/View/LiveingView/GiftListView/MOGiftListBagView/MOBagCollectionView.m

@@ -12,8 +12,7 @@
 
 @interface MOBagCollectionView ()
 <UICollectionViewDelegate,
-UICollectionViewDataSource,
-MOGiftListViewModelDelegate>
+UICollectionViewDataSource>
 
 @property (nonatomic, strong) UICollectionView *collectionView;
 /** 没有更多的数据视图 */
@@ -32,7 +31,6 @@ MOGiftListViewModelDelegate>
     if (self) {
         [self setupUI];
         self.listViewModel = listViewModel;
-        [listViewModel addObserver:self];
     }
     
     return self;
@@ -49,7 +47,9 @@ MOGiftListViewModelDelegate>
 }
 
 #pragma mark - JXCategoryListContentViewDelegate
-- (void)listWillAppear{
+- (void)listDidAppear{
+    if (self.isHidden) return;
+    
     self.next = @"";
     
     if(self.listViewModel.curRoomId.length == 0){
@@ -94,7 +94,7 @@ MOGiftListViewModelDelegate>
     if(!giftModel.lock){
         giftModel.isSelect = YES;
         self.selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];//选中第一个
-        self.selectCellBlock ? self.selectCellBlock(giftModel) : nil;
+        self.selectGiftBlock(giftModel, self.type);
     }
     else{
         self.theFirstGiftBlock ? self.theFirstGiftBlock() : nil;
@@ -113,7 +113,7 @@ MOGiftListViewModelDelegate>
                 object.isSelect = YES;
                 
                 self.selectIndexPath = [NSIndexPath indexPathForRow:theIndex inSection:0];//选中第一个
-                self.selectCellBlock ? self.selectCellBlock(object) : nil;
+                self.selectGiftBlock(object, self.type);
                 [self.collectionView scrollToItemAtIndexPath:self.selectIndexPath atScrollPosition:UICollectionViewScrollPositionTop animated:NO];
                 [MOSvgaSourceManage shareManager].hitGiftModel = nil;
                 
@@ -158,6 +158,17 @@ MOGiftListViewModelDelegate>
                 object.isBag = YES;
             }
             
+            BOOL isHaveSelet = NO;
+            for (MOGiftlist *giftModel in weakSelf.dataArr) {
+                if(giftModel.isSelect){
+                    isHaveSelet = YES;
+                }
+            }
+            
+            if(!isHaveSelet){
+                [self toChangeTheFirstChooseWith:weakSelf.dataArr];
+            }
+            
             [weakSelf.collectionView reloadData];
             
             weakSelf.noMoreDataView.isHaveData = (weakSelf.dataArr.count > 0) ? YES : NO;
@@ -240,31 +251,6 @@ MOGiftListViewModelDelegate>
     return self;
 }
 
-#pragma mark MOGiftListViewModelDelegate
-- (void)onGiftListChangedWithCategory:(NSInteger)category list:(NSArray<MOGiftlist *> *)list {
-    BOOL isHaveSelet = NO;
-    for (MOGiftlist *giftModel in list) {
-        if(giftModel.isSelect){
-            isHaveSelet = YES;
-        }
-    }
-    
-    if(!isHaveSelet){
-        [self toChangeTheFirstChooseWith:list];
-    }
-    
-    [self.collectionView reloadData];
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-        if (self.reloadCollectionViewBlock) {
-            self.reloadCollectionViewBlock(self);
-        }
-    });
-    
-    self.noMoreDataView.isHaveData = list.count > 0 ? YES : NO;
-    
-    [self toSelectTheHitGift];//跳转Hit礼物
-}
-
 #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
 {
@@ -309,7 +295,7 @@ MOGiftListViewModelDelegate>
     self.giftNum = 1;
     
     self.selectIndexPath = indexPath;
-    self.selectCellBlock ? self.selectCellBlock(modle) : nil;
+    self.selectGiftBlock(modle, self.type);
     
     [self.collectionView reloadData];
 }

+ 8 - 7
MiMoLive/Classes/Live/View/LiveingView/GiftListView/MOGiftListBagView/MOGiftListBagView.m

@@ -274,7 +274,11 @@
     }
     
     //刷新背包
-    [self.bagCollectionView listWillAppear];
+    if (self.titleCategoryView.selectedIndex == 0) {
+        [self.bagCollectionView listDidAppear];
+    } else {
+        [self.propsCollectionView listDidAppear];
+    }
     
     CGRect actionViewRect = self.contentView.frame;
     actionViewRect.origin.x = SCREENWIDTH;
@@ -375,12 +379,8 @@
         _bagCollectionView = [[MOBagCollectionView alloc] initWith:self.giftViewModel];
         
         WEAKSELF
-        _bagCollectionView.selectGiftBlock = ^(MOGiftlist * _Nonnull selectGiftModel, NSInteger giftType) {
-            weakSelf.selectGiftBlock ? weakSelf.selectGiftBlock(selectGiftModel, giftType) : nil;
-        };
-        _bagCollectionView.theFirstGiftBlock = ^{
-            weakSelf.theFirstGiftBlock ? weakSelf.theFirstGiftBlock() : nil;
-        };
+        _bagCollectionView.selectGiftBlock = weakSelf.selectGiftBlock;
+        _bagCollectionView.theFirstGiftBlock = weakSelf.theFirstGiftBlock;
     }
     return _bagCollectionView;
 }
@@ -410,6 +410,7 @@
                     make.top.equalTo(weakSelf.contentView).offset(kTheAnimationTop);
                 }];
             }
+            weakSelf.selectCellBlock(selectModel);
         };
         
         _propsCollectionView.toShopBlock = ^{

+ 37 - 2
MiMoLive/Classes/Live/View/LiveingView/GiftListView/MOGiftListBagView/Props/MOPropsCollectionView.m

@@ -76,8 +76,19 @@
     self.sort = 0;
 }
 
+- (void)handleCellClick:(NSIndexPath *)indexPath {
+    for (MOShopList *object in self.dataArr) {
+        object.isSelect = NO;
+    }
+    
+    MOShopList *model = self.dataArr[indexPath.row];
+    model.isSelect = YES;
+    self.selectIndexPath = indexPath;
+    self.selectCellBlock ? self.selectCellBlock(model) : nil;
+}
+
 #pragma mark - JXCategoryListContentViewDelegate
-- (void)listWillAppear{
+- (void)listDidAppear{
     self.next = @"";
     [self toGetThePropsData];
 }
@@ -101,6 +112,11 @@
         if(kCode_Success){
 //            MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
             BOOL isFirstHidden = NO;
+            MOShopList *selected = nil;
+            if (self.selectIndexPath != nil && self.selectIndexPath.row < self.dataArr.count) {
+                selected = self.dataArr[self.selectIndexPath.row];
+            }
+
             MOShopBaseData *baseModel = [MOShopBaseData modelObjectWithDictionary:data[@"data"]];
             weakSelf.propNearExpiryPropCountBlock ? weakSelf.propNearExpiryPropCountBlock(baseModel.propNearExpiryPropCount) : nil;
             if(baseModel.next == nil || baseModel.next.length == 0){
@@ -133,7 +149,26 @@
                 }
                 self.next = baseModel.next;
             }
-
+            
+            BOOL found = NO;
+            for (MOShopList *item in self.dataArr) {
+                if ([item.id isEqualToString:selected.id]) {
+                    item.isSelect = YES;
+                    self.selectIndexPath = [NSIndexPath indexPathForRow:[self.dataArr indexOfObject:item] inSection:0];
+                    selected = item;
+                    found = YES;
+                    break;
+                }
+            }
+            if (!found && self.dataArr.count > 0) {
+                // 默认选中第一个
+                found = YES;
+                selected = self.dataArr.firstObject;
+                [self handleCellClick:[NSIndexPath indexPathForRow:0 inSection:0]];
+            } else {
+                self.selectCellBlock(found ? selected : nil);
+            }
+            
             [self.collectionView reloadData];
             
             self.noMoreDataView.isHaveData = (weakSelf.dataArr.count > 0) ? YES : NO;

+ 8 - 8
MiMoLive/Classes/Live/View/LiveingView/GiftListView/MOGiftListView.m

@@ -253,12 +253,6 @@ MOGiftComboViewDelegate>
     }];
     self.giftPanelsView = panelsView;
     
-    [self.bgView addSubview:self.bagView];
-    [self.bagView mas_makeConstraints:^(MASConstraintMaker *make) {
-        make.edges.equalTo(self);
-    }];
-    self.bagView.hidden = YES;
-    
     [self.bgView addSubview:self.susuImageView];
     [self.susuImageView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.right.equalTo(self.bgView);
@@ -670,8 +664,6 @@ MOGiftComboViewDelegate>
 }
 
 - (void)showGiftListView{
-    self.showUpBlock();
-    
     [self setHidden:NO];
     self.frame = CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT);
     
@@ -691,6 +683,7 @@ MOGiftComboViewDelegate>
         weakSelf.bgView.frame = actionViewRect;
     } completion:^(BOOL finished) {
         [weakSelf.listViewModel preloadGiftList];
+        weakSelf.showUpBlock();
     }];
     
     [self.giftPanelsView toJudgeIsNeedChangeTheSelectTitle];//判断是否有滑动到特定分类的需求
@@ -1121,6 +1114,13 @@ MOGiftComboViewDelegate>
 
 - (void)onGiftPanelsViewClickBagButton {
     [self.bottomMenuView updateSelectItem:nil];
+    
+    if (self.bagView.superview == nil) {
+        [self.bgView insertSubview:self.bagView belowSubview:self.susuImageView];
+        [self.bagView mas_makeConstraints:^(MASConstraintMaker *make) {
+            make.edges.equalTo(self);
+        }];
+    }
     self.bagView.hidden = NO;
     self.bagView.multiple = self.multiple;
     self.bagView.giftRedCount = self.giftRedCount;