diff --git a/Projects/Features/LiveStreamFeature/Sources/Chating/Views/ChattingListView.swift b/Projects/Features/LiveStreamFeature/Sources/Chating/Views/ChattingListView.swift index 9c366fa..f63f935 100644 --- a/Projects/Features/LiveStreamFeature/Sources/Chating/Views/ChattingListView.swift +++ b/Projects/Features/LiveStreamFeature/Sources/Chating/Views/ChattingListView.swift @@ -10,6 +10,7 @@ protocol ChatInputFieldAction { } final class ChattingListView: BaseView { + private let chattingContainerView = UIView() private let titleLabel = UILabel() private let chatListView = UITableView(frame: .zero, style: .plain) private let chatEmptyView = ChatEmptyView() @@ -17,6 +18,7 @@ final class ChattingListView: BaseView { private let recentChatButton = UIButton() @Published private var isScrollFixed = true + private var isAnimating = false private var recentChatButtonShowConstraints: [NSLayoutConstraint] = [] private var recentChatButtonHideConstraints: [NSLayoutConstraint] = [] @@ -48,8 +50,9 @@ final class ChattingListView: BaseView { } override func setupViews() { - addSubview(titleLabel) - addSubview(chatListView) + addSubview(chattingContainerView) + chattingContainerView.addSubview(titleLabel) + chattingContainerView.addSubview(chatListView) addSubview(recentChatButton) addSubview(chatInputField) @@ -59,7 +62,6 @@ final class ChattingListView: BaseView { chatListView.register(ChattingCell.self, forCellReuseIdentifier: ChattingCell.identifier) chatListView.register(SystemAlarmCell.self, forCellReuseIdentifier: SystemAlarmCell.identifier) chatListView.backgroundView = chatEmptyView - chatListView.bounces = false } override func setupStyles() { @@ -77,15 +79,21 @@ final class ChattingListView: BaseView { } override func setupLayouts() { + chattingContainerView.ezl.makeConstraint { + $0.horizontal(to: self) + .top(to: self) + .bottom(to: chatInputField.ezl.top) + } + titleLabel.ezl.makeConstraint { - $0.top(to: self) - .leading(to: self, offset: 20) + $0.top(to: chattingContainerView, offset: 24) + .leading(to: chattingContainerView, offset: 20) } chatListView.ezl.makeConstraint { - $0.horizontal(to: self) + $0.horizontal(to: chattingContainerView) .top(to: titleLabel.ezl.bottom, offset: 21) - .bottom(to: chatInputField.ezl.top) + .bottom(to: chattingContainerView) } chatInputField.ezl.makeConstraint { @@ -107,7 +115,7 @@ final class ChattingListView: BaseView { override func setupActions() { let tapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) - self.addGestureRecognizer(tapGesture) + chattingContainerView.addGestureRecognizer(tapGesture) $isScrollFixed .sink { [weak self] in @@ -117,8 +125,8 @@ final class ChattingListView: BaseView { recentChatButton.addAction( UIAction { [weak self] _ in - self?.updateRecentChatButtonConstraint(isHidden: true) self?.scrollToBottom() + self?.updateRecentChatButtonConstraint(isHidden: true) }, for: .touchUpInside ) @@ -138,6 +146,7 @@ final class ChattingListView: BaseView { private func scrollToBottom() { guard let indexPath = lastIndexPath() else { return } + isAnimating = true chatListView.scrollToRow(at: indexPath, at: .bottom, animated: true) } @@ -181,9 +190,13 @@ extension ChattingListView: ChatInputFieldAction { } extension ChattingListView: UITableViewDelegate { - func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { - guard let lastIndexPath = lastIndexPath(), - let indexPathList = chatListView.indexPathsForVisibleRows else { return } - isScrollFixed = indexPathList.contains(lastIndexPath) + func scrollViewDidScroll(_ scrollView: UIScrollView) { + guard !isAnimating else { return } + let offsetMaxY = scrollView.contentSize.height - scrollView.bounds.height + isScrollFixed = (offsetMaxY - 50...offsetMaxY) ~= scrollView.contentOffset.y || offsetMaxY < scrollView.contentOffset.y + } + + func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) { + isAnimating = false } } diff --git a/Projects/Features/LiveStreamFeature/Sources/Player/ViewControllers/LiveStreamViewController.swift b/Projects/Features/LiveStreamFeature/Sources/Player/ViewControllers/LiveStreamViewController.swift index 36b34f0..143f570 100644 --- a/Projects/Features/LiveStreamFeature/Sources/Player/ViewControllers/LiveStreamViewController.swift +++ b/Projects/Features/LiveStreamFeature/Sources/Player/ViewControllers/LiveStreamViewController.swift @@ -117,7 +117,7 @@ public final class LiveStreamViewController: BaseViewController