TUIGroupPinPageViewController.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // TUIGroupPinPageViewController.m
  3. // TUIChat
  4. //
  5. // Created by Tencent on 2024/05/20.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIGroupPinPageViewController.h"
  9. #import <TIMCommon/NSString+TUIEmoji.h>
  10. #import <TIMCommon/TIMCommonModel.h>
  11. #import <TIMCommon/TIMDefine.h>
  12. #import <TUICore/NSDictionary+TUISafe.h>
  13. #import <TUICore/TUICore.h>
  14. #import <TUICore/TUILogin.h>
  15. #import "TUIGroupPinCell.h"
  16. #import "TUIMessageDataProvider.h"
  17. @interface TUIGroupPinPageViewController() <UITableViewDelegate,UITableViewDataSource>
  18. @end
  19. @implementation TUIGroupPinPageViewController
  20. - (instancetype)init {
  21. self = [super init];
  22. if (self) {
  23. self.tableview.backgroundColor = TUIChatDynamicColor(@"chat_pop_group_pin_back_color", @"#F9F9F9");
  24. self.customArrowView.backgroundColor = TUIChatDynamicColor(@"chat_pop_group_pin_back_color", @"#F9F9F9");
  25. self.bottomShadow.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.5];
  26. [self addSingleTapGesture];
  27. }
  28. return self;
  29. }
  30. - (void)addSingleTapGesture {
  31. // When clicking on the shadow, the page disappears
  32. self.view.userInteractionEnabled = YES;
  33. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
  34. [self.view addGestureRecognizer:singleTap];
  35. }
  36. - (void)singleTap:(UITapGestureRecognizer *)tap {
  37. [UIView animateWithDuration:0.3 animations:^{
  38. self.tableview.frame = CGRectMake(0, self.tableview.frame.origin.y, self.view.frame.size.width, 60);
  39. self.customArrowView.frame = CGRectMake(0, CGRectGetMaxY(self.tableview.frame), self.view.frame.size.width, self.customArrowView.frame.size.height);
  40. self.bottomShadow.frame = CGRectMake(0, CGRectGetMaxY(self.customArrowView.frame), self.view.frame.size.width, 0);
  41. }completion:^(BOOL finished) {
  42. if (finished) {
  43. [self dismissViewControllerAnimated:NO completion:nil];
  44. }
  45. }];
  46. }
  47. - (UITableView *)tableview {
  48. if (!_tableview) {
  49. _tableview = [[UITableView alloc] init];
  50. _tableview.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  51. _tableview.delegate = self;
  52. _tableview.dataSource = self;
  53. [_tableview setSeparatorStyle:UITableViewCellSeparatorStyleNone];
  54. _tableview.showsVerticalScrollIndicator = NO;
  55. _tableview.showsHorizontalScrollIndicator = NO;
  56. [self.view addSubview:_tableview];
  57. UIView *herderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)];
  58. _tableview.tableHeaderView = herderView;
  59. }
  60. return _tableview;
  61. }
  62. - (UIView *)customArrowView {
  63. if (!_customArrowView) {
  64. _customArrowView = [[UIView alloc] initWithFrame:CGRectMake(0, _tableview.frame.size.height, _tableview.frame.size.width, 100)];
  65. [self.view addSubview:_customArrowView];
  66. UIView *arrowBackgroundView = [[UIView alloc] initWithFrame:CGRectZero];
  67. arrowBackgroundView.backgroundColor = [UIColor clearColor];
  68. arrowBackgroundView.layer.cornerRadius = 5;
  69. [_customArrowView addSubview:arrowBackgroundView];
  70. _customArrowView.clipsToBounds = YES;
  71. UIImageView *arrow = [[UIImageView alloc] initWithFrame:CGRectZero];
  72. arrow.image = TUIChatBundleThemeImage(@"chat_pop_group_pin_up_arrow_img", @"chat_up_arrow_icon");
  73. [arrowBackgroundView addSubview:arrow];
  74. [arrowBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.center.mas_equalTo(_customArrowView);
  76. make.size.mas_equalTo(CGSizeMake(20, 20));
  77. }];
  78. [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.center.mas_equalTo(arrowBackgroundView);
  80. make.size.mas_equalTo(CGSizeMake(20, 20));
  81. }];
  82. }
  83. return _customArrowView;
  84. }
  85. - (UIView *)bottomShadow {
  86. if (!_bottomShadow) {
  87. _bottomShadow = [[UIView alloc] init];
  88. _bottomShadow.userInteractionEnabled = NO;
  89. [self.view addSubview:_bottomShadow];
  90. }
  91. return _bottomShadow;
  92. }
  93. #pragma mark - group pin
  94. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  95. TUIGroupPinCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  96. if (cell == nil) {
  97. cell = [[TUIGroupPinCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  98. }
  99. cell.backgroundColor = [UIColor systemGroupedBackgroundColor];
  100. V2TIMMessage *msg = self.groupPinList[indexPath.row];
  101. TUIMessageCellData * cellData = [TUIMessageDataProvider getCellData:msg];
  102. [cell fillWithData:cellData];
  103. __weak __typeof(self) weakSelf = self;
  104. cell.cellView.removeButton.hidden = !self.canRemove;
  105. cell.cellView.onClickRemove = ^(V2TIMMessage *originMessage) {
  106. if (weakSelf.onClickRemove) {
  107. weakSelf.onClickRemove(originMessage);
  108. }
  109. };
  110. cell.cellView.onClickCellView = ^(V2TIMMessage *originMessage) {
  111. if (weakSelf.onClickCellView) {
  112. weakSelf.onClickCellView(originMessage);
  113. }
  114. [weakSelf singleTap:nil];
  115. };
  116. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  117. return cell;
  118. }
  119. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  120. return 1;
  121. }
  122. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  123. return self.groupPinList.count;
  124. }
  125. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  126. CGFloat contentH = 62;
  127. CGFloat padding = 0;
  128. return contentH + padding;
  129. }
  130. @end