Commit 9ddfc0fd cgx

优化动态评论回复显示

1 个父辈 c2bc1f1b
正在显示 23 个修改的文件 包含 454 行增加136 行删除
......@@ -38,6 +38,11 @@ NS_ASSUME_NONNULL_BEGIN
/// 获取格式化时间
/// @param time time(单位:s)
+ (NSString *)getFormatTime:(NSInteger)time;
/// 计算字符串行数
/// @param width width
/// @param attributes attributes
- (NSArray *)getLinesArrayOfStringWidth:(CGFloat)width attributes:(NSDictionary *)attributes;
@end
NS_ASSUME_NONNULL_END
......@@ -6,6 +6,7 @@
//
#import "NSString+Extras.h"
#import <CoreText/CoreText.h>
@implementation NSString (Extras)
......@@ -60,4 +61,34 @@
return [NSString stringWithFormat:@"%02ld:%02ld", minutes, seconds];
}
- (NSArray *)getLinesArrayOfStringWidth:(CGFloat)width attributes:(NSDictionary *)attributes {
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:self attributes:attributes];
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attStr);
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, CGRectMake(0, 0, width, 100000));
CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL);
NSArray *lines = ( NSArray *)CTFrameGetLines(frame);
NSMutableArray *linesArray = [[NSMutableArray alloc]init];
for (id line in lines) {
CTLineRef lineRef = (__bridge CTLineRef)line;
CFRange lineRange = CTLineGetStringRange(lineRef);
NSRange range = NSMakeRange(lineRange.location, lineRange.length);
NSString *lineString = [self substringWithRange:range];
CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr,
lineRange,
kCTKernAttributeName,
(CFTypeRef)([NSNumber numberWithFloat:0.0]));
CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr,
lineRange,
kCTKernAttributeName,
(CFTypeRef)([NSNumber numberWithInt:0.0]));
[linesArray addObject:lineString];
}
CGPathRelease(path);
CFRelease(frame);
CFRelease(frameSetter);
return (NSArray *)linesArray;
}
@end
......@@ -25,8 +25,10 @@ NS_ASSUME_NONNULL_BEGIN
+ (UILabel *)labWithText:(NSString *)text font:(UIFont *)font fit:(BOOL)fit;
// 根据文本及字体计算UILabel的高度
// 根据text及字体计算UILabel的高度
+ (CGFloat)getHeightByWidth:(CGFloat)width text:(NSString *)text font:(UIFont *)font;
// 根据attributedText及字体计算UILabel的高度
+ (CGFloat)getHeightByWidth:(CGFloat)width attributedText:(NSAttributedString *)attributedText font:(UIFont *)font;
// 根据文本及字体计算UILabel的宽度
+ (CGFloat)getWidthWithText:(NSString *)text font:(UIFont *)font;
@end
......
......@@ -54,8 +54,7 @@
return lab;
}
+ (CGFloat)getHeightByWidth:(CGFloat)width text:(NSString *)text font:(UIFont *)font
{
+ (CGFloat)getHeightByWidth:(CGFloat)width text:(NSString *)text font:(UIFont *)font {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
label.text = text;
label.font = font;
......@@ -65,6 +64,16 @@
return ceil(height);
}
+ (CGFloat)getHeightByWidth:(CGFloat)width attributedText:(NSAttributedString *)attributedText font:(UIFont *)font {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
label.attributedText = attributedText;
label.font = font;
label.numberOfLines = 0;
[label sizeToFit];
CGFloat height = label.frame.size.height;
return ceil(height);
}
+ (CGFloat)getWidthWithText:(NSString *)text font:(UIFont *)font {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
label.text = text;
......
......@@ -91,6 +91,10 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>
<key>Privacy - Photo Library Additions Usage Description </key>
<string>APP需要您的同意,才能访问相册。</string>
<key>UIBackgroundModes</key>
......@@ -99,11 +103,5 @@
</array>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>NSBonjourServices</key>
<array>
<string>_dartobservatory._tcp</string>
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>需要访问本地网络权限</string>
</dict>
</plist>
......@@ -9,13 +9,12 @@
#import "CommunityView.h"
#import "ComListViewModel.h"
#import "DynamicController.h"
#import "TestFlutterController.h"
#import "MessageController.h"
#import "ReportController.h"
#import "DynamicDetailController.h"
@interface CommunityController () <CommunityViewDelegate, DynamicControllerDelegate, DynamicDetailControllerDelegate>
@property (nonatomic, strong) CommunityView *communityView;
@property (nonatomic, strong) TestFlutterController *flutterEngine;
@property (nonatomic, assign) int offset;
@property (nonatomic, strong) NSURLSessionDataTask *likeDataTask;
/// 存储动态id
......@@ -54,8 +53,7 @@
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
self.flutterEngine = [TestFlutterController new];
[self.navigationController pushViewController:self.flutterEngine animated:YES];
[self.navigationController pushViewController:[MessageController new] animated:YES];
}
#pragma mark - CommunityViewDelegate
......
//
// MessageController.h
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 社区消息通知页面
@interface MessageController : UIViewController
@end
NS_ASSUME_NONNULL_END
//
// MessageController.m
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import "MessageController.h"
#import "MessageNotiView.h"
@interface MessageController () <MessageNotiViewDelegate>
@property (nonatomic, strong) MessageNotiView *messageNotiView;
@end
@implementation MessageController
- (void)loadView {
self.view = self.messageNotiView;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"消息中心";
}
#pragma mark - 品牌模式
- (NaviStyle)navigationBarStyle {
return NaviStyleDefault;
}
#pragma mark - lazy
- (MessageNotiView *)messageNotiView {
if (!_messageNotiView) {
_messageNotiView = [[MessageNotiView alloc] initWithDelegate:self];
}
return _messageNotiView;
}
@end
......@@ -9,10 +9,6 @@
#import "CommentModel.h"
#import "ReplyModel.h"
#define kContentLeftMargin 84
#define kContentRightMargin 30
#define kMaxContentHeight 40
NS_ASSUME_NONNULL_BEGIN
FOUNDATION_EXTERN UIFont * const CommentContentFont;
......@@ -23,23 +19,23 @@ FOUNDATION_EXTERN UIFont * const CommentContentFont;
@property (nonatomic, strong) CommentModel *commentModel;
/// 回复model
@property (nonatomic, strong) ReplyModel *replyModel;
/// 是否展开全部评论内容
@property (nonatomic, assign) BOOL isShowAllCommentContent;
- (NSString *)replyNickName;
+ (UIFont *)commentContentFont;
+ (UIFont *)replayNickNameFont;
+ (UIFont *)replayContentFont;
+ (UIFont *)replyNickNameFont;
+ (UIFont *)replyContentFont;
- (NSAttributedString *)replyContentAttriStr;
- (CGFloat)commentContentLeftMargin;
- (CGFloat)commentContentRightMargin;
- (CGFloat)commentContentHeight;
- (CGFloat)showAllBtnHeight;
- (CGFloat)replayNickNameW;
- (CGSize)replayContentSize;
- (CGFloat)replyNickNameW;
- (CGSize)replyContentSize;
- (CGFloat)replyViewHeight;
- (CGFloat)commentCellHeight;
- (BOOL)isHiddenShowAllBtn;
@end
NS_ASSUME_NONNULL_END
......@@ -7,14 +7,19 @@
#import "ComReplyModel.h"
// 回复内容显示最大行数
#define kMaxReplyLine 2
@implementation ComReplyModel
#pragma mark - 模型字段映射
+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{@"commentModel" : @"comment",
@"replyModel" : @"reply"
};
}
#pragma mark - public
- (NSString *)replyNickName {
return [NSString stringWithFormat:@"%@:", self.replyModel.nick_name];
}
......@@ -23,41 +28,65 @@
return SysFont(14);
}
+ (UIFont *)replayNickNameFont {
+ (UIFont *)replyNickNameFont {
return SysFont(15);
}
+ (UIFont *)replayContentFont {
+ (UIFont *)replyContentFont {
return SysFont(14);
}
- (CGFloat)commentContentHeight {
CGFloat contentW = kScreenWidth - kContentLeftMargin - kContentRightMargin;
NSString *content = self.commentModel.content;
CGFloat commentH = [UILabel getHeightByWidth:contentW text:content font:[ComReplyModel commentContentFont]];
return self.isShowAllCommentContent ? commentH : (commentH > kMaxContentHeight ? kMaxContentHeight : commentH);
- (NSAttributedString *)replyContentAttriStr {
NSString *replyContentStr = self.replyModel.content ? self.replyModel.content : @"";
NSMutableAttributedString *replyAttStr = [[NSMutableAttributedString alloc] initWithString:replyContentStr attributes:[self replyContentAttributes:NO]];
if ([self replyContentMaxLines].count > kMaxReplyLine) {
// 1、获取显示最多行字符串
NSMutableString *mLineStr = [NSMutableString string];
for (NSInteger i = 0; i < kMaxReplyLine; i++) {
[mLineStr appendString:[self replyContentMaxLines][i]];
}
// 2、截取字符串最后1个位置,用于填充自定义富文本
NSString * subLineStr = [mLineStr substringWithRange:NSMakeRange(0, mLineStr.length - 1)];
// 3、将subLineStr转换未富文本
replyAttStr = [[NSMutableAttributedString alloc] initWithString:subLineStr attributes:[self replyContentAttributes:NO]];
// 4、自定义结尾富文本
NSMutableAttributedString *dotAtrStr = [[NSMutableAttributedString alloc] initWithString:@"..." attributes:[self replyContentAttributes:YES]];
[replyAttStr appendAttributedString:dotAtrStr.copy];
}
return replyAttStr.copy;
}
- (CGFloat)showAllBtnHeight {
return [self isHiddenShowAllBtn] ? 0 : 10;
- (CGFloat)commentContentLeftMargin {
return 84;
}
- (CGFloat)replayNickNameW {
CGFloat replayNameLabW = [UILabel getWidthWithText:[self replyNickName] font:[ComReplyModel replayNickNameFont]];
return replayNameLabW > 75 ? 75 : replayNameLabW;
- (CGFloat)commentContentRightMargin {
return 30;
}
- (CGFloat)commentContentHeight {
CGFloat commentContentW = kScreenWidth - [self commentContentLeftMargin] - [self commentContentRightMargin];
NSString *content = self.commentModel.content;
return [UILabel getHeightByWidth:commentContentW text:content font:[ComReplyModel commentContentFont]];
}
- (CGSize)replayContentSize {
CGFloat replayContentW = kScreenWidth - kContentLeftMargin - kContentRightMargin - [self replayNickNameW] - 16;
CGFloat replayContentH = [UILabel getHeightByWidth:replayContentW text:self.replyModel.content font:[ComReplyModel replayContentFont]];
replayContentH = replayContentH > kMaxContentHeight ? : replayContentH;
return CGSizeMake(replayContentW, replayContentH);
- (CGFloat)replyNickNameW {
CGFloat replyNameLabW = [UILabel getWidthWithText:[self replyNickName] font:[ComReplyModel replyNickNameFont]];
return replyNameLabW > 75 ? 75 : replyNameLabW;
}
- (CGSize)replyContentSize {
CGFloat replyContentW = [self replyContentMaxW];
CGFloat replyContentH = [UILabel getHeightByWidth:replyContentW attributedText:[self replyContentAttriStr] font:[ComReplyModel replyContentFont]];
return CGSizeMake(replyContentW, replyContentH);
}
- (CGFloat)replyViewHeight {
CGFloat replayViewH = 0;
if (self.replyModel) {
replayViewH = 9 + [self replayContentSize].height + (self.commentModel.total_replys > 1 ? 37 : 9);
replayViewH = 9 + [self replyContentSize].height + (self.commentModel.total_replys > 1 ? 37 : 9);
}
return replayViewH;
}
......@@ -67,20 +96,31 @@
CGFloat commentH = [self commentContentHeight];
CGFloat replayViewH = [self replyViewHeight] + (self.replyModel ? 12 : 0);
CGFloat bottomMargin = 15;
CGFloat showAllBtnH = [self showAllBtnHeight];
return topH + commentH + showAllBtnH + replayViewH + bottomMargin;
return topH + commentH + replayViewH + bottomMargin;
}
#pragma mark - private
- (NSArray *)replyContentMaxLines {
return [self.replyModel.content getLinesArrayOfStringWidth:[self replyContentMaxW] attributes:@{NSFontAttributeName : [ComReplyModel replyContentFont]}];
}
- (BOOL)isHiddenShowAllBtn {
if (self.isShowAllCommentContent) {
return YES;
- (CGFloat)replyContentMaxW {
return kScreenWidth - [self commentContentLeftMargin] - [self commentContentRightMargin] - [self replyNickNameW] - 16;
}
- (NSDictionary *)replyContentAttributes:(BOOL)isTail {
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.minimumLineHeight = [ComReplyModel replyContentFont].lineHeight;
paragraphStyle.maximumLineHeight = [ComReplyModel replyContentFont].lineHeight;
paragraphStyle.alignment = NSTextAlignmentLeft;
NSMutableDictionary *mAttributes = [NSMutableDictionary dictionaryWithDictionary:
@{NSFontAttributeName : [ComReplyModel replyContentFont],
NSParagraphStyleAttributeName : paragraphStyle}];
// 只有1条回复高亮...
if (isTail && self.commentModel.total_replys < 2) {
[mAttributes setObject:BrandColor forKey:NSForegroundColorAttributeName];
}
// 只有评论没有回复并且评论内容只显示一部分,则"显示全部"按钮显示
CGFloat contentW = kScreenWidth - kContentLeftMargin - kContentRightMargin;
NSString *content = self.commentModel.content;
CGFloat commentH = [UILabel getHeightByWidth:contentW text:content font:[ComReplyModel commentContentFont]];
BOOL isGreaterMax = commentH > kMaxContentHeight;
return !(self.commentModel && self.replyModel == nil && isGreaterMax);
return mAttributes.copy;
}
@end
//
// CommentReplyCell.h
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 消息中心评论回复cell
@interface CommentReplyCell : UITableViewCell
@end
NS_ASSUME_NONNULL_END
//
// CommentReplyCell.m
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import "CommentReplyCell.h"
@implementation CommentReplyCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
//
// CommentCell.h
// DynamicCommentCell.h
// DreamSleep
//
// Created by peter on 2022/10/8.
......@@ -8,22 +8,18 @@
#import <UIKit/UIKit.h>
#import "ComReplyModel.h"
/// 用户点击评论内容回调
typedef void(^TapCommentContentLabBlock)(void);
/// 显示全部评论内容回调
typedef void(^TapAllCommentContentBlock)(void);
/// 查看评论所有回复内容回调
typedef void(^LookAllRelpyListBlock)(void);
NS_ASSUME_NONNULL_BEGIN
/// 评论、部分回复cell
@interface CommentCell : UITableViewCell
/// 动态评论、部分回复cell
@interface DynamicCommentCell : UITableViewCell
@property (nonatomic, strong) ComReplyModel *comReplyModel;
@property (nonatomic, copy) TapCommentContentLabBlock tapCommentContentLabBlock;
@property (nonatomic, copy) TapAllCommentContentBlock tapAllCommentContentBlock;
@property (nonatomic, copy) LookAllRelpyListBlock lookAllRelpyListBlock;
@end
NS_ASSUME_NONNULL_END
//
// CommentCell.m
// DynamicCommentCell.m
// DreamSleep
//
// Created by peter on 2022/10/8.
//
#import "CommentCell.h"
#import "DynamicCommentCell.h"
@interface CommentCell ()
@interface DynamicCommentCell ()
@property (nonatomic, strong) UIImageView *userIcon;
@property (nonatomic, strong) UILabel *userNameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *commentContentLab;
@property (nonatomic, strong) UIButton *showAllBtn;
@property (nonatomic, strong) UIView *replyView;
@property (nonatomic, strong) UILabel *replyUserLab;
@property (nonatomic, strong) UILabel *replyContentLab;
@property (nonatomic, strong) UIButton *totalReplyBtn;
@end
@implementation CommentCell
@implementation DynamicCommentCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
......@@ -30,7 +29,6 @@
[self.contentView addSubview:self.userNameLab];
[self.contentView addSubview:self.timeLab];
[self.contentView addSubview:self.commentContentLab];
[self.contentView addSubview:self.showAllBtn];
[self.contentView addSubview:self.replyView];
[self.userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
......@@ -58,39 +56,32 @@
self.userNameLab.text = comReplyModel.commentModel.nick_name;
self.timeLab.text = comReplyModel.commentModel.publish_time;
self.commentContentLab.text = comReplyModel.commentModel.content;
self.showAllBtn.hidden = [comReplyModel isHiddenShowAllBtn];
self.replyUserLab.text = [comReplyModel replyNickName];
self.replyContentLab.text = comReplyModel.replyModel.content;
self.replyContentLab.attributedText = [comReplyModel replyContentAttriStr];
[self.totalReplyBtn setTitle:[NSString stringWithFormat:@"共%d条回复>", comReplyModel.commentModel.total_replys] forState:UIControlStateNormal];
self.totalReplyBtn.hidden = comReplyModel.commentModel.total_replys > 1 ? NO : YES;
[self.commentContentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.userIcon.mas_bottom).offset(8);
make.left.equalTo(self.contentView).offset(kContentLeftMargin);
make.right.equalTo(self.contentView).offset(-kContentRightMargin);
make.left.equalTo(self.contentView).offset([comReplyModel commentContentLeftMargin]);
make.right.equalTo(self.contentView).offset(-[comReplyModel commentContentRightMargin]);
make.height.equalTo(@([comReplyModel commentContentHeight]));
}];
[self.showAllBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.commentContentLab.mas_bottom);
make.right.equalTo(self.commentContentLab);
make.height.equalTo(@([comReplyModel showAllBtnHeight]));
}];
[self.replyView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.showAllBtn.mas_bottom).offset(12);
make.top.equalTo(self.commentContentLab.mas_bottom).offset(12);
make.left.right.equalTo(self.commentContentLab);
make.height.equalTo(@([comReplyModel replyViewHeight]));
}];
[self.replyUserLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.replyView).offset(8);
make.left.equalTo(self.replyView).offset(8);
make.width.equalTo(@([comReplyModel replayNickNameW]));
make.width.equalTo(@([comReplyModel replyNickNameW]));
}];
[self.replyContentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.replyView).offset(9);
make.top.equalTo(self.replyUserLab);
make.left.equalTo(self.replyUserLab.mas_right);
make.size.mas_equalTo([comReplyModel replayContentSize]);
make.size.mas_equalTo([comReplyModel replyContentSize]);
}];
[self.totalReplyBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.replyUserLab);
......@@ -99,9 +90,9 @@
}
#pragma mark - private
- (void)popReplyInputView {
if (self.tapCommentContentLabBlock) {
self.tapCommentContentLabBlock();
- (void)lookAllRelpyList {
if (self.lookAllRelpyListBlock) {
self.lookAllRelpyListBlock();
}
}
......@@ -137,50 +128,32 @@
_commentContentLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
_commentContentLab.numberOfLines = 0;
_commentContentLab.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(popReplyInputView)];
[_commentContentLab addGestureRecognizer:tapGR];
}
return _commentContentLab;
}
- (UIButton *)showAllBtn {
if (!_showAllBtn) {
WS(weakSelf);
_showAllBtn = [UIButton btnWithTitle:@"显示全部" titleColor:BrandColor font:SysFont(10)];
[_showAllBtn addTouchUpInsideHandler:^(NSInteger tag) {
if (weakSelf.tapAllCommentContentBlock) {
weakSelf.tapAllCommentContentBlock();
}
}];
}
return _showAllBtn;
}
- (UIView *)replyView {
if (!_replyView) {
_replyView = [UIView new];
[_replyView cornerRadius:12];
_replyView.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, CornerViewDarkColor, BGColor);
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lookAllRelpyList)];
[_replyView addGestureRecognizer:tapGR];
UILabel *replyUserLab = [UILabel labWithFont:[ComReplyModel replayNickNameFont]];
UILabel *replyUserLab = [UILabel labWithFont:[ComReplyModel replyNickNameFont]];
replyUserLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, DkTitleColor, DSWhite);
[_replyView addSubview:replyUserLab];
self.replyUserLab = replyUserLab;
UILabel *replyContentLab = [UILabel labWithFont:[ComReplyModel replayContentFont]];
UILabel *replyContentLab = [UILabel labWithFont:[ComReplyModel replyContentFont]];
replyContentLab.numberOfLines = 0;
replyContentLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
[_replyView addSubview:replyContentLab];
self.replyContentLab = replyContentLab;
WS(weakSelf);
UIButton *totalReplyBtn = [UIButton btnWithTitle:@"" font:SysFont(15)];
[totalReplyBtn setTitleColor:BrandColor forState:UIControlStateNormal];
[totalReplyBtn addTouchUpInsideHandler:^(NSInteger tag) {
if (weakSelf.lookAllRelpyListBlock) {
weakSelf.lookAllRelpyListBlock();
}
}];
totalReplyBtn.userInteractionEnabled = NO;
[_replyView addSubview:totalReplyBtn];
self.totalReplyBtn = totalReplyBtn;
}
......
......@@ -8,7 +8,7 @@
#import "DynamicDetailView.h"
#import "InteractView.h"
#import "ComDynamicCell.h"
#import "CommentCell.h"
#import "DynamicCommentCell.h"
#define kSectionHeaderHeight 48
#define kSectionFooterHeight 8
......@@ -154,31 +154,11 @@
cell.model = self.detailListArr[indexPath.section];
return cell;
} else {
CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([CommentCell class]) forIndexPath:indexPath];
WS(weakSelf);
DynamicCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([DynamicCommentCell class]) forIndexPath:indexPath];
NSArray *comment_reply_arr = self.detailListArr[indexPath.section];
ComReplyModel *comReplyModel = comment_reply_arr[indexPath.row];
cell.comReplyModel = comReplyModel;
WS(weakSelf);
cell.tapCommentContentLabBlock = ^{
/*
// 1、自己不能回复自己
if ([LoginUtils getUserID] == comReplyModel.commentModel.user_id) {
[DSProgressHUD showToast:@"不能对自己发布的评论进行回复!"];
return;
}
// 2、动态发布者才能进行回复
ComDynModel *talkModel = self.detailListArr[0];
if ([LoginUtils getUserID] == talkModel.userID) {
[weakSelf.interactView popReplyInputBoxWithCommentUser:comReplyModel.commentModel.nick_name];
} else {
[DSProgressHUD showToast:@"只有动态发布者才能回复!"];
}
*/
};
cell.tapAllCommentContentBlock = ^{
comReplyModel.isShowAllCommentContent = YES;
[weakSelf.dynamicDetailView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
};
cell.lookAllRelpyListBlock = ^{
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(jumpReplyListView:)]) {
[weakSelf.delegate jumpReplyListView:comReplyModel.commentModel.comment_id];
......@@ -197,7 +177,7 @@
_dynamicDetailView.backgroundColor = DSClearColor;
_dynamicDetailView.showsVerticalScrollIndicator = NO;
_dynamicDetailView.separatorStyle = UITableViewCellSeparatorStyleNone;
[_dynamicDetailView registerClass:[CommentCell class] forCellReuseIdentifier:NSStringFromClass([CommentCell class])];
[_dynamicDetailView registerClass:[DynamicCommentCell class] forCellReuseIdentifier:NSStringFromClass([DynamicCommentCell class])];
_dynamicDetailView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, CGFLOAT_MIN)];
_dynamicDetailView.tableFooterView = footView;
......
......@@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateLikeBtnState:(BOOL)isLike likeCount:(int)likeCount;
- (void)updateRemarkCount:(int)remarkCount;
/// 弹出回复输入框
/// 弹出回复输入框(第一版暂不考虑)
/// @param commentUser @评论者
- (void)popReplyInputBoxWithCommentUser:(NSString *)commentUser;
......
//
// MessageNotiCell.h
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 消息中心顶部官方通知和点赞通知cell
@interface MessageNotiCell : UITableViewCell
@end
NS_ASSUME_NONNULL_END
//
// MessageNotiCell.m
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import "MessageNotiCell.h"
@interface MessageNotiCell ()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *detailLab;
@end
@implementation MessageNotiCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = DSClearColor;
[self.contentView addSubview:self.icon];
[self.contentView addSubview:self.titleLab];
[self.contentView addSubview:self.detailLab];
[self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(30);
make.top.equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(40, 40));
}];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.icon.mas_right).offset(14);
make.top.equalTo(self.icon);
make.right.equalTo(self.contentView).offset(-30);
}];
[self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLab);
make.bottom.equalTo(self.icon);
}];
}
return self;
}
@end
//
// MessageNotiView.h
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@protocol MessageNotiViewDelegate <NSObject>
@end
/// 消息通知view
@interface MessageNotiView : UITableView
@property (nonatomic, weak) id<MessageNotiViewDelegate> messageDelegate;
- (instancetype)initWithDelegate:(id<MessageNotiViewDelegate>)messageDelegate;
@end
NS_ASSUME_NONNULL_END
//
// MessageNotiView.m
// DreamSleep
//
// Created by peter on 2022/10/10.
//
#import "MessageNotiView.h"
#import "MessageNotiCell.h"
#import "CommentReplyCell.h"
static int secHeaderHeight = 52;
static int secFooterHeight = 8;
@interface MessageNotiView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSArray *messageListArr;
@end
@implementation MessageNotiView
- (instancetype)initWithDelegate:(id<MessageNotiViewDelegate>)messageDelegate {
if (self = [super initWithFrame:CGRectZero style:UITableViewStyleGrouped]) {
self.messageDelegate = messageDelegate;
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
self.messageListArr = @[@"1", @"2"];
self.delegate = self;
self.dataSource = self;
self.showsVerticalScrollIndicator = NO;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
[self registerClass:[MessageNotiCell class] forCellReuseIdentifier:NSStringFromClass([MessageNotiCell class])];
[self registerClass:[CommentReplyCell class] forCellReuseIdentifier:NSStringFromClass([CommentReplyCell class])];
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, CGFLOAT_MIN)];
self.tableFooterView = footView;
}
return self;
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.messageListArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 2;
} else {
return 10;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return 77;
} else {
return 100;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return section == 0 ? CGFLOAT_MIN : secHeaderHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 0)];
header.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
if (section == 0) {
header.height = 0;
} else {
header.height = secHeaderHeight;
UILabel *totalReplyCountLab = [UILabel labWithFont:BoldFont(15)];
totalReplyCountLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
totalReplyCountLab.origin = CGPointMake(15, 15);
totalReplyCountLab.text = @"评论和回复";
[totalReplyCountLab sizeToFit];
[header addSubview:totalReplyCountLab];
}
return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return section == self.messageListArr.count - 1 ? CGFLOAT_MIN : secFooterHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, section == self.messageListArr.count - 1 ? CGFLOAT_MIN : secFooterHeight)];
footer.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, AlertDarkColor, DSWhite);
return footer;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
MessageNotiCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MessageNotiCell class]) forIndexPath:indexPath];
return cell;
} else {
CommentReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([CommentReplyCell class]) forIndexPath:indexPath];
return cell;
}
}
@end
......@@ -25,7 +25,6 @@
self.delegate = self;
self.dataSource = self;
self.backgroundColor = DSClearColor;
self.showsVerticalScrollIndicator = NO;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
[self registerClass:[MajorCommentCell class] forCellReuseIdentifier:NSStringFromClass([MajorCommentCell class])];
......
......@@ -118,6 +118,7 @@
[DSProgressHUD showToast:@"请输入评论内容"];
return;
}
content = [NSString transferSpecialCharacters:content];
if (self.tapFinishBlock) {
self.tapFinishBlock(sender.tag, content);
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!