|
|
@@ -85,6 +85,35 @@ extension LNImageFeedDetailViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private func toComment(checkScroll: Bool = true) {
|
|
|
+ guard let curDetail else { return }
|
|
|
+ if checkScroll, !scrollToComment() {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let panel = LNFeedCommentInputPanel()
|
|
|
+ panel.handler = { [weak self] comment in
|
|
|
+ guard let self else { return }
|
|
|
+ LNFeedManager.shared.sendFeedComment(id: curDetail.id, content: comment) { [weak self] success in
|
|
|
+ guard let self else { return }
|
|
|
+ guard success else { return }
|
|
|
+
|
|
|
+ let item = LNFeedCommentVO()
|
|
|
+ item.avatar = myUserInfo.avatar
|
|
|
+ item.nickname = myUserInfo.nickname
|
|
|
+ item.textContent = comment
|
|
|
+ item.createdAt = Int(curTime * 1_000)
|
|
|
+ comments.insert(item, at: 0)
|
|
|
+ tableView.reloadSections(.init(integer: 1), with: .automatic)
|
|
|
+
|
|
|
+ curDetail.commentCount += 1
|
|
|
+ commentLabel.text = "\(curDetail.commentCount)"
|
|
|
+ LNFeedManager.shared.notifyFeedCommentChanged(id: curDetail.id, count: curDetail.commentCount)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ panel.popup()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension LNImageFeedDetailViewController: UITableViewDataSource, UITableViewDelegate {
|
|
|
@@ -149,6 +178,29 @@ extension LNImageFeedDetailViewController: UITableViewDataSource, UITableViewDel
|
|
|
}
|
|
|
|
|
|
extension LNImageFeedDetailViewController {
|
|
|
+ private func scrollToComment() -> Bool {
|
|
|
+ if curDetail?.commentCount == 0 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if tableView.contentOffset.y
|
|
|
+ + tableView.bounds.height
|
|
|
+ + tableView.contentInset.top
|
|
|
+ > tableView.contentSize.height - 50 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ let rect = tableView.rectForHeader(inSection: 1)
|
|
|
+ let convertedRect = tableView.convert(rect, to: tableView.superview)
|
|
|
+
|
|
|
+ if convertedRect.minY - 50 <= tableView.bounds.minY + tableView.contentInset.top {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ let indexPath = IndexPath(row: 0, section: 1)
|
|
|
+ tableView.scrollToRow(at: indexPath, at: .top, animated: true)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
private func setupViews() {
|
|
|
setupNavBar()
|
|
|
|
|
|
@@ -269,28 +321,7 @@ extension LNImageFeedDetailViewController {
|
|
|
let container = UIView()
|
|
|
container.onTap { [weak self] in
|
|
|
guard let self else { return }
|
|
|
- guard let curDetail else { return }
|
|
|
- let panel = LNFeedCommentInputPanel()
|
|
|
- panel.handler = { [weak self] comment in
|
|
|
- guard let self else { return }
|
|
|
- LNFeedManager.shared.sendFeedComment(id: curDetail.id, content: comment) { [weak self] success in
|
|
|
- guard let self else { return }
|
|
|
- guard success else { return }
|
|
|
-
|
|
|
- let item = LNFeedCommentVO()
|
|
|
- item.avatar = myUserInfo.avatar
|
|
|
- item.nickname = myUserInfo.nickname
|
|
|
- item.textContent = comment
|
|
|
- item.createdAt = Int(curTime * 1_000)
|
|
|
- comments.insert(item, at: 0)
|
|
|
- tableView.reloadSections(.init(integer: 1), with: .automatic)
|
|
|
-
|
|
|
- curDetail.commentCount += 1
|
|
|
- commentLabel.text = "\(curDetail.commentCount)"
|
|
|
- LNFeedManager.shared.notifyFeedCommentChanged(id: curDetail.id, count: curDetail.commentCount)
|
|
|
- }
|
|
|
- }
|
|
|
- panel.popup()
|
|
|
+ toComment()
|
|
|
}
|
|
|
|
|
|
let commentIc = UIImageView()
|
|
|
@@ -351,19 +382,7 @@ extension LNImageFeedDetailViewController {
|
|
|
container.layer.cornerRadius = 19
|
|
|
container.onTap { [weak self] in
|
|
|
guard let self else { return }
|
|
|
- guard let curDetail else { return }
|
|
|
- let panel = LNFeedCommentInputPanel()
|
|
|
- panel.handler = { [weak self] comment in
|
|
|
- guard let self else { return }
|
|
|
- LNFeedManager.shared.sendFeedComment(id: curDetail.id, content: comment)
|
|
|
- { [weak self] success in
|
|
|
- guard let self else { return }
|
|
|
- guard success else { return }
|
|
|
- curDetail.commentCount += 1
|
|
|
- commentLabel.text = "\(curDetail.commentCount)"
|
|
|
- }
|
|
|
- }
|
|
|
- panel.popup()
|
|
|
+ toComment(checkScroll: false)
|
|
|
}
|
|
|
container.snp.makeConstraints { make in
|
|
|
make.height.equalTo(38)
|
|
|
@@ -401,6 +420,7 @@ extension LNImageFeedDetailViewController {
|
|
|
tableView.separatorStyle = .none
|
|
|
tableView.dataSource = self
|
|
|
tableView.delegate = self
|
|
|
+ tableView.allowsSelection = false
|
|
|
|
|
|
let footer = MJRefreshAutoNormalFooter { [weak self] in
|
|
|
guard let self else { return }
|