Merge pull request #3249 from vladyslav-iosdev/#3248

Prepare build for iOS 15 #3248
pull/3277/head
Hwee-Boon Yar 3 years ago committed by GitHub
commit 709e89cbfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      AlphaWallet/Accounts/ViewControllers/AccountsViewController.swift
  2. 3
      AlphaWallet/Core/Views/DropDownView.swift
  3. 2
      AlphaWallet/Settings/ViewControllers/AdvancedSettingsViewController.swift
  4. 2
      AlphaWallet/Settings/ViewControllers/EnabledServersViewController.swift
  5. 2
      AlphaWallet/Settings/ViewControllers/ServersViewController.swift
  6. 49
      AlphaWallet/Settings/ViewControllers/SettingsViewController.swift
  7. 1
      AlphaWallet/Settings/ViewControllers/SupportViewController.swift
  8. 36
      AlphaWallet/Settings/Views/SettingTableViewCell.swift
  9. 23
      AlphaWallet/Settings/Views/SettingViewHeader.swift
  10. 21
      AlphaWallet/Settings/Views/SwitchTableViewCell.swift
  11. 23
      AlphaWallet/Style/AppStyle.swift
  12. 29
      AlphaWallet/Tokens/ViewControllers/AddHideTokensViewController.swift
  13. 2
      AlphaWallet/Tokens/ViewControllers/TokensViewController.swift
  14. 11
      AlphaWallet/Tokens/ViewModels/AddHideTokenSectionHeaderViewModel.swift
  15. 116
      AlphaWallet/Tokens/Views/AddHideTokenSectionHeaderView.swift
  16. 11
      AlphaWallet/Tokens/Views/PopularTokenViewCell.swift
  17. 75
      AlphaWallet/Tokens/Views/TokensViewControllerTableViewSectionHeader.swift
  18. 12
      AlphaWallet/Tokens/Views/WalletTokenViewCell.swift
  19. 2
      AlphaWallet/UI/AddressTextField.swift
  20. 47
      AlphaWallet/UI/Views/TextView.swift
  21. 6
      AlphaWallet/Wallet/ViewControllers/ImportWalletViewController.swift

@ -11,7 +11,20 @@ protocol AccountsViewControllerDelegate: AnyObject {
class AccountsViewController: UIViewController {
private let roundedBackground = RoundedBackground()
private let tableView = UITableView(frame: .zero, style: .plain)
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .singleLine
tableView.backgroundColor = GroupedTable.Color.background
tableView.tableFooterView = UIView()
tableView.rowHeight = UITableView.automaticDimension
tableView.register(AccountViewCell.self)
tableView.register(WalletSummaryTableViewCell.self)
tableView.addSubview(tableViewRefreshControl)
return tableView
}()
private var viewModel: AccountsViewModel
private let config: Config
private let keystore: Keystore
@ -30,28 +43,14 @@ class AccountsViewController: UIViewController {
super.init(nibName: nil, bundle: nil)
roundedBackground.backgroundColor = GroupedTable.Color.background
roundedBackground.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(roundedBackground)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .singleLine
tableView.backgroundColor = GroupedTable.Color.background
tableView.tableFooterView = UIView()
tableView.rowHeight = UITableView.automaticDimension
tableView.register(AccountViewCell.self)
tableView.register(WalletSummaryTableViewCell.self)
tableView.addSubview(tableViewRefreshControl)
roundedBackground.addSubview(tableView)
NSLayoutConstraint.activate([
tableView.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor),
tableView.topAnchor.constraint(equalTo: roundedBackground.topAnchor),
tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
] + roundedBackground.createConstraintsWithContainer(view: view))
NSLayoutConstraint.activate(
tableView.anchorsConstraintSafeArea(to: roundedBackground) +
roundedBackground.createConstraintsWithContainer(view: view)
)
}
private lazy var tableViewRefreshControl: UIRefreshControl = {
@ -209,6 +208,10 @@ extension AccountsViewController: UITableViewDataSource {
extension AccountsViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return viewModel.shouldHideHeader(in: section).shouldHide ? .leastNormalMagnitude : UITableView.automaticDimension
}
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let value = viewModel.shouldHideHeader(in: section)
let headerView = AccountViewTableSectionHeader()

@ -63,7 +63,8 @@ final class DropDownView<T: DropDownItemType>: UIView, ReusableTableHeaderViewTy
button.setImage(R.image.iconsSystemExpandMore(), for: .normal)
button.imageView?.contentMode = .scaleAspectFit
button.semanticContentAttribute = .forceRightToLeft
button.heightConstraint.flatMap { NSLayoutConstraint.deactivate([$0]) }
return button
}()

