From 6fbfcb308aae5939951701fe647b119d75e8802f Mon Sep 17 00:00:00 2001 From: Ivan Grachyov Date: Thu, 9 Dec 2021 16:25:30 +0300 Subject: [PATCH] Prettify account cell --- .../Library/ButtonWithExtendedArea.swift | 22 +++++++++ .../Accounts/AccountTableViewCell.swift | 14 +++++- .../Screens/Accounts/AccountTableViewCell.xib | 46 ++++++++++++++----- .../Accounts/AccountsListViewController.swift | 11 ++++- Tokenary.xcodeproj/project.pbxproj | 12 +++++ 5 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 Tokenary iOS/Library/ButtonWithExtendedArea.swift diff --git a/Tokenary iOS/Library/ButtonWithExtendedArea.swift b/Tokenary iOS/Library/ButtonWithExtendedArea.swift new file mode 100644 index 00000000..fe260847 --- /dev/null +++ b/Tokenary iOS/Library/ButtonWithExtendedArea.swift @@ -0,0 +1,22 @@ +// Copyright © 2021 Tokenary. All rights reserved. + +import UIKit + +class ButtonWithExtendedArea: UIButton { + + var minimumHitArea = CGSize(width: 60, height: 60) + + override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { + if isHidden || !isUserInteractionEnabled || alpha < 0.01 { return nil } + + // increase the hit frame to be at least as big as `minimumHitArea` + let buttonSize = bounds.size + let widthToAdd = max(minimumHitArea.width - buttonSize.width, 0) + let heightToAdd = max(minimumHitArea.height - buttonSize.height, 0) + let largerFrame = bounds.insetBy(dx: -widthToAdd / 2, dy: -heightToAdd / 2) + + // perform hit test on larger frame + return (largerFrame.contains(point)) ? self : nil + } + +} diff --git a/Tokenary iOS/Screens/Accounts/AccountTableViewCell.swift b/Tokenary iOS/Screens/Accounts/AccountTableViewCell.swift index e12d775d..7b09d90a 100644 --- a/Tokenary iOS/Screens/Accounts/AccountTableViewCell.swift +++ b/Tokenary iOS/Screens/Accounts/AccountTableViewCell.swift @@ -3,15 +3,27 @@ import UIKit import BlockiesSwift +protocol AccountTableViewCellDelegate: AnyObject { + + func didTapMoreButton(accountCell: AccountTableViewCell) + +} + class AccountTableViewCell: UITableViewCell { + private weak var cellDelegate: AccountTableViewCellDelegate? @IBOutlet weak var avatarImageView: UIImageView! @IBOutlet weak var titleLabel: UILabel! - func setup(address: String) { + func setup(address: String, delegate: AccountTableViewCellDelegate) { + cellDelegate = delegate avatarImageView.image = Blockies(seed: address.lowercased()).createImage() let without0x = address.dropFirst(2) titleLabel.text = without0x.prefix(4) + "..." + without0x.suffix(4) } + @IBAction func moreButtonTapped(_ sender: Any) { + cellDelegate?.didTapMoreButton(accountCell: self) + } + } diff --git a/Tokenary iOS/Screens/Accounts/AccountTableViewCell.xib b/Tokenary iOS/Screens/Accounts/AccountTableViewCell.xib index 2c2651da..17568b06 100644 --- a/Tokenary iOS/Screens/Accounts/AccountTableViewCell.xib +++ b/Tokenary iOS/Screens/Accounts/AccountTableViewCell.xib @@ -9,40 +9,64 @@ - - + + - + - + - + + + + + + + - + - - + + + + + + - + + + + diff --git a/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift b/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift index 23aa7aa5..4251e798 100644 --- a/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift +++ b/Tokenary iOS/Screens/Accounts/AccountsListViewController.swift @@ -103,8 +103,17 @@ extension AccountsListViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellOfType(AccountTableViewCell.self, for: indexPath) let wallet = wallets[indexPath.row] - cell.setup(address: wallet.ethereumAddress ?? "") + cell.setup(address: wallet.ethereumAddress ?? "", delegate: self) return cell } } + +extension AccountsListViewController: AccountTableViewCellDelegate { + + func didTapMoreButton(accountCell: AccountTableViewCell) { + // TODO: implement + showMessageAlert(text: "Hello fren") + } + +} diff --git a/Tokenary.xcodeproj/project.pbxproj b/Tokenary.xcodeproj/project.pbxproj index ae243778..83e5b11e 100644 --- a/Tokenary.xcodeproj/project.pbxproj +++ b/Tokenary.xcodeproj/project.pbxproj @@ -65,6 +65,7 @@ 2C96D38F2762317300687301 /* AccountTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C96D38D2762317300687301 /* AccountTableViewCell.swift */; }; 2C96D3902762317300687301 /* AccountTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C96D38E2762317300687301 /* AccountTableViewCell.xib */; }; 2C96D392276232A300687301 /* UITableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C96D391276232A300687301 /* UITableView.swift */; }; + 2C96D3962762380400687301 /* ButtonWithExtendedArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C96D3952762380400687301 /* ButtonWithExtendedArea.swift */; }; 2C9F0B6526BDC9AF008FA3D6 /* EthereumNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C9F0B6426BDC9AF008FA3D6 /* EthereumNetwork.swift */; }; 2C9F0B6826BDCB2E008FA3D6 /* EthereumChain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C9F0B6726BDCB2E008FA3D6 /* EthereumChain.swift */; }; 2CAA412526C7CD93009F3535 /* ReviewRequester.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CAA412426C7CD93009F3535 /* ReviewRequester.swift */; }; @@ -239,6 +240,7 @@ 2C96D38D2762317300687301 /* AccountTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTableViewCell.swift; sourceTree = ""; }; 2C96D38E2762317300687301 /* AccountTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountTableViewCell.xib; sourceTree = ""; }; 2C96D391276232A300687301 /* UITableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITableView.swift; sourceTree = ""; }; + 2C96D3952762380400687301 /* ButtonWithExtendedArea.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonWithExtendedArea.swift; sourceTree = ""; }; 2C9F0B6426BDC9AF008FA3D6 /* EthereumNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumNetwork.swift; sourceTree = ""; }; 2C9F0B6726BDCB2E008FA3D6 /* EthereumChain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumChain.swift; sourceTree = ""; }; 2CAA412426C7CD93009F3535 /* ReviewRequester.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewRequester.swift; sourceTree = ""; }; @@ -423,6 +425,7 @@ children = ( 2C5FF97126C84F7B00B32ACC /* AppDelegate.swift */, 2C5FF97326C84F7B00B32ACC /* SceneDelegate.swift */, + 2C96D394276237F600687301 /* Library */, 2CC6EF0E275E64840040CC62 /* Extensions */, 2CF255BB275A74A400AE54B9 /* Screens */, 2C5FF97726C84F7B00B32ACC /* Main.storyboard */, @@ -508,6 +511,14 @@ path = Accounts; sourceTree = ""; }; + 2C96D394276237F600687301 /* Library */ = { + isa = PBXGroup; + children = ( + 2C96D3952762380400687301 /* ButtonWithExtendedArea.swift */, + ); + path = Library; + sourceTree = ""; + }; 2CC6EF0E275E64840040CC62 /* Extensions */ = { isa = PBXGroup; children = ( @@ -1054,6 +1065,7 @@ buildActionMask = 2147483647; files = ( 2CF255BA275A749300AE54B9 /* ApproveViewController.swift in Sources */, + 2C96D3962762380400687301 /* ButtonWithExtendedArea.swift in Sources */, 2CF25599275A46E200AE54B9 /* PeerMeta.swift in Sources */, 2CF255A0275A47DD00AE54B9 /* Bundle.swift in Sources */, 2CF255AC275A48CF00AE54B9 /* EthereumNetwork.swift in Sources */,