Skip to content

Commit

Permalink
Merge pull request #541 from Adamant-im/dev/trello.com/c/j08aAwNP
Browse files Browse the repository at this point in the history
[trello.com/c/j08aAwNP] Feat: Scroll Up button in the chat list
  • Loading branch information
IanaaDvlp authored Oct 5, 2024
2 parents 7a4f159 + 9ede6c7 commit 6f46bc7
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Adamant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
93A118532993241D00E144CC /* ChatMessagesListFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A118522993241D00E144CC /* ChatMessagesListFactory.swift */; };
93A18C862AAEACC100D0AB98 /* AdamantWalletFactoryCompose.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A18C852AAEACC100D0AB98 /* AdamantWalletFactoryCompose.swift */; };
93A18C892AAEAE7700D0AB98 /* WalletFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A18C882AAEAE7700D0AB98 /* WalletFactory.swift */; };
93A91FD1297972B7001DB1F8 /* ChatScrollDownButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A91FD0297972B7001DB1F8 /* ChatScrollDownButton.swift */; };
93A91FD1297972B7001DB1F8 /* ChatScrollButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A91FD0297972B7001DB1F8 /* ChatScrollButton.swift */; };
93A91FD329799298001DB1F8 /* ChatStartPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93A91FD229799298001DB1F8 /* ChatStartPosition.swift */; };
93ADE0712ACA66AF008ED641 /* VibrationSelectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93ADE06E2ACA66AF008ED641 /* VibrationSelectionViewModel.swift */; };
93ADE0722ACA66AF008ED641 /* VibrationSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93ADE06F2ACA66AF008ED641 /* VibrationSelectionView.swift */; };
Expand Down Expand Up @@ -1037,7 +1037,7 @@
93A118522993241D00E144CC /* ChatMessagesListFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatMessagesListFactory.swift; sourceTree = "<group>"; };
93A18C852AAEACC100D0AB98 /* AdamantWalletFactoryCompose.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdamantWalletFactoryCompose.swift; sourceTree = "<group>"; };
93A18C882AAEAE7700D0AB98 /* WalletFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletFactory.swift; sourceTree = "<group>"; };
93A91FD0297972B7001DB1F8 /* ChatScrollDownButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatScrollDownButton.swift; sourceTree = "<group>"; };
93A91FD0297972B7001DB1F8 /* ChatScrollButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatScrollButton.swift; sourceTree = "<group>"; };
93A91FD229799298001DB1F8 /* ChatStartPosition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatStartPosition.swift; sourceTree = "<group>"; };
93ADE06E2ACA66AF008ED641 /* VibrationSelectionViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VibrationSelectionViewModel.swift; sourceTree = "<group>"; };
93ADE06F2ACA66AF008ED641 /* VibrationSelectionView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VibrationSelectionView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2026,7 +2026,7 @@
413AD21A29CDDD750025F255 /* ChatReply */,
9377FBE0296C2AB700C9211B /* ChatTransaction */,
938F7D652955C966001915CA /* ChatInputBar.swift */,
93A91FD0297972B7001DB1F8 /* ChatScrollDownButton.swift */,
93A91FD0297972B7001DB1F8 /* ChatScrollButton.swift */,
9371130E2996EDA900F64CF9 /* ChatRefreshMock.swift */,
93996A962968209C008D080B /* ChatMessagesCollection.swift */,
9382F61229DEC0A3005E6216 /* ChatModelView.swift */,
Expand Down Expand Up @@ -3580,7 +3580,7 @@
E9FAE5DA203DBFEF008D3A6B /* Comparable+clamped.swift in Sources */,
93A91FD329799298001DB1F8 /* ChatStartPosition.swift in Sources */,
3A2F55F92AC6F308000A3F26 /* CoinTransaction+CoreDataClass.swift in Sources */,
93A91FD1297972B7001DB1F8 /* ChatScrollDownButton.swift in Sources */,
93A91FD1297972B7001DB1F8 /* ChatScrollButton.swift in Sources */,
3AA3880A2B69173500125684 /* DashNetworkInfoDTO.swift in Sources */,
41C1698C29E7F34900FEB3CB /* RichTransactionReplyService.swift in Sources */,
935F53D629BE8F7400779492 /* TransactionStatusPublisher.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions Adamant/Modules/Chat/View/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ private extension ChatViewController {
// MARK: Making entities

private extension ChatViewController {
func makeScrollDownButton() -> ChatScrollDownButton {
let button = ChatScrollDownButton()
func makeScrollDownButton() -> ChatScrollButton {
let button = ChatScrollButton(position: .down)
button.action = { [weak self] in
guard let id = self?.viewModel.getTempOffset(visibleIndex: self?.messagesCollectionView.indexPathsForVisibleItems.last?.section)
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,43 @@
import UIKit
import SnapKit

final class ChatScrollDownButton: UIView {
enum Position {
case up
case down
}

final class ChatScrollButton: UIView {
private lazy var button: UIButton = {
let button = UIButton(type: .custom)
button.setImage(.asset(named: "ScrollDown"), for: .normal)
button.alpha = 0.5
switch position {
case .up:
button.setImage(.asset(named: "scrollUp"), for: .normal)
case .down:
button.setImage(.asset(named: "ScrollDown"), for: .normal)
}
button.addTarget(self, action: #selector(onTap), for: .touchUpInside)
return button
}()

private let position: Position

var action: (() -> Void)?

override init(frame: CGRect) {
init(frame: CGRect = .zero, position: Position) {
self.position = position
super.init(frame: frame)
configure()
}

required init?(coder: NSCoder) {
self.position = .down
super.init(coder: coder)
configure()
}
}

private extension ChatScrollDownButton {
private extension ChatScrollButton {
func configure() {
addSubview(button)
button.snp.makeConstraints {
Expand Down
26 changes: 25 additions & 1 deletion Adamant/Modules/ChatsList/ChatListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ final class ChatListViewController: KeyboardObservingViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var newChatButton: UIBarButtonItem!

private lazy var scrollUpButton = ChatScrollButton(position: .up)

// MARK: Properties
var chatsController: NSFetchedResultsController<Chatroom>?
var unreadController: NSFetchedResultsController<ChatTransaction>?
Expand Down Expand Up @@ -187,7 +189,8 @@ final class ChatListViewController: KeyboardObservingViewController {
busyIndicatorView.layer.cornerRadius = 14
busyIndicatorView.clipsToBounds = true

addObservers()
configureScrollUpButton()
addObservers()
setColors()
}

Expand Down Expand Up @@ -259,6 +262,22 @@ final class ChatListViewController: KeyboardObservingViewController {
tableView.tableHeaderView = UIView()
}

func configureScrollUpButton() {
view.addSubview(scrollUpButton)

scrollUpButton.isHidden = true

scrollUpButton.action = { [weak self] in
self?.tableView.scrollToRow(at: IndexPath(row: .zero, section: .zero), at: .top, animated: true)
}

scrollUpButton.snp.makeConstraints { make in
make.trailing.equalToSuperview().offset(-20)
make.top.equalTo(view.safeAreaLayoutGuide).offset(20)
make.size.equalTo(30)
}
}

// MARK: Add Observers

private func addObservers() {
Expand Down Expand Up @@ -577,6 +596,11 @@ extension ChatListViewController: UITableViewDelegate, UITableViewDataSource {
}
}
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y + scrollView.safeAreaInsets.top
scrollUpButton.isHidden = offsetY < cellHeight * 0.75
}
}

// MARK: - UITableView Cells
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "scrollUp.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6f46bc7

Please sign in to comment.