Add white background behind TS buttons #1930

pull/2132/head
Vladyslav shepitko 4 years ago
parent 3da57dfc38
commit d5d11bc5a4
  1. 5
      AlphaWallet/Style/AppStyle.swift
  2. 16
      AlphaWallet/Tokens/ViewControllers/TokenInstanceViewController.swift
  3. 17
      AlphaWallet/Tokens/ViewControllers/TokenViewController.swift
  4. 22
      AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift
  5. 62
      AlphaWallet/UI/ButtonsBar.swift

@ -194,6 +194,11 @@ enum DataEntry {
static let headerReferenceSizeWidth: CGFloat = 100
}
enum ButtonsBar {
static let insets: UIEdgeInsets = .init(top: 20, left: 0, bottom: 20, right: 0)
static let separatorHeight: CGFloat = 1.0
}
}
enum Font {

@ -77,13 +77,9 @@ class TokenInstanceViewController: UIViewController, TokenVerifiableStatusViewCo
header.delegate = self
let footerBar = UIView()
footerBar.translatesAutoresizingMaskIntoConstraints = false
footerBar.backgroundColor = .clear
let footerBar = ButtonsBarBackgroundView(buttonsBar: buttonsBar)
roundedBackground.addSubview(footerBar)
footerBar.addSubview(buttonsBar)
NSLayoutConstraint.activate([
header.heightAnchor.constraint(equalToConstant: TokenCardsViewControllerHeader.height),
@ -94,15 +90,7 @@ class TokenInstanceViewController: UIViewController, TokenVerifiableStatusViewCo
stackView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor),
stackView.topAnchor.constraint(equalTo: roundedBackground.topAnchor),
buttonsBar.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor),
buttonsBar.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor),
buttonsBar.topAnchor.constraint(equalTo: footerBar.topAnchor),
buttonsBar.heightAnchor.constraint(equalToConstant: ButtonsBar.buttonsHeight),
footerBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
footerBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen),
footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor),
footerBar.anchorsConstraint(to: view),
] + roundedBackground.createConstraintsWithContainer(view: view))
}

@ -56,13 +56,9 @@ class TokenViewController: UIViewController {
tableView.translatesAutoresizingMaskIntoConstraints = false
roundedBackground.addSubview(tableView)
let footerBar = UIView()
footerBar.translatesAutoresizingMaskIntoConstraints = false
footerBar.backgroundColor = .clear
let footerBar = ButtonsBarBackgroundView(buttonsBar: buttonsBar)
roundedBackground.addSubview(footerBar)
footerBar.addSubview(buttonsBar)
configureBalanceViewModel()
NSLayoutConstraint.activate([
@ -70,16 +66,7 @@ class TokenViewController: UIViewController {
header.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor),
tableView.anchorsConstraint(to: roundedBackground),
buttonsBar.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor),
buttonsBar.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor),
buttonsBar.topAnchor.constraint(equalTo: footerBar.topAnchor),
buttonsBar.heightAnchor.constraint(equalToConstant: ButtonsBar.buttonsHeight),
footerBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
footerBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen),
footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor),
footerBar.anchorsConstraint(to: view),
roundedBackground.createConstraintsWithContainer(view: view),
])