@ -20,7 +20,7 @@ class AdvancedSettingsViewController: UIViewController {
private lazy var viewModel: AdvancedSettingsViewModel = AdvancedSettingsViewModel()
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.tableFooterView = UIView.tableFooterToRemoveEmptyCellSeparators()
tableView.register(SettingTableViewCell.self)
tableView.register(SwitchTableViewCell.self)

@ -16,7 +16,7 @@ class EnabledServersViewController: UIViewController {
private let roundedBackground = RoundedBackground()
private let headers = (mainnet: EnableServersHeaderView(), testnet: EnableServersHeaderView())
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.delegate = self
tableView.separatorStyle = .singleLine

@ -8,7 +8,7 @@ protocol ServersViewControllerDelegate: AnyObject {
class ServersViewController: UIViewController {
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.delegate = self
tableView.dataSource = self

@ -23,21 +23,20 @@ class SettingsViewController: UIViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let promptBackupWalletViewHolder = UIView()
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.tableFooterView = UIView.tableFooterToRemoveEmptyCellSeparators()
tableView.registerHeaderFooterView(SettingViewHeader.self)
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.register(SettingTableViewCell.self)
tableView.register(SwitchTableViewCell.self)
tableView.separatorStyle = .singleLine
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.dataSource = self
tableView.delegate = self
tableView.estimatedRowHeight = TokensCardViewController.anArbitraryRowHeightSoAutoSizingCellsWorkIniOS10
tableView.tableFooterView = UIView.tableFooterToRemoveEmptyCellSeparators()
return tableView
}()
private lazy var viewModel: SettingsViewModel = SettingsViewModel(account: account, keystore: keystore)
private let roundedBackground = RoundedBackground()
weak var delegate: SettingsViewControllerDelegate?
var promptBackupWalletView: UIView? {
didSet {
@ -67,17 +66,11 @@ class SettingsViewController: UIViewController {
self.analyticsCoordinator = analyticsCoordinator
super.init(nibName: nil, bundle: nil)
roundedBackground.backgroundColor = GroupedTable.Color.background
view.addSubview(roundedBackground)
roundedBackground.addSubview(tableView)
view.addSubview(tableView)
NSLayoutConstraint.activate([
tableView.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor),
tableView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor),
tableView.topAnchor.constraint(equalTo: roundedBackground.topAnchor),
tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
] + roundedBackground.createConstraintsWithContainer(view: view))
tableView.anchorsConstraint(to: view)
])
}
override func viewDidLoad() {
@ -124,7 +117,7 @@ class SettingsViewController: UIViewController {
}
}
private func configureChangeWalletCellWithResolvedENS(_ row: SettingsWalletRow, cell: SettingTableViewCell) {
private func configureChangeWalletCellWithResolvedENS(_ row: SettingsWalletRow, indexPath: IndexPath, cell: SettingTableViewCell) {
cell.configure(viewModel: .init(
titleText: row.title,
subTitleText: viewModel.addressReplacedWithENSOrWalletName(),
@ -134,8 +127,8 @@ class SettingsViewController: UIViewController {
firstly {
GetWalletNameCoordinator(config: config).getName(forAddress: account.address)
}.done { [weak self] name in
guard let strongSelf = self else { return }
//TODO check if still correct cell, since this is async
//NOTE check if still correct cell, since this is async
guard let strongSelf = self, cell.indexPath == indexPath else { return }
let viewModel: SettingTableViewCellViewModel = .init(
titleText: row.title,
subTitleText: strongSelf.viewModel.addressReplacedWithENSOrWalletName(name),
@ -231,7 +224,7 @@ extension SettingsViewController: UITableViewDataSource {
let row = rows[indexPath.row]
switch row {
case .changeWallet:
configureChangeWalletCellWithResolvedENS(row, cell: cell)
configureChangeWalletCellWithResolvedENS(row, indexPath: indexPath, cell: cell)
return cell
case .backup:
@ -254,14 +247,18 @@ extension SettingsViewController: UITableViewDataSource {
extension SettingsViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
//Hide the footer
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
.leastNormalMagnitude
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
nil
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView: SettingViewHeader = tableView.dequeueReusableHeaderFooterView()
let section = viewModel.sections[section]
let viewModel = SettingViewHeaderViewModel(section: section)
let headerView: SettingViewHeader = SettingViewHeader()
let viewModel = SettingViewHeaderViewModel(section: self.viewModel.sections[section])
headerView.configure(viewModel: viewModel)
return headerView
@ -288,9 +285,7 @@ extension SettingsViewController: UITableViewDelegate {
switch rows[indexPath.row] {
case .advanced:
delegate?.settingsViewControllerAdvancedSettingsSelected(in: self)
case .notifications:
break
case .passcode:
case .notifications, .passcode:
break
case .selectActiveNetworks:
delegate?.settingsViewControllerActiveNetworksSelected(in: self)

@ -17,7 +17,6 @@ class SupportViewController: UIViewController {
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.tableFooterView = UIView.tableFooterToRemoveEmptyCellSeparators()
tableView.register(SettingViewHeader.self, forHeaderFooterViewReuseIdentifier: SettingViewHeader.reusableIdentifier)
tableView.register(SettingTableViewCell.self)
tableView.separatorStyle = .singleLine
tableView.backgroundColor = GroupedTable.Color.background

@ -13,6 +13,12 @@ class SettingTableViewCell: UITableViewCell {
imageView.contentMode = .scaleAspectFill
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.clipsToBounds = true
NSLayoutConstraint.activate([
imageView.widthAnchor.constraint(equalToConstant: 40),
imageView.heightAnchor.constraint(equalToConstant: 40),
])
return imageView
}()
@ -41,39 +47,27 @@ class SettingTableViewCell: UITableViewCell {
return label
}()
private var iconAndTextTopBottomConstraints: [NSLayoutConstraint] = []
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
selectionStyle = .none
accessoryType = .disclosureIndicator
let stackView = [
let col1 = [
titleLabel,
subTitleLabel
].asStackView(axis: .vertical, spacing: 0)
let stackView = [
iconImageView, col1
].asStackView(axis: .horizontal, spacing: 16, alignment: .center)
stackView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(iconImageView)
contentView.addSubview(stackView)
iconAndTextTopBottomConstraints = [
iconImageView.topAnchor.constraint(greaterThanOrEqualTo: contentView.topAnchor, constant: 10),
iconImageView.bottomAnchor.constraint(greaterThanOrEqualTo: contentView.bottomAnchor, constant: -10),
stackView.topAnchor.constraint(greaterThanOrEqualTo: contentView.topAnchor, constant: 10),
stackView.bottomAnchor.constraint(greaterThanOrEqualTo: contentView.bottomAnchor, constant: 10),
]
NSLayoutConstraint.activate([
iconImageView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
iconImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
iconImageView.widthAnchor.constraint(equalToConstant: 40),
iconImageView.heightAnchor.constraint(equalToConstant: 40),
stackView.leadingAnchor.constraint(equalTo: iconImageView.trailingAnchor, constant: 16),
stackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
stackView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
] + iconAndTextTopBottomConstraints)
stackView.anchorsConstraint(to: contentView, edgeInsets: .init(top: 10, left: 16, bottom: 10, right: 10))
])
}
override func prepareForReuse() {
@ -93,9 +87,5 @@ class SettingTableViewCell: UITableViewCell {
subTitleLabel.isHidden = viewModel.subTitleHidden
subTitleLabel.font = viewModel.subTitleFont
subTitleLabel.textColor = viewModel.subTitleTextColor
for constraint in iconAndTextTopBottomConstraints {
constraint.constant = viewModel.subTitleHidden ? 10 : 20
}
}
}

@ -7,7 +7,7 @@
import UIKit
class SettingViewHeader: UITableViewHeaderFooterView {
class SettingViewHeader: UIView {
private let titleLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
@ -37,27 +37,26 @@ class SettingViewHeader: UITableViewHeaderFooterView {
private var topSeparatorHeight: NSLayoutConstraint!
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
init() {
super.init(frame: .zero)
let stackView = [
topSeparator,
.spacer(height: 13, backgroundColor: .clear),
[.spacerWidth(16), titleLabel, detailsLabel, .spacerWidth(16)].asStackView(axis: .horizontal),
[.spacerWidth(16), titleLabel, detailsLabel, .spacerWidth(16)].asStackView(axis: .horizontal, alignment: .center),
.spacer(height: 13, backgroundColor: .clear),
bottomSperator
].asStackView(axis: .vertical)
stackView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(stackView)
addSubview(stackView)
topSeparatorHeight = topSeparator.heightAnchor.constraint(equalToConstant: 1)
NSLayoutConstraint.activate([
stackView.anchorsConstraint(to: contentView),
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
bottomSperator.heightAnchor.constraint(equalToConstant: 1)
stackView.anchorsConstraint(to: self),
bottomSperator.heightAnchor.constraint(equalToConstant: 1),
topSeparatorHeight
])
topSeparatorHeight = topSeparator.heightAnchor.constraint(equalToConstant: 1)
topSeparatorHeight.isActive = true
}
required init?(coder aDecoder: NSCoder) {
@ -74,7 +73,7 @@ class SettingViewHeader: UITableViewHeaderFooterView {
detailsLabel.font = viewModel.detailsTextFont
topSeparator.backgroundColor = viewModel.separatorColor
bottomSperator.backgroundColor = viewModel.separatorColor
contentView.backgroundColor = viewModel.backgroundColor
backgroundColor = viewModel.backgroundColor
topSeparatorHeight.constant = viewModel.showTopSeparator ? 1 : 0
}
}

@ -42,29 +42,22 @@ class SwitchTableViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
switchView.addTarget(self, action: #selector(switchChanged(_:)), for: .valueChanged)
switchView.addTarget(self, action: #selector(switchChanged), for: .valueChanged)
selectionStyle = .none
accessoryType = .none
contentView.addSubview(titleLabel)
contentView.addSubview(iconImageView)
contentView.addSubview(switchView)
let stackView = [
iconImageView, titleLabel, .spacerWidth(flexible: true), switchView
].asStackView(axis: .horizontal, spacing: 16)
stackView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(stackView)
NSLayoutConstraint.activate([
iconImageView.topAnchor.constraint(greaterThanOrEqualTo: contentView.topAnchor, constant: 10),
iconImageView.bottomAnchor.constraint(greaterThanOrEqualTo: contentView.bottomAnchor, constant: -10),
iconImageView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
iconImageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
iconImageView.widthAnchor.constraint(equalToConstant: 40),
iconImageView.heightAnchor.constraint(equalToConstant: 40),
titleLabel.leadingAnchor.constraint(equalTo: iconImageView.trailingAnchor, constant: 16),
titleLabel.trailingAnchor.constraint(equalTo: switchView.leadingAnchor),
titleLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
switchView.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
switchView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -20),
stackView.anchorsConstraint(to: contentView, edgeInsets: .init(top: 10, left: 16, bottom: 10, right: 20))
])
}

@ -19,6 +19,29 @@ func applyStyle() {
.font: Fonts.bold(size: 36) as Any,
]
// NOTE: Fixes iOS 15 navigation bar black background
if #available(iOS 15.0, *) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = Colors.appBackground
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
} else {
// Fallback on earlier versions
}
if #available(iOS 13.0, *) {
//NOTE: Hides back button text
let titleTextAttributes: [NSAttributedString.Key : Any] = [
.foregroundColor: UIColor.clear
]
UINavigationBar.appearance().standardAppearance.backButtonAppearance.normal.titleTextAttributes = titleTextAttributes
UINavigationBar.appearance().compactAppearance?.backButtonAppearance.normal.titleTextAttributes = titleTextAttributes
UINavigationBar.appearance().scrollEdgeAppearance?.backButtonAppearance.normal.titleTextAttributes = titleTextAttributes
} else {
// Fallback on earlier versions
}
//We could have set the backBarButtonItem with an empty title for every view controller, but we don't have a place to do it for Eureka view controllers. Using appearance here, while a hack is still more convenient though, since we don't have to do it for every view controller instance
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -200, vertical: 0), for: .default)
UIBarButtonItem.appearance().tintColor = Colors.navigationButtonTintColor

@ -20,17 +20,13 @@ class AddHideTokensViewController: UIViewController {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.register(WalletTokenViewCell.self)
tableView.register(PopularTokenViewCell.self)
tableView.registerHeaderFooterView(AddHideTokenSectionHeaderView.self)
tableView.registerHeaderFooterView(TokensViewController.GeneralTableViewSectionHeader<DropDownView<SortTokensParam>>.self)
//NOTE: Facing strange behavoir, while using isEditing for table view it brakes constraints while `isEditing = false` its not.
tableView.isEditing = true
tableView.estimatedRowHeight = 100
tableView.dataSource = self
tableView.delegate = self
tableView.separatorStyle = .singleLine
tableView.separatorInset = .zero
tableView.contentInset = .zero
tableView.contentOffset = .zero
tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.size.width, height: 0.01))
tableView.estimatedRowHeight = DataEntry.Metric.TableView.estimatedRowHeight
tableView.translatesAutoresizingMaskIntoConstraints = false
return tableView
@ -45,7 +41,6 @@ class AddHideTokensViewController: UIViewController {
}()
private var bottomConstraint: NSLayoutConstraint!
private lazy var keyboardChecker = KeyboardChecker(self, resetHeightDefaultValue: 0, ignoreBottomSafeArea: true)
weak var delegate: AddHideTokensViewControllerDelegate?
init(viewModel: AddHideTokensViewModel, assetDefinitionStore: AssetDefinitionStore) {
@ -270,6 +265,7 @@ extension AddHideTokensViewController: UITableViewDataSource {
}
extension AddHideTokensViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
viewModel.editingStyle(indexPath: indexPath)
}
@ -292,26 +288,17 @@ extension AddHideTokensViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
switch viewModel.sections[section] {
case .sortingFilters:
let header: TokensViewController.GeneralTableViewSectionHeader<DropDownView<SortTokensParam>> = tableView.dequeueReusableHeaderFooterView()
let header = TokensViewController.ContainerView(subview: tokenFilterView)
header.useSeparatorLine = true
header.subview = tokenFilterView
return header
case .availableNewTokens, .popularTokens, .hiddenTokens, .displayedTokens:
let view: AddHideTokenSectionHeaderView = tableView.dequeueReusableHeaderFooterView()
view.configure(viewModel: .init(text: viewModel.titleForSection(section)))
return view
let viewModel: AddHideTokenSectionHeaderViewModel = .init(titleText: self.viewModel.titleForSection(section))
return AddHideTokensViewController.functional.headerView(for: section, viewModel: viewModel)
}
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
switch viewModel.sections[section] {
case .sortingFilters:
return 60
case .availableNewTokens, .popularTokens, .hiddenTokens, .displayedTokens:
return 65
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
//Hide the footer

@ -46,7 +46,7 @@ class TokensViewController: UIViewController {
lazy private var tableViewFilterView = SegmentedControl.tokensSegmentControl(titles: TokensViewModel.segmentedControlTitles)
lazy private var collectiblesCollectionViewFilterView = SegmentedControl.tokensSegmentControl(titles: TokensViewModel.segmentedControlTitles)
private lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.register(FungibleTokenViewCell.self)
tableView.register(EthTokenViewCell.self)
tableView.register(NonFungibleTokenViewCell.self)

@ -8,10 +8,11 @@
import UIKit
struct AddHideTokenSectionHeaderViewModel {
let text: String
var separatorColor: UIColor {
GroupedTable.Color.cellSeparator
}
let titleText: String
var separatorColor: UIColor = GroupedTable.Color.cellSeparator
var titleTextFont: UIFont = Fonts.bold(size: 24)
var titleTextColor: UIColor = .black
var backgroundColor: UIColor = Colors.appBackground
var showTopSeparator: Bool = false
}

@ -1,76 +1,78 @@
// Copyright © 2020 Stormbird PTE. LTD.
import UIKit
extension AddHideTokensViewController {
class functional {}
}
extension AddHideTokensViewController.functional {
static func headerView(for section: Int, viewModel: AddHideTokenSectionHeaderViewModel) -> UIView {
let view = AddHideTokenSectionHeaderView()
view.configure(viewModel: viewModel)
return view
}
}
private class AddHideTokenSectionHeaderView: UIView {
class AddHideTokenSectionHeaderView: UITableViewHeaderFooterView {
private lazy var titleLabel: UILabel = {
private let titleLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = Fonts.bold(size: 24)
label.textColor = .black
return label
}()
var rightAccessoryView: UIView? {
didSet {
if let view = rightAccessoryView {
setup(rightAccessoryView: view)
} else if let oldValue = oldValue {
oldValue.removeFromSuperview()
}
}
}
private var separatorView: UIView = {
private let topSeparator: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = R.color.mercury()
return view
}()
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
setupViews()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func awakeFromNib() {
super.awakeFromNib()
setupViews()
}
private func setupViews() {
backgroundColor = .white
contentView.backgroundColor = .white
addSubview(titleLabel)
addSubview(separatorView)
private let bottomSperator: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = R.color.mercury()
return view
}()
private var topSeparatorHeight: NSLayoutConstraint!
init() {
super.init(frame: .zero)
let stackView = [
topSeparator,
.spacer(height: 20, backgroundColor: .clear),
[.spacerWidth(16), titleLabel, .spacerWidth(16)].asStackView(axis: .horizontal),
.spacer(height: 20, backgroundColor: .clear),
bottomSperator
].asStackView(axis: .vertical)
stackView.translatesAutoresizingMaskIntoConstraints = false
addSubview(stackView)
NSLayoutConstraint.activate([
titleLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
separatorView.centerXAnchor.constraint(equalTo: centerXAnchor),
separatorView.widthAnchor.constraint(equalTo: widthAnchor),
separatorView.heightAnchor.constraint(equalToConstant: GroupedTable.Metric.cellSeparatorHeight),
separatorView.bottomAnchor.constraint(equalTo: bottomAnchor)
stackView.anchorsConstraint(to: self),
bottomSperator.heightAnchor.constraint(equalToConstant: 1)
])
topSeparatorHeight = topSeparator.heightAnchor.constraint(equalToConstant: 1)
topSeparatorHeight.isActive = true
}
private func setup(rightAccessoryView: UIView) {
addSubview(rightAccessoryView)
NSLayoutConstraint.activate([
rightAccessoryView.widthAnchor.constraint(equalTo: widthAnchor),
rightAccessoryView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16)
])
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(viewModel: AddHideTokenSectionHeaderViewModel) {
titleLabel.text = viewModel.text
separatorView.backgroundColor = viewModel.separatorColor
titleLabel.text = viewModel.titleText
titleLabel.textColor = viewModel.titleTextColor
titleLabel.font = viewModel.titleTextFont
topSeparator.backgroundColor = viewModel.separatorColor
bottomSperator.backgroundColor = viewModel.separatorColor
backgroundColor = viewModel.backgroundColor
topSeparatorHeight.constant = viewModel.showTopSeparator ? 1 : 0
}
}

@ -25,17 +25,14 @@ class PopularTokenViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(background)
background.translatesAutoresizingMaskIntoConstraints = false
let col0 = tokenIconImageView
let col1 = [
[titleLabel, UIView.spacerWidth(flexible: true)].asStackView(spacing: 5)
].asStackView(axis: .vertical, spacing: 2)
let stackView = [col0, col1].asStackView(spacing: 12, alignment: .center)
let stackView = [
tokenIconImageView, titleLabel, UIView.spacerWidth(flexible: true)
].asStackView(axis: .horizontal, spacing: 12, alignment: .center)
stackView.translatesAutoresizingMaskIntoConstraints = false
background.addSubview(stackView)
background.addSubview(stackView)
NSLayoutConstraint.activate([
tokenIconImageView.heightAnchor.constraint(equalToConstant: 40),

@ -10,6 +10,7 @@ protocol ReusableTableHeaderViewType: UIView, WithReusableIdentifier {
extension TokensViewController {
class GeneralTableViewSectionHeader<T: ReusableTableHeaderViewType>: UITableViewHeaderFooterView {
private var snapConstraints: [NSLayoutConstraint] = []
var subview: T? {
didSet {
guard let subview = subview else {
@ -24,10 +25,13 @@ extension TokensViewController {
contentView.addSubview(subview)
contentView.addSubview(bottomSeparator)
contentView.addSubview(topSeparator)
NSLayoutConstraint.activate([
subview.anchorsConstraint(to: contentView),
] + topSeparator.anchorSeparatorToTop(to: contentView) + bottomSeparator.anchorSeparatorToBottom(to: contentView))
NSLayoutConstraint.deactivate(snapConstraints)
snapConstraints = subview.anchorsConstraint(to: contentView) +
topSeparator.anchorSeparatorToTop(to: contentView) +
bottomSeparator.anchorSeparatorToBottom(to: contentView)
NSLayoutConstraint.activate(snapConstraints)
}
}
@ -74,6 +78,69 @@ extension TokensViewController {
return nil
}
}
class ContainerView<T: UIView>: UIView {
private var snapConstraints: [NSLayoutConstraint] = []
var subview: T {
didSet {
stackView.removeAllArrangedSubviews()
stackView.addArrangedSubviews([topSeparator, subview, bottomSeparator])
}
}
private (set) var bottomSeparator: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private (set) var topSeparator: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
var useSeparatorLine: Bool {
get {
!bottomSeparator.isHidden
}
set {
bottomSeparator.isHidden = !newValue
topSeparator.isHidden = !newValue
}
}
private let stackView: UIStackView = [].asStackView(axis: .vertical)
init(subview: T) {
self.subview = subview
super.init(frame: .zero)
stackView.translatesAutoresizingMaskIntoConstraints = false
backgroundColor = Colors.appWhite
bottomSeparator.isHidden = true
topSeparator.isHidden = true
bottomSeparator.backgroundColor = GroupedTable.Color.cellSeparator
topSeparator.backgroundColor = GroupedTable.Color.cellSeparator
addSubview(stackView)
NSLayoutConstraint.activate([
topSeparator.heightAnchor.constraint(equalToConstant: 1),
bottomSeparator.heightAnchor.constraint(equalToConstant: 1),
stackView.anchorsConstraint(to: self)
])
stackView.addArrangedSubviews([topSeparator, subview, bottomSeparator])
}
required init?(coder aDecoder: NSCoder) {
return nil
}
}
}
extension UIView {

@ -28,17 +28,13 @@ class WalletTokenViewCell: UITableViewCell {
contentView.addSubview(background)
background.translatesAutoresizingMaskIntoConstraints = false
cryptoValueLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
cryptoValueLabel.setContentHuggingPriority(.required, for: .horizontal)
let col0 = tokenIconImageView
let col1 = [
let stackView = [
tokenIconImageView,
[cryptoValueLabel, titleLabel, UIView.spacerWidth(flexible: true)].asStackView(spacing: 5)
].asStackView(axis: .vertical, spacing: 2)
let stackView = [col0, col1].asStackView(spacing: 12, alignment: .center)
].asStackView(spacing: 12, alignment: .center)
stackView.translatesAutoresizingMaskIntoConstraints = false
background.addSubview(stackView)
NSLayoutConstraint.activate([
tokenIconImageView.heightAnchor.constraint(equalToConstant: 40),
tokenIconImageView.widthAnchor.constraint(equalToConstant: 40),

@ -50,7 +50,6 @@ class AddressTextField: UIControl {
button.setContentHuggingPriority(.required, for: .horizontal)
button.setContentCompressionResistancePriority(.required, for: .horizontal)
button.titleEdgeInsets = .zero
button.contentEdgeInsets = .zero
return button
}()
@ -67,7 +66,6 @@ class AddressTextField: UIControl {
button.setContentHuggingPriority(.required, for: .horizontal)
button.setContentCompressionResistancePriority(.required, for: .horizontal)
button.titleEdgeInsets = .zero
button.contentEdgeInsets = .zero
return button
}()

@ -37,6 +37,8 @@ class TextView: UIControl {
}
set {
textView.text = newValue
let notification = Notification(name: UITextView.textDidChangeNotification, object: textView)
notifications.post(notification)
}
}
var inputAccessoryButtonType = InputAccessoryButtonType.none {
@ -90,26 +92,55 @@ class TextView: UIControl {
button.setBackgroundColor(.clear, forState: .normal)
button.contentHorizontalAlignment = .right
button.heightConstraint.flatMap { NSLayoutConstraint.deactivate([$0]) }
button.contentEdgeInsets = .zero
return button
}()
var clearButton: Button = {
let button = Button(size: .normal, style: .borderless)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle("Clear", for: .normal)
button.titleLabel?.font = DataEntry.Font.accessory
button.setTitleColor(DataEntry.Color.icon, for: .normal)
button.setBackgroundColor(.clear, forState: .normal)
button.contentHorizontalAlignment = .right
button.heightConstraint.flatMap { NSLayoutConstraint.deactivate([$0]) }
button.contentEdgeInsets = .zero
return button
}()
private var isConfigured = false
weak var delegate: TextViewDelegate?
private let notifications = NotificationCenter.default
init() {
super.init(frame: .zero)
pasteButton.addTarget(self, action: #selector(pasteAction), for: .touchUpInside)
clearButton.addTarget(self, action: #selector(clearAction), for: .touchUpInside)
translatesAutoresizingMaskIntoConstraints = false
textView.translatesAutoresizingMaskIntoConstraints = false
textView.delegate = self
textView.textContainerInset = .init(top: 10, left: 12, bottom: 10, right: 12)
updateClearAndPasteButtons(value)
addSubview(textView)
NSLayoutConstraint.activate([
textView.anchorsConstraint(to: self),
])
notifications.addObserver(self,
selector: #selector(textDidChangeNotification),
name: UITextView.textDidChangeNotification, object: nil)
}
@objc func clearAction() {
value = String()
errorState = .none
}
var statusContainerView: UIStackView {
@ -124,6 +155,7 @@ class TextView: UIControl {
let addressControlsStackView = [
pasteButton,
clearButton
].asStackView(axis: .horizontal)
addressControlsStackView.translatesAutoresizingMaskIntoConstraints = false
@ -138,7 +170,7 @@ class TextView: UIControl {
stackView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
addressControlsStackView.trailingAnchor.constraint(equalTo: addressControlsContainer.trailingAnchor, constant: -7),
addressControlsStackView.trailingAnchor.constraint(equalTo: addressControlsContainer.trailingAnchor),
addressControlsStackView.topAnchor.constraint(equalTo: addressControlsContainer.topAnchor),
addressControlsStackView.bottomAnchor.constraint(equalTo: addressControlsContainer.bottomAnchor),
addressControlsStackView.leadingAnchor.constraint(greaterThanOrEqualTo: addressControlsContainer.leadingAnchor),
@ -148,6 +180,19 @@ class TextView: UIControl {
return stackView
}
@objc private func textDidChangeNotification(_ notification: Notification) {
guard textView == notification.object as? UITextView, let text = textView.text else {
return
}
updateClearAndPasteButtons(text)
}
private func updateClearAndPasteButtons(_ text: String) {
clearButton.isHidden = text.isEmpty
pasteButton.isHidden = !text.isEmpty
}
func configureOnce() {
guard !isConfigured else { return }
isConfigured = true

@ -123,7 +123,7 @@ class ImportWalletViewController: UIViewController {
private lazy var watchControlsStackView: UIStackView = [
watchAddressTextField.label,
.spacer(height: 4),
watchAddressTextField.defaultLayout(),
watchAddressTextField.defaultLayout(edgeInsets: .zero),
.spacer(height: 4),
].asStackView(axis: .vertical)
@ -185,7 +185,7 @@ class ImportWalletViewController: UIViewController {
let stackView = [
tabBar,
.spacer(height: ScreenChecker().isNarrowScreen ? 5 : 10),
.spacer(height: ScreenChecker().isNarrowScreen ? 10 : 30),
mnemonicControlsStackView,
keystoreJSONControlsStackView,
privateKeyControlsStackView,
@ -208,7 +208,7 @@ class ImportWalletViewController: UIViewController {
footerBar.addSubview(buttonsBar)
let xMargin = CGFloat(7)
let xMargin = CGFloat(16)
let heightThatFitsPrivateKeyNicely = CGFloat(ScreenChecker().isNarrowScreen ? 80 : 100)
footerBottomConstraint = footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor)

Loading…
Cancel
Save