An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
alpha-wallet-ios/AlphaWallet/UI/EmptyView.swift

74 lines
2.3 KiB

// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import UIKit
import StatefulViewController
class EmptyView: UIView {
private let titleLabel = UILabel()
private let imageView = UIImageView()
private let button = Button(size: .normal, style: .solid)
private let insets: UIEdgeInsets
private var onRetry: (() -> Void)? = .none
private let viewModel = StateViewModel()
init(
frame: CGRect = .zero,
title: String = R.string.localizable.empty(),
image: UIImage? = R.image.no_transactions_mascot(),
insets: UIEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0),
onRetry: (() -> Void)? = .none
) {
self.insets = insets
self.onRetry = onRetry
super.init(frame: frame)
backgroundColor = .white
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.text = title
titleLabel.font = viewModel.descriptionFont
titleLabel.textColor = viewModel.descriptionTextColor
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.image = image
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitle(R.string.localizable.refresh(), for: .normal)
button.addTarget(self, action: #selector(retry), for: .touchUpInside)
let stackView = [
imageView,
titleLabel,
].asStackView(axis: .vertical, spacing: 30, alignment: .center)
stackView.translatesAutoresizingMaskIntoConstraints = false
if let _ = onRetry {
stackView.addArrangedSubview(button)
}
addSubview(stackView)
NSLayoutConstraint.activate([
stackView.trailingAnchor.constraint(equalTo: trailingAnchor),
stackView.leadingAnchor.constraint(equalTo: leadingAnchor),
stackView.centerXAnchor.constraint(equalTo: centerXAnchor),
stackView.centerYAnchor.constraint(equalTo: centerYAnchor),
button.widthAnchor.constraint(equalToConstant: 160),
])
}
@objc func retry() {
onRetry?()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
extension EmptyView: StatefulPlaceholderView {
func placeholderViewInsets() -> UIEdgeInsets {
return insets
}
}