@ -102,28 +102,16 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr
tableView.estimatedRowHeight = TokensCardViewController.anArbitaryRowHeightSoAutoSizingCellsWorkIniOS10
roundedBackground.addSubview(tableView)
let footerBar = UIView()
footerBar.translatesAutoresizingMaskIntoConstraints = false
footerBar.backgroundColor = .clear
let footerBar = ButtonsBarBackgroundView(buttonsBar: buttonsBar)
roundedBackground.addSubview(footerBar)
footerBar.addSubview(buttonsBar)
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.bottomAnchor),
buttonsBar.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor),
buttonsBar.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor),
buttonsBar.topAnchor.constraint(equalTo: footerBar.topAnchor),
buttonsBar.heightAnchor.constraint(equalToConstant: ButtonsBar.buttonsHeight),
footerBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
footerBar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen),
footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor),
footerBar.anchorsConstraint(to: view),
] + roundedBackground.createConstraintsWithContainer(view: view))
registerForPreviewing(with: self, sourceView: tableView)
@ -169,20 +157,14 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr
button.isEnabled = false
}
}
configureButtonsBarParentUserInteractionEnabledToPassthroughTouch(isEnabled: !viewModel.actions.isEmpty)
} else {
buttonsBar.configuration = .empty
configureButtonsBarParentUserInteractionEnabledToPassthroughTouch(isEnabled: false)
}
sizingCell = nil
tableView.reloadData()
}
private func configureButtonsBarParentUserInteractionEnabledToPassthroughTouch(isEnabled: Bool) {
buttonsBar.superview?.isUserInteractionEnabled = isEnabled
}
override
func viewDidLoad() {
super.viewDidLoad()

@ -92,14 +92,65 @@ class BarButton: UIButton {
}
}
class ButtonsBar: UIView {
class ButtonsBarBackgroundView: UIView {
private let buttonsBar: ButtonsBar
private let separatorLine: UIView = {
let view = UIView()
view.backgroundColor = R.color.mike()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private var observation: NSKeyValueObservation?
init(buttonsBar: ButtonsBar, edgeInsets: UIEdgeInsets = DataEntry.Metric.ButtonsBar.insets) {
self.buttonsBar = buttonsBar
super.init(frame: .zero)
addSubview(separatorLine)
addSubview(buttonsBar)
translatesAutoresizingMaskIntoConstraints = false
backgroundColor = Colors.appWhite
NSLayoutConstraint.activate([
separatorLine.leadingAnchor.constraint(equalTo: leadingAnchor),
separatorLine.trailingAnchor.constraint(equalTo: trailingAnchor),
separatorLine.topAnchor.constraint(equalTo: topAnchor),
separatorLine.heightAnchor.constraint(equalToConstant: DataEntry.Metric.ButtonsBar.separatorHeight),
buttonsBar.leadingAnchor.constraint(equalTo: leadingAnchor, constant: edgeInsets.left),
buttonsBar.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -edgeInsets.right),
buttonsBar.topAnchor.constraint(equalTo: separatorLine.bottomAnchor, constant: edgeInsets.top),
buttonsBar.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor, constant: -edgeInsets.bottom),
])
observation = buttonsBar.observe(\.buttons) { sender, _ in
self.isHidden = sender.buttons.isEmpty
}
}
func anchorsConstraint(to view: UIView) -> [NSLayoutConstraint] {
return [
leadingAnchor.constraint(equalTo: view.leadingAnchor),
trailingAnchor.constraint(equalTo: view.trailingAnchor),
bottomAnchor.constraint(equalTo: view.bottomAnchor)
]
}
required init?(coder: NSCoder) {
return nil
}
}
@objc class ButtonsBar: UIView {
static let buttonsHeight = CGFloat(ScreenChecker().isNarrowScreen ? 38 : 48)
//A gap so it doesn't stick to the bottom of devices without a bottom safe area
static let marginAtBottomScreen = CGFloat(3)
private var buttonContainerViews: [ContainerViewWithShadow<BarButton>] = []
private var moreButtonContainerViews: [ContainerViewWithShadow<BarButton>] = []
private let buttonsStackView: UIStackView
//NOTE: we need to handle buttont changes, for this we will use buttonsStackView, to make sure that number of button has changed
private var buttonsStackView: UIStackView
private var innerStackView: UIStackView
private var observations: [NSKeyValueObservation] = []
@ -107,7 +158,7 @@ class ButtonsBar: UIView {
buttons.filter { $0.displayButton }.enumerated().filter { configuration.shouldHideButton(at: $0.offset) }.map { $0.element }
}
var buttons: [BarButton] {
@objc dynamic var buttons: [BarButton] {
return buttonContainerViews.map { $0.childView }
}
@ -145,6 +196,7 @@ class ButtonsBar: UIView {
let margin = CGFloat(20)
NSLayoutConstraint.activate([
heightAnchor.constraint(equalToConstant: ButtonsBar.buttonsHeight),
innerStackView.anchorsConstraint(to: self, edgeInsets: .init(top: 0, left: margin, bottom: 0, right: margin)),
])
@ -156,6 +208,8 @@ class ButtonsBar: UIView {
}
private func didUpdateView(with configuration: ButtonsBarConfiguration) {
willChangeValue(for: \.buttons)
buttonContainerViews = ButtonsBar.bar(numberOfButtons: configuration.barButtonTypes.count)
resetIsHiddenObservers()
@ -174,6 +228,8 @@ class ButtonsBar: UIView {
buttonsStackView.addArrangedSubviews(buttons)
innerStackView.addArrangedSubviews([buttonsStackView] + moreButtons)
didChangeValue(for: \.buttons)
}
fileprivate func setup(viewModel: ButtonsBarViewModel, view: ContainerViewWithShadow<BarButton>) {

Loading…
Cancel
Save