@@ -93,7 +93,8 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
[ self . inputView mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . left . right . equalTo ( self ) ;
make . height . mas_equalTo ( 50 ) ;
self . inputBottomConstraint = make . bottom . equalTo ( self ) . offset ( - KB_SafeAreaBottom ( ) ) ;
self . inputBottomConstraint =
make . bottom . equalTo ( self ) . offset ( - KB_SafeAreaBottom ( ) ) ;
} ] ;
[ self . tableView mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
@@ -148,7 +149,8 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
[ self . inputBottomConstraint uninstall ] ;
[ self . inputView mas_updateConstraints : ^ ( MASConstraintMaker * make ) {
self . inputBottomConstraint = make . bottom . equalTo ( self ) ;
self . inputBottomConstraint =
make . bottom . equalTo ( self ) . offset ( - KB_SafeAreaBottom ( ) ) ;
} ] ;
[ UIView animateWithDuration : duration
@@ -196,10 +198,12 @@ static NSString *const kCommentFooterIdentifier = @"CommentFooter";
for ( NSDictionary * dict in commentsArray ) {
KBAICommentModel * comment = [ KBAICommentModel mj_objectWithKeyValues : dict ] ;
// 预 先 计 算 并 缓 存 Header 高 度
comment . cachedHeaderHeight = [ comment calculateHeaderHeightWithMaxWidth : tableWidth ] ;
comment . cachedHeaderHeight =
[ comment calculateHeaderHeightWithMaxWidth : tableWidth ] ;
// 预 先 计 算 并 缓 存 所 有 Reply 高 度
for ( KBAIReplyModel * reply in comment . replies ) {
reply . cachedCellHeight = [ reply calculateCellHeightWithMaxWidth : tableWidth ] ;
reply . cachedCellHeight =
[ reply calculateCellHeightWithMaxWidth : tableWidth ] ;
}
[ self . comments addObject : comment ] ;
}
@@ -365,7 +369,8 @@ static NSInteger const kRepliesLoadCount = 5;
NSInteger newCount = comment . displayedReplies . count ;
NSMutableArray * insertIndexPaths = [ NSMutableArray array ] ;
for ( NSInteger i = currentCount ; i < newCount ; i + + ) {
[ insertIndexPaths addObject : [ NSIndexPath indexPathForRow : i inSection : section ] ] ;
[ insertIndexPaths addObject : [ NSIndexPath indexPathForRow : i
inSection : section ] ] ;
}
// 插 入 行 ( 不 刷 新 Header , 避 免 头 像 闪 烁 )
@@ -391,7 +396,8 @@ static NSInteger const kRepliesLoadCount = 5;
// 计 算 要 删 除 的 行
NSMutableArray * deleteIndexPaths = [ NSMutableArray array ] ;
for ( NSInteger i = 0 ; i < rowCount ; i + + ) {
[ deleteIndexPaths addObject : [ NSIndexPath indexPathForRow : i inSection : section ] ] ;
[ deleteIndexPaths addObject : [ NSIndexPath indexPathForRow : i
inSection : section ] ] ;
}
// 收 起 全 部 回 复
@@ -458,7 +464,7 @@ static NSInteger const kRepliesLoadCount = 5;
- ( BaseTableView * ) tableView {
if ( ! _tableView ) {
_tableView = [ [ BaseTableView alloc ] initWithFrame : CGRectZero
style : UITableViewStyleGrouped ] ;
style : UITableViewStyleGrouped ] ;
_tableView . dataSource = self ;
_tableView . delegate = self ;
_tableView . backgroundColor = [ UIColor whiteColor ] ;
@@ -496,20 +502,26 @@ static NSInteger const kRepliesLoadCount = 5;
# pragma mark - Reply
- ( void ) setReplyToComment : ( KBAICommentModel * ) comment reply : ( KBAIReplyModel * ) reply {
- ( void ) setReplyToComment : ( KBAICommentModel * ) comment
reply : ( KBAIReplyModel * ) reply {
self . replyToComment = comment ;
self . replyToReply = reply ;
if ( reply ) {
// 回 复 二 级 评 论
self . inputView . placeholder = [ NSString stringWithFormat : @ "回复 @%@" , reply . userName ] ;
self . inputView . placeholder =
[ NSString stringWithFormat : @ "回复 @%@" , reply . userName ] ;
} else if ( comment ) {
// 回 复 一 级 评 论
self . inputView . placeholder = [ NSString stringWithFormat : @ "回复 @%@" , comment . userName ] ;
self . inputView . placeholder =
[ NSString stringWithFormat : @ "回复 @%@" , comment . userName ] ;
} else {
// 普 通 评 论
self . inputView . placeholder = @ "说点什么..." ;
}
// 弹 起 键 盘
[ self . inputView showKeyboard ] ;
}
- ( void ) clearReplyTarget {
@@ -521,7 +533,8 @@ static NSInteger const kRepliesLoadCount = 5;
# pragma mark - Send Comment
- ( void ) sendCommentWithText : ( NSString * ) text {
if ( text . length = = 0 ) return ;
if ( text . length = = 0 )
return ;
CGFloat tableWidth = self . tableView . bounds . size . width ;
if ( tableWidth <= 0 ) {
@@ -555,7 +568,8 @@ static NSInteger const kRepliesLoadCount = 5;
newComment . replies = @ [ ] ;
// 计 算 高 度 缓 存
newComment . cachedHeaderHeight = [ newComment calculateHeaderHeightWithMaxWidth : tableWidth ] ;
newComment . cachedHeaderHeight =
[ newComment calculateHeaderHeightWithMaxWidth : tableWidth ] ;
// 插 入 到 数 组 第 一 个
[ self . comments insertObject : newComment atIndex : 0 ] ;
@@ -572,7 +586,8 @@ static NSInteger const kRepliesLoadCount = 5;
- ( void ) sendReplyWithText : ( NSString * ) text tableWidth : ( CGFloat ) tableWidth {
KBAICommentModel * comment = self . replyToComment ;
if ( ! comment ) return ;
if ( ! comment )
return ;
// 创 建 新 二 级 评 论
KBAIReplyModel * newReply = [ [ KBAIReplyModel alloc ] init ] ;
@@ -591,7 +606,8 @@ static NSInteger const kRepliesLoadCount = 5;
}
// 计 算 高 度 缓 存
newReply . cachedCellHeight = [ newReply calculateCellHeightWithMaxWidth : tableWidth ] ;
newReply . cachedCellHeight =
[ newReply calculateCellHeightWithMaxWidth : tableWidth ] ;
// 添 加 到 replies 数 组
NSMutableArray * newReplies = [ NSMutableArray arrayWithArray : comment . replies ] ;
@@ -601,15 +617,17 @@ static NSInteger const kRepliesLoadCount = 5;
// 找 到 该 评 论 的 section
NSInteger section = [ self . comments indexOfObject : comment ] ;
if ( section = = NSNotFound ) return ;
if ( section = = NSNotFound )
return ;
// 如 果 已 展 开 , 添 加 到 displayedReplies 并 插 入 行
if ( comment . isRepliesExpanded ) {
NSInteger newRowIndex = comment . displayedReplies . count ;
[ comment . displayedReplies addObject : newReply ] ;
NSIndexPath * indexPath = [ NSIndexPath indexPathForRow : newRowIndex inSection : section ] ;
[ self . tableView insertRowsAtIndexPaths : @ [ indexPath ]
NSIndexPath * indexPath = [ NSIndexPath indexPathForRow : newRowIndex
inSection : section ] ;
[ self . tableView insertRowsAtIndexPaths : @ [ indexPath ]
withRowAnimation : UITableViewRowAnimationAutomatic ] ;
// 刷 新 Footer