diff --git a/AlphaWallet.xcodeproj/project.pbxproj b/AlphaWallet.xcodeproj/project.pbxproj index c337eddd8..74010270a 100644 --- a/AlphaWallet.xcodeproj/project.pbxproj +++ b/AlphaWallet.xcodeproj/project.pbxproj @@ -417,6 +417,7 @@ 5E7C7BFE9C8CAA3E204B1FAA /* TokenRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7F89E3480D3680750EA9 /* TokenRowView.swift */; }; 5E7C7C0D3181CD31A581AEBE /* EditMyDappViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7F55495A6095B3E86248 /* EditMyDappViewController.swift */; }; 5E7C7C0FAC500A6651E663FD /* TransferTokensCardQuantitySelectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C703BA1D0E9ACB7399155 /* TransferTokensCardQuantitySelectionViewModel.swift */; }; + 5E7C7C0FBEF6206024FB355E /* ButtonsBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C774238AE6861A7935EEE /* ButtonsBar.swift */; }; 5E7C7C21E5CAF122AA4F6617 /* HowDoIGetMyMoneyInfoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C78B001F9F95F404D5FEF /* HowDoIGetMyMoneyInfoViewController.swift */; }; 5E7C7C7142C4519873B2BB4E /* ImportWalletTabBarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7C2872E213BBB05D55BA /* ImportWalletTabBarViewModel.swift */; }; 5E7C7C8BC4763CFDD3EE119D /* AssetAttributeFunctionCall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C75C1D4D61A74BACAFF69 /* AssetAttributeFunctionCall.swift */; }; @@ -962,6 +963,7 @@ 5E7C7721E0E4D4EFDD35E196 /* ScanQRCodeCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScanQRCodeCoordinator.swift; sourceTree = ""; }; 5E7C772DC28C5110021894E3 /* ImageCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCache.swift; sourceTree = ""; }; 5E7C77316522DF2B256F1F92 /* TokensCardViewControllerHeaderViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokensCardViewControllerHeaderViewModel.swift; sourceTree = ""; }; + 5E7C774238AE6861A7935EEE /* ButtonsBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ButtonsBar.swift; path = AlphaWallet/UI/ButtonsBar.swift; sourceTree = SOURCE_ROOT; }; 5E7C774BCA281E4B077DBBFA /* WhatIsEthereumInfoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WhatIsEthereumInfoViewController.swift; sourceTree = ""; }; 5E7C775FD95FE80B0F1CEA33 /* TokenAdaptorTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenAdaptorTest.swift; sourceTree = ""; }; 5E7C776B129861728FFB8CC8 /* EditMyDappViewControllerViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditMyDappViewControllerViewModel.swift; sourceTree = ""; }; @@ -1789,6 +1791,7 @@ 5E7C7CC48CA7A1EA7D539C87 /* VerifiableStatusViewController.swift */, 5E7C77B790551456E111ED4F /* PeekOpenSeaNonFungibleTokenViewController.swift */, 5E7C7EC53B2B5DFAAC7965EC /* TokenViewController.swift */, + 5E7C774238AE6861A7935EEE /* ButtonsBar.swift */, ); path = ViewControllers; sourceTree = ""; @@ -4079,6 +4082,7 @@ 5E7C7A6E4C1AEFED0B0630A6 /* TokenViewControllerTransactionCellViewModel.swift in Sources */, 5E7C749615D227B91E40B274 /* TokenViewControllerHeaderView.swift in Sources */, 5E7C72EECA8154CEB7D9F46C /* ContainerViewWithShadow.swift in Sources */, + 5E7C7C0FBEF6206024FB355E /* ButtonsBar.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AlphaWallet/Browser/ViewControllers/EditMyDappViewController.swift b/AlphaWallet/Browser/ViewControllers/EditMyDappViewController.swift index fc582d110..3d24de40b 100644 --- a/AlphaWallet/Browser/ViewControllers/EditMyDappViewController.swift +++ b/AlphaWallet/Browser/ViewControllers/EditMyDappViewController.swift @@ -17,7 +17,7 @@ class EditMyDappViewController: UIViewController { private let urlLabel = UILabel() private let urlTextField = UITextField() private let cancelButton = UIButton(type: .system) - private let saveButton = UIButton(type: .system) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: EditMyDappViewControllerViewModel? weak var delegate: EditMyDappViewControllerDelegate? @@ -53,12 +53,7 @@ class EditMyDappViewController: UIViewController { footerBar.translatesAutoresizingMaskIntoConstraints = false roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - saveButton.translatesAutoresizingMaskIntoConstraints = false - saveButton.setContentCompressionResistancePriority(.required, for: .horizontal) - saveButton.setContentHuggingPriority(.defaultLow, for: .horizontal) - saveButton.addTarget(self, action: #selector(save), for: .touchUpInside) - footerBar.addSubview(saveButton) + footerBar.addSubview(buttonsBar) cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside) cancelButton.translatesAutoresizingMaskIntoConstraints = false @@ -79,14 +74,13 @@ class EditMyDappViewController: UIViewController { footerBar.leadingAnchor.constraint(equalTo: view.leadingAnchor), footerBar.trailingAnchor.constraint(equalTo: view.trailingAnchor), - //Additional allowance so there's a margin below the buttons for non-iPhone X devices - footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), - saveButton.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor, constant: 15), - saveButton.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor, constant: -15), - saveButton.topAnchor.constraint(equalTo: footerBar.topAnchor), - saveButton.heightAnchor.constraint(equalToConstant: buttonsHeight), + buttonsBar.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), + buttonsBar.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), + buttonsBar.topAnchor.constraint(equalTo: footerBar.topAnchor), + buttonsBar.heightAnchor.constraint(equalToConstant: ButtonsBar.buttonsHeight), stackView.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor, constant: 37), stackView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor, constant: -37), @@ -148,11 +142,10 @@ class EditMyDappViewController: UIViewController { urlTextField.returnKeyType = .done urlTextField.text = viewModel.urlTextFieldText - saveButton.setTitleColor(viewModel.saveButtonTitleColor, for: .normal) - saveButton.backgroundColor = viewModel.saveButtonBackgroundColor - saveButton.titleLabel?.font = viewModel.saveButtonFont + buttonsBar.configure() + let saveButton = buttonsBar.buttons[0] + saveButton.addTarget(self, action: #selector(save), for: .touchUpInside) saveButton.setTitle(viewModel.saveButtonTitle, for: .normal) - saveButton.cornerRadius = viewModel.saveButtonCornerRadius cancelButton.setTitleColor(viewModel.cancelButtonTitleColor, for: .normal) cancelButton.titleLabel?.font = viewModel.cancelButtonFont diff --git a/AlphaWallet/Browser/ViewModel/EditMyDappViewControllerViewModel.swift b/AlphaWallet/Browser/ViewModel/EditMyDappViewControllerViewModel.swift index 164f3456c..510bcc5bf 100644 --- a/AlphaWallet/Browser/ViewModel/EditMyDappViewControllerViewModel.swift +++ b/AlphaWallet/Browser/ViewModel/EditMyDappViewControllerViewModel.swift @@ -118,26 +118,10 @@ struct EditMyDappViewControllerViewModel { return dapp.url } - var saveButtonTitleColor: UIColor { - return Colors.appWhite - } - - var saveButtonBackgroundColor: UIColor { - return Colors.appHighlightGreen - } - - var saveButtonFont: UIFont { - return Fonts.regular(size: 20)! - } - var saveButtonTitle: String { return R.string.localizable.save() } - var saveButtonCornerRadius: CGFloat { - return 16 - } - var cancelButtonTitleColor: UIColor { return Colors.appWhite } diff --git a/AlphaWallet/Market/ViewControllers/ImportMagicTokenViewController.swift b/AlphaWallet/Market/ViewControllers/ImportMagicTokenViewController.swift index fb45b054b..58644baa4 100644 --- a/AlphaWallet/Market/ViewControllers/ImportMagicTokenViewController.swift +++ b/AlphaWallet/Market/ViewControllers/ImportMagicTokenViewController.swift @@ -24,8 +24,7 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS private let ethCostLabel = UILabel() private let dollarCostLabelLabel = UILabel() private let dollarCostLabel = PaddedLabel() - private var actionButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) - private var cancelButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 2) private var viewModel: ImportMagicTokenViewControllerViewModel? let config: Config @@ -90,15 +89,6 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS ].asStackView(axis: .vertical, alignment: .center) costStackView?.translatesAutoresizingMaskIntoConstraints = false - let actionButton = actionButtonContainer.childView - actionButton.addTarget(self, action: #selector(actionTapped), for: .touchUpInside) - - let cancelButton = cancelButtonContainer.childView - cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside) - - let buttonsStackView = [.spacerWidth(20), actionButtonContainer, .spacerWidth(7), cancelButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let stackView = [ header, .spacer(height: 1), @@ -118,8 +108,7 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) let separatorThickness = CGFloat(1) @@ -137,16 +126,14 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS separator2.leadingAnchor.constraint(equalTo: tokenCardRowView.background.leadingAnchor), separator2.trailingAnchor.constraint(equalTo: tokenCardRowView.background.trailingAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), - - actionButtonContainer.widthAnchor.constraint(equalTo: cancelButtonContainer.widthAnchor), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), statusLabel.widthAnchor.constraint(equalTo: tokenCardRowView.widthAnchor, constant: -20), @@ -213,19 +200,15 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS activityIndicator.stopAnimating() } - actionButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let actionButton = actionButtonContainer.childView - actionButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - actionButton.backgroundColor = viewModel.buttonBackgroundColor - actionButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + + let actionButton = buttonsBar.buttons[0] actionButton.setTitle(viewModel.actionButtonTitle, for: .normal) + actionButton.addTarget(self, action: #selector(actionTapped), for: .touchUpInside) - cancelButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let cancelButton = cancelButtonContainer.childView - cancelButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - cancelButton.backgroundColor = viewModel.buttonBackgroundColor - cancelButton.titleLabel?.font = viewModel.buttonFont + let cancelButton = buttonsBar.buttons[1] cancelButton.setTitle(viewModel.cancelButtonTitle, for: .normal) + cancelButton.addTarget(self, action: #selector(cancel), for: .touchUpInside) actionButton.isHidden = !viewModel.showActionButton diff --git a/AlphaWallet/Market/ViewModels/ImportMagicTokenViewControllerViewModel.swift b/AlphaWallet/Market/ViewModels/ImportMagicTokenViewControllerViewModel.swift index e301a0fb2..2c29cb150 100644 --- a/AlphaWallet/Market/ViewModels/ImportMagicTokenViewControllerViewModel.swift +++ b/AlphaWallet/Market/ViewModels/ImportMagicTokenViewControllerViewModel.swift @@ -244,18 +244,6 @@ struct ImportMagicTokenViewControllerViewModel { return Fonts.light(size: 21)! } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - var showActionButton: Bool { switch state { case .promptImport: @@ -326,24 +314,4 @@ struct ImportMagicTokenViewControllerViewModel { self.state = state self.server = server } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Redeem/ViewControllers/RedeemTokenCardQuantitySelectionViewController.swift b/AlphaWallet/Redeem/ViewControllers/RedeemTokenCardQuantitySelectionViewController.swift index 82199d4f4..0f9c1bab7 100644 --- a/AlphaWallet/Redeem/ViewControllers/RedeemTokenCardQuantitySelectionViewController.swift +++ b/AlphaWallet/Redeem/ViewControllers/RedeemTokenCardQuantitySelectionViewController.swift @@ -20,7 +20,7 @@ class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVer private let subtitleLabel = UILabel() private let quantityStepper = NumberStepper() private let tokenRowView: TokenRowView & UIView - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: RedeemTokenCardQuantitySelectionViewModel let config: Config @@ -51,10 +51,6 @@ class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVer subtitleLabel.translatesAutoresizingMaskIntoConstraints = false - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletTokenRedeemButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - tokenRowView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(tokenRowView) @@ -74,16 +70,12 @@ class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVer stackView.translatesAutoresizingMaskIntoConstraints = false roundedBackground.addSubview(stackView) - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ header.heightAnchor.constraint(equalToConstant: 90), @@ -97,14 +89,14 @@ class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVer stackView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor), stackView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) } @@ -161,11 +153,10 @@ class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVer tokenRowView.stateLabel.isHidden = true - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletTokenRedeemButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } private func getTokenHolderFromQuantity() -> TokenHolder { diff --git a/AlphaWallet/Redeem/ViewControllers/RedeemTokenViewController.swift b/AlphaWallet/Redeem/ViewControllers/RedeemTokenViewController.swift index 9f250e626..00824d253 100644 --- a/AlphaWallet/Redeem/ViewControllers/RedeemTokenViewController.swift +++ b/AlphaWallet/Redeem/ViewControllers/RedeemTokenViewController.swift @@ -19,7 +19,7 @@ class RedeemTokenViewController: UIViewController, TokenVerifiableStatusViewCont private let roundedBackground = RoundedBackground() private let header = TokensCardViewControllerTitleHeader() private let tableView = UITableView(frame: .zero, style: .plain) - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: RedeemTokenCardViewModel let config: Config @@ -51,20 +51,12 @@ class RedeemTokenViewController: UIViewController, TokenVerifiableStatusViewCont tableView.estimatedRowHeight = TokensCardViewController.anArbitaryRowHeightSoAutoSizingCellsWorkIniOS10 roundedBackground.addSubview(tableView) - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ tableView.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor), @@ -72,14 +64,14 @@ class RedeemTokenViewController: UIViewController, TokenVerifiableStatusViewCont tableView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), tableView.bottomAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) } @@ -98,11 +90,10 @@ class RedeemTokenViewController: UIViewController, TokenVerifiableStatusViewCont header.configure(title: viewModel.title) tableView.tableHeaderView = header - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } @objc diff --git a/AlphaWallet/Redeem/ViewModels/RedeemTokenCardQuantitySelectionViewModel.swift b/AlphaWallet/Redeem/ViewModels/RedeemTokenCardQuantitySelectionViewModel.swift index 138935a90..12266de7c 100644 --- a/AlphaWallet/Redeem/ViewModels/RedeemTokenCardQuantitySelectionViewModel.swift +++ b/AlphaWallet/Redeem/ViewModels/RedeemTokenCardQuantitySelectionViewModel.swift @@ -26,18 +26,6 @@ struct RedeemTokenCardQuantitySelectionViewModel { return Colors.appBackground } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - var subtitleColor: UIColor { return Colors.appGrayLabelColor } @@ -54,24 +42,4 @@ struct RedeemTokenCardQuantitySelectionViewModel { let tokenTypeName = XMLHandler(contract: token.address.eip55String).getTokenTypeName() return R.string.localizable.aWalletTokenRedeemQuantityTitle(tokenTypeName.localizedUppercase) } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Redeem/ViewModels/RedeemTokenCardViewModel.swift b/AlphaWallet/Redeem/ViewModels/RedeemTokenCardViewModel.swift index e346f2e11..f2be4e099 100644 --- a/AlphaWallet/Redeem/ViewModels/RedeemTokenCardViewModel.swift +++ b/AlphaWallet/Redeem/ViewModels/RedeemTokenCardViewModel.swift @@ -31,18 +31,6 @@ struct RedeemTokenCardViewModel { return R.string.localizable.aWalletTokenRedeemSelectTokensTitle(tokenTypeName) } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - func toggleSelection(for indexPath: IndexPath) -> [IndexPath] { let tokenHolder = item(for: indexPath) var changed = [indexPath] @@ -60,24 +48,4 @@ struct RedeemTokenCardViewModel { } return changed } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Sell/ViewControllers/EnterSellTokensCardPriceQuantityViewController.swift b/AlphaWallet/Sell/ViewControllers/EnterSellTokensCardPriceQuantityViewController.swift index a6246cea9..16c560b98 100644 --- a/AlphaWallet/Sell/ViewControllers/EnterSellTokensCardPriceQuantityViewController.swift +++ b/AlphaWallet/Sell/ViewControllers/EnterSellTokensCardPriceQuantityViewController.swift @@ -21,7 +21,7 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer private let dollarCostLabelLabel = UILabel() private let dollarCostLabel = PaddedLabel() private let tokenRowView: TokenRowView & UIView - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: EnterSellTokensCardPriceQuantityViewControllerViewModel private let ethPrice: Subscribable private var totalEthCost: Ether { @@ -81,10 +81,6 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer scrollView.translatesAutoresizingMaskIntoConstraints = false roundedBackground.addSubview(scrollView) - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - tokenRowView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(tokenRowView) @@ -155,16 +151,12 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer stackView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(stackView) - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ header.heightAnchor.constraint(equalToConstant: 90), @@ -192,14 +184,14 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer stackView.topAnchor.constraint(equalTo: scrollView.topAnchor), stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), @@ -321,11 +313,11 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer tokenRowView.stateLabel.isHidden = true - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } private func getTokenHolderFromQuantity() -> TokenHolder { diff --git a/AlphaWallet/Sell/ViewControllers/SellTokensCardViewController.swift b/AlphaWallet/Sell/ViewControllers/SellTokensCardViewController.swift index f29c2d89c..20a6d9c2b 100644 --- a/AlphaWallet/Sell/ViewControllers/SellTokensCardViewController.swift +++ b/AlphaWallet/Sell/ViewControllers/SellTokensCardViewController.swift @@ -12,7 +12,7 @@ class SellTokensCardViewController: UIViewController, TokenVerifiableStatusViewC private let roundedBackground = RoundedBackground() private let header = TokensCardViewControllerTitleHeader() private let tableView = UITableView(frame: .zero, style: .plain) - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: SellTokensCardViewModel let config: Config @@ -45,20 +45,12 @@ class SellTokensCardViewController: UIViewController, TokenVerifiableStatusViewC tableView.estimatedRowHeight = TokensCardViewController.anArbitaryRowHeightSoAutoSizingCellsWorkIniOS10 roundedBackground.addSubview(tableView) - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ tableView.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor), @@ -66,14 +58,14 @@ class SellTokensCardViewController: UIViewController, TokenVerifiableStatusViewC tableView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), tableView.bottomAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) } @@ -92,11 +84,10 @@ class SellTokensCardViewController: UIViewController, TokenVerifiableStatusViewC header.configure(title: viewModel.title) tableView.tableHeaderView = header - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } @objc diff --git a/AlphaWallet/Sell/ViewControllers/SetSellTokensCardExpiryDateViewController.swift b/AlphaWallet/Sell/ViewControllers/SetSellTokensCardExpiryDateViewController.swift index 9046fdbd2..0a4dd8577 100644 --- a/AlphaWallet/Sell/ViewControllers/SetSellTokensCardExpiryDateViewController.swift +++ b/AlphaWallet/Sell/ViewControllers/SetSellTokensCardExpiryDateViewController.swift @@ -24,7 +24,7 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab private let noteLabel = UILabel() private let noteBorderView = UIView() private let tokenRowView: TokenRowView & UIView - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private let datePicker = UIDatePicker() private let timePicker = UIDatePicker() private var viewModel: SetSellTokensCardExpiryDateViewControllerViewModel @@ -71,10 +71,6 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab scrollView.translatesAutoresizingMaskIntoConstraints = false roundedBackground.addSubview(scrollView) - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - tokenRowView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(tokenRowView) @@ -157,16 +153,12 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab stackView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(stackView) - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ header.heightAnchor.constraint(equalToConstant: 90), @@ -202,14 +194,14 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab stackView.topAnchor.constraint(equalTo: scrollView.topAnchor), stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), @@ -318,11 +310,11 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab tokenRowView.stateLabel.isHidden = true - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } override func viewDidLayoutSubviews() { diff --git a/AlphaWallet/Sell/ViewModels/EnterSellTokensCardPriceQuantityViewControllerViewModel.swift b/AlphaWallet/Sell/ViewModels/EnterSellTokensCardPriceQuantityViewControllerViewModel.swift index 50fd67035..142be12ab 100644 --- a/AlphaWallet/Sell/ViewModels/EnterSellTokensCardPriceQuantityViewControllerViewModel.swift +++ b/AlphaWallet/Sell/ViewModels/EnterSellTokensCardPriceQuantityViewControllerViewModel.swift @@ -23,18 +23,6 @@ struct EnterSellTokensCardPriceQuantityViewControllerViewModel { return Colors.appBackground } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - var choiceLabelColor: UIColor { return Colors.appGrayLabelColor } @@ -122,24 +110,4 @@ struct EnterSellTokensCardPriceQuantityViewControllerViewModel { self.tokenHolder = tokenHolder self.server = server } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Sell/ViewModels/SellTokensCardViewModel.swift b/AlphaWallet/Sell/ViewModels/SellTokensCardViewModel.swift index c98595ae4..3fceef64f 100644 --- a/AlphaWallet/Sell/ViewModels/SellTokensCardViewModel.swift +++ b/AlphaWallet/Sell/ViewModels/SellTokensCardViewModel.swift @@ -25,18 +25,6 @@ struct SellTokensCardViewModel { return R.string.localizable.aWalletTokenSellSelectTokensTitle(tokenTypeName) } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - func toggleSelection(for indexPath: IndexPath) -> [IndexPath] { let tokenHolder = item(for: indexPath) var changed = [indexPath] @@ -55,23 +43,4 @@ struct SellTokensCardViewModel { return changed } - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Sell/ViewModels/SetSellTokensCardExpiryDateViewControllerViewModel.swift b/AlphaWallet/Sell/ViewModels/SetSellTokensCardExpiryDateViewControllerViewModel.swift index ef9ed5c8a..c1ea77035 100644 --- a/AlphaWallet/Sell/ViewModels/SetSellTokensCardExpiryDateViewControllerViewModel.swift +++ b/AlphaWallet/Sell/ViewModels/SetSellTokensCardExpiryDateViewControllerViewModel.swift @@ -18,18 +18,6 @@ struct SetSellTokensCardExpiryDateViewControllerViewModel { return Colors.appBackground } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - var choiceLabelColor: UIColor { return Colors.appGrayLabelColor } @@ -126,24 +114,4 @@ struct SetSellTokensCardExpiryDateViewControllerViewModel { self.ethCost = ethCost self.server = server } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Style/AppStyle.swift b/AlphaWallet/Style/AppStyle.swift index 42087e92b..3ae495702 100644 --- a/AlphaWallet/Style/AppStyle.swift +++ b/AlphaWallet/Style/AppStyle.swift @@ -100,8 +100,6 @@ extension UISegmentedControl { } enum Metrics { - static let greenButtonHeight = CGFloat(48) - enum DappsHome { enum Icon { static let shadowOffset = CGSize(width: 0, height: 0) diff --git a/AlphaWallet/Tokens/ViewControllers/NewTokenViewController.swift b/AlphaWallet/Tokens/ViewControllers/NewTokenViewController.swift index 6c752915a..2f1de092c 100644 --- a/AlphaWallet/Tokens/ViewControllers/NewTokenViewController.swift +++ b/AlphaWallet/Tokens/ViewControllers/NewTokenViewController.swift @@ -26,7 +26,7 @@ class NewTokenViewController: UIViewController, CanScanQRCode { private let decimalsTextField = TextField() private let balanceTextField = TextField() private let nameTextField = TextField() - private var saveButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var scrollViewBottomAnchorConstraint: NSLayoutConstraint! @@ -96,20 +96,13 @@ class NewTokenViewController: UIViewController, CanScanQRCode { stackView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(stackView) - let saveButton = saveButtonContainer.childView - saveButton.addTarget(self, action: #selector(addToken), for: .touchUpInside) - saveButton.isEnabled = true - saveButton.setTitle(R.string.localizable.done(), for: .normal) - - let buttonsStackView = [.spacerWidth(20), saveButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false + buttonsBar.buttons[0].isEnabled = true footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) let xMargin = CGFloat(7) scrollViewBottomAnchorConstraint = scrollView.bottomAnchor.constraint(equalTo: footerBar.topAnchor, constant: 0) @@ -124,14 +117,14 @@ class NewTokenViewController: UIViewController, CanScanQRCode { stackView.topAnchor.constraint(equalTo: scrollView.topAnchor), stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), @@ -170,16 +163,14 @@ class NewTokenViewController: UIViewController, CanScanQRCode { nameTextField.label.textAlignment = .center nameTextField.label.text = viewModel.nameLabel - saveButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let saveButton = saveButtonContainer.childView - saveButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - saveButton.setTitleColor(Colors.veryLightGray, for: .disabled) - saveButton.backgroundColor = viewModel.buttonBackgroundColor - saveButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let saveButton = buttonsBar.buttons[0] + saveButton.addTarget(self, action: #selector(addToken), for: .touchUpInside) + saveButton.setTitle(R.string.localizable.done(), for: .normal) } private func updateSaveButtonBasedOnTokenTypeDetected() { - let saveButton = saveButtonContainer.childView + let saveButton = buttonsBar.buttons[0] if tokenType == nil { saveButton.isEnabled = false saveButton.setTitle(R.string.localizable.detectingTokenTypeTitle(), for: .normal) diff --git a/AlphaWallet/Tokens/ViewControllers/TokenViewController.swift b/AlphaWallet/Tokens/ViewControllers/TokenViewController.swift index 450257792..adbbb0885 100644 --- a/AlphaWallet/Tokens/ViewControllers/TokenViewController.swift +++ b/AlphaWallet/Tokens/ViewControllers/TokenViewController.swift @@ -18,8 +18,7 @@ class TokenViewController: UIViewController { private let tokensDataStore: TokensDataStore private let transferType: TransferType private let tableView = UITableView(frame: .zero, style: .plain) - private var sendButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) - private var receiveButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 2) weak var delegate: TokenViewControllerDelegate? @@ -42,13 +41,10 @@ class TokenViewController: UIViewController { tableView.translatesAutoresizingMaskIntoConstraints = false roundedBackground.addSubview(tableView) - let buttonsStackView = [.spacerWidth(20), sendButtonContainer, .spacerWidth(7), receiveButtonContainer, .spacerWidth(20)].asStackView(axis: .horizontal) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - roundedBackground.addSubview(buttonsStackView) + roundedBackground.addSubview(buttonsBar) configureBalanceViewModel() - let buttonsHeight = Metrics.greenButtonHeight NSLayoutConstraint.activate([ header.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor), header.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor), @@ -58,13 +54,10 @@ class TokenViewController: UIViewController { tableView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), tableView.bottomAnchor.constraint(equalTo: roundedBackground.bottomAnchor), - sendButtonContainer.widthAnchor.constraint(equalTo: receiveButtonContainer.widthAnchor), - - buttonsStackView.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), - //Some gap so it doesn't stick to the bottom of devices without a bottom safe area - buttonsStackView.bottomAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -7), + buttonsBar.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor), + buttonsBar.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor), + buttonsBar.heightAnchor.constraint(equalToConstant: ButtonsBar.buttonsHeight), + buttonsBar.bottomAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.marginAtBottomScreen), ] + roundedBackground.createConstraintsWithContainer(view: view)) } @@ -88,21 +81,15 @@ class TokenViewController: UIViewController { header.frame.size.height = 220 tableView.tableHeaderView = header - sendButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.sendReceiveButtonCornerRadius) - - receiveButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.sendReceiveButtonCornerRadius) + buttonsBar.configure() - let sendButton = sendButtonContainer.childView + let sendButton = buttonsBar.buttons[0] sendButton.setTitle(viewModel.sendButtonTitle, for: .normal) sendButton.addTarget(self, action: #selector(send), for: .touchUpInside) - sendButton.setBackgroundColor(viewModel.sendReceiveButtonBackgroundColor, forState: .normal) - sendButton.setTitleColor(viewModel.sendReceiveButtonTitleColor, for: .normal) - let receiveButton = receiveButtonContainer.childView + let receiveButton = buttonsBar.buttons[1] receiveButton.setTitle(viewModel.receiveButtonTitle, for: .normal) receiveButton.addTarget(self, action: #selector(receive), for: .touchUpInside) - receiveButton.setBackgroundColor(viewModel.sendReceiveButtonBackgroundColor, forState: .normal) - receiveButton.setTitleColor(viewModel.sendReceiveButtonTitleColor, for: .normal) tableView.reloadData() } diff --git a/AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift b/AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift index 4cba7e66f..b182a6ee1 100644 --- a/AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift +++ b/AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift @@ -30,9 +30,7 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr private let header = TokenCardsViewControllerHeader() private let roundedBackground = RoundedBackground() private let tableView = UITableView(frame: .zero, style: .plain) - private var redeemButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) - private var transferButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) - private var sellButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 3) let config: Config var contract: String { @@ -81,28 +79,12 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr tableView.estimatedRowHeight = TokensCardViewController.anArbitaryRowHeightSoAutoSizingCellsWorkIniOS10 roundedBackground.addSubview(tableView) - let redeemButton = redeemButtonContainer.childView - redeemButton.setTitle(R.string.localizable.aWalletTokenRedeemButtonTitle(), for: .normal) - redeemButton.addTarget(self, action: #selector(redeem), for: .touchUpInside) - - let sellButton = sellButtonContainer.childView - sellButton.setTitle(R.string.localizable.aWalletTokenSellButtonTitle(), for: .normal) - sellButton.addTarget(self, action: #selector(sell), for: .touchUpInside) - - let transferButton = transferButtonContainer.childView - transferButton.setTitle(R.string.localizable.aWalletTokenTransferButtonTitle(), for: .normal) - transferButton.addTarget(self, action: #selector(transfer), for: .touchUpInside) - - let buttonsStackView = [.spacerWidth(20), redeemButtonContainer, .spacerWidth(7), sellButtonContainer, .spacerWidth(7), transferButtonContainer, .spacerWidth(20)].asStackView() - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ tableView.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor), @@ -110,17 +92,14 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr tableView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), tableView.bottomAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), - - redeemButtonContainer.widthAnchor.constraint(equalTo: sellButtonContainer.widthAnchor), - redeemButtonContainer.widthAnchor.constraint(equalTo: transferButtonContainer.widthAnchor), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) @@ -142,36 +121,29 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr header.configure(viewModel: .init(tokenObject: tokenObject, server: config.server)) tableView.tableHeaderView = header - redeemButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let redeemButton = redeemButtonContainer.childView - redeemButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - redeemButton.setTitleColor(viewModel.disabledButtonTitleColor, for: .disabled) - redeemButton.backgroundColor = viewModel.buttonBackgroundColor - redeemButton.titleLabel?.font = viewModel.buttonFont - - sellButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let sellButton = sellButtonContainer.childView - sellButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - sellButton.setTitleColor(viewModel.disabledButtonTitleColor, for: .disabled) - sellButton.backgroundColor = viewModel.buttonBackgroundColor - sellButton.titleLabel?.font = viewModel.buttonFont - - transferButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let transferButton = transferButtonContainer.childView - transferButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - transferButton.setTitleColor(viewModel.disabledButtonTitleColor, for: .disabled) - transferButton.backgroundColor = viewModel.buttonBackgroundColor - transferButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + + let redeemButton = buttonsBar.buttons[0] + redeemButton.setTitle(R.string.localizable.aWalletTokenRedeemButtonTitle(), for: .normal) + redeemButton.addTarget(self, action: #selector(redeem), for: .touchUpInside) + + let sellButton = buttonsBar.buttons[1] + sellButton.setTitle(R.string.localizable.aWalletTokenSellButtonTitle(), for: .normal) + sellButton.addTarget(self, action: #selector(sell), for: .touchUpInside) + + let transferButton = buttonsBar.buttons[2] + transferButton.setTitle(R.string.localizable.aWalletTokenTransferButtonTitle(), for: .normal) + transferButton.addTarget(self, action: #selector(transfer), for: .touchUpInside) switch tokenObject.type { case .nativeCryptocurrency, .erc20, .xDai: break case .erc875: - redeemButtonContainer.isHidden = false - sellButtonContainer.isHidden = false + buttonsBar.buttons[0].isHidden = false + buttonsBar.buttons[1].isHidden = false case .erc721: - redeemButtonContainer.isHidden = true - sellButtonContainer.isHidden = true + buttonsBar.buttons[0].isHidden = true + buttonsBar.buttons[1].isHidden = true } [redeemButton, sellButton, transferButton].forEach { $0.isEnabled = !isReadOnly } diff --git a/AlphaWallet/Tokens/ViewModels/NewTokenViewModel.swift b/AlphaWallet/Tokens/ViewModels/NewTokenViewModel.swift index 314c730ba..5b5e367f9 100644 --- a/AlphaWallet/Tokens/ViewModels/NewTokenViewModel.swift +++ b/AlphaWallet/Tokens/ViewModels/NewTokenViewModel.swift @@ -50,36 +50,4 @@ struct NewTokenViewModel { var nameLabel: String { return R.string.localizable.name().uppercased() } - - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Tokens/ViewModels/TokenViewControllerViewModel.swift b/AlphaWallet/Tokens/ViewModels/TokenViewControllerViewModel.swift index fcf629387..80a8e2c62 100644 --- a/AlphaWallet/Tokens/ViewModels/TokenViewControllerViewModel.swift +++ b/AlphaWallet/Tokens/ViewModels/TokenViewControllerViewModel.swift @@ -47,32 +47,4 @@ struct TokenViewControllerViewModel { var receiveButtonTitle: String { return R.string.localizable.receive() } - - var sendReceiveButtonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var sendReceiveButtonTitleColor: UIColor { - return Colors.appWhite - } - - var sendReceiveButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Tokens/ViewModels/TokensCardViewModel.swift b/AlphaWallet/Tokens/ViewModels/TokensCardViewModel.swift index 102fa9858..5c4215818 100644 --- a/AlphaWallet/Tokens/ViewModels/TokensCardViewModel.swift +++ b/AlphaWallet/Tokens/ViewModels/TokensCardViewModel.swift @@ -26,22 +26,6 @@ struct TokensCardViewModel { return tokenHolders.count } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var disabledButtonTitleColor: UIColor { - return Colors.darkGray - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - func toggleDetailsVisible(for indexPath: IndexPath) -> [IndexPath] { let tokenHolder = item(for: indexPath) var changed = [indexPath] @@ -56,24 +40,4 @@ struct TokensCardViewModel { } return changed } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Transfer/ViewControllers/ChooseTokenCardTransferModeViewController.swift b/AlphaWallet/Transfer/ViewControllers/ChooseTokenCardTransferModeViewController.swift index 57dc4064f..6cba2e2ee 100644 --- a/AlphaWallet/Transfer/ViewControllers/ChooseTokenCardTransferModeViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/ChooseTokenCardTransferModeViewController.swift @@ -13,8 +13,7 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab private let roundedBackground = RoundedBackground() private let header = TokensCardViewControllerTitleHeader() private let tokenRowView: TokenRowView & UIView - private var generateMagicLinkButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) - private var transferNowButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 2) private var viewModel: ChooseTokenCardTransferModeViewControllerViewModel private let tokenHolder: TokenHolder @@ -51,14 +50,6 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab roundedBackground.translatesAutoresizingMaskIntoConstraints = false view.addSubview(roundedBackground) - let generateMagicLinkButton = generateMagicLinkButtonContainer.childView - generateMagicLinkButton.setTitle(R.string.localizable.aWalletTokenTransferModeMagicLinkButtonTitle(), for: .normal) - generateMagicLinkButton.addTarget(self, action: #selector(generateMagicLinkTapped), for: .touchUpInside) - - let transferNowButton = transferNowButtonContainer.childView - transferNowButton.setTitle(" \(R.string.localizable.aWalletTokenTransferModeNowButtonTitle()) ", for: .normal) - transferNowButton.addTarget(self, action: #selector(transferNowTapped), for: .touchUpInside) - tokenRowView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(tokenRowView) @@ -69,16 +60,12 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab stackView.translatesAutoresizingMaskIntoConstraints = false roundedBackground.addSubview(stackView) - let buttonsStackView = [.spacerWidth(18), generateMagicLinkButtonContainer, .spacerWidth(5), transferNowButtonContainer, .spacerWidth(18)].asStackView() - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ header.heightAnchor.constraint(equalToConstant: 90), @@ -90,14 +77,14 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab stackView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor), stackView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) } @@ -136,18 +123,18 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab tokenRowView.stateLabel.isHidden = true - generateMagicLinkButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let generateMagicLinkButton = generateMagicLinkButtonContainer.childView - generateMagicLinkButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - generateMagicLinkButton.backgroundColor = viewModel.buttonBackgroundColor - generateMagicLinkButton.titleLabel?.font = viewModel.buttonFont - //Hardcode position because text is very long compared to the transferNowButton - generateMagicLinkButton.titleEdgeInsets = .init(top: 0, left: horizontalAdjustmentForLongMagicLinkButtonTitle, bottom: 0, right: 0) + buttonsBar.configure() - transferNowButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let transferNowButton = transferNowButtonContainer.childView - transferNowButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - transferNowButton.backgroundColor = viewModel.buttonBackgroundColor + let generateMagicLinkButton = buttonsBar.buttons[0] + generateMagicLinkButton.setTitle(R.string.localizable.aWalletTokenTransferModeMagicLinkButtonTitle(), for: .normal) + generateMagicLinkButton.addTarget(self, action: #selector(generateMagicLinkTapped), for: .touchUpInside) + + let transferNowButton = buttonsBar.buttons[1] + transferNowButton.setTitle(" \(R.string.localizable.aWalletTokenTransferModeNowButtonTitle()) ", for: .normal) + transferNowButton.addTarget(self, action: #selector(transferNowTapped), for: .touchUpInside) + + //Button fonts have to be smaller because the button title is too long + generateMagicLinkButton.titleLabel?.font = viewModel.buttonFont transferNowButton.titleLabel?.font = viewModel.buttonFont } } diff --git a/AlphaWallet/Transfer/ViewControllers/SendViewController.swift b/AlphaWallet/Transfer/ViewControllers/SendViewController.swift index bace017ec..d716006e1 100644 --- a/AlphaWallet/Transfer/ViewControllers/SendViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/SendViewController.swift @@ -24,7 +24,7 @@ class SendViewController: UIViewController, CanScanQRCode { private let amountTextField = AmountTextField() private let targetAddressLabel = UILabel() private let amountLabel = UILabel() - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: SendViewModel! private var headerViewModel = SendHeaderViewViewModel() private var balanceViewModel: BalanceBaseViewModel? @@ -98,13 +98,6 @@ class SendViewController: UIViewController, CanScanQRCode { amountTextField.isFiatButtonHidden = true } - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.send(), for: .normal) - nextButton.addTarget(self, action: #selector(send), for: .touchUpInside) - - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let stackView = [ header, .spacer(height: ScreenChecker().isNarrowScreen() ? 7: 20), @@ -126,8 +119,7 @@ class SendViewController: UIViewController, CanScanQRCode { footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ header.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor, constant: 30), @@ -144,14 +136,14 @@ class SendViewController: UIViewController, CanScanQRCode { stackView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor), stackView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) @@ -179,11 +171,10 @@ class SendViewController: UIViewController, CanScanQRCode { amountLabel.font = viewModel.textFieldsLabelFont amountLabel.textColor = viewModel.textFieldsLabelTextColor - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.send(), for: .normal) + nextButton.addTarget(self, action: #selector(send), for: .touchUpInside) } override func viewDidLayoutSubviews() { diff --git a/AlphaWallet/Transfer/ViewControllers/SetTransferTokensCardExpiryDateViewController.swift b/AlphaWallet/Transfer/ViewControllers/SetTransferTokensCardExpiryDateViewController.swift index bde242225..f6d4e3c35 100644 --- a/AlphaWallet/Transfer/ViewControllers/SetTransferTokensCardExpiryDateViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/SetTransferTokensCardExpiryDateViewController.swift @@ -22,7 +22,7 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri private let noteTitleLabel = UILabel() private let noteLabel = UILabel() private let noteBorderView = UIView() - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: SetTransferTokensCardExpiryDateViewControllerViewModel private let tokenHolder: TokenHolder @@ -65,10 +65,6 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri linkExpiryDateLabel.translatesAutoresizingMaskIntoConstraints = false linkExpiryTimeLabel.translatesAutoresizingMaskIntoConstraints = false - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - tokenRowView.translatesAutoresizingMaskIntoConstraints = false scrollView.addSubview(tokenRowView) @@ -142,16 +138,12 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri linkExpiryTimeField.translatesAutoresizingMaskIntoConstraints = false linkExpiryTimeField.delegate = self - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ header.heightAnchor.constraint(equalToConstant: 90), @@ -184,14 +176,14 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri stackView.topAnchor.constraint(equalTo: scrollView.topAnchor), stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), @@ -298,11 +290,10 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri noteBorderView.layer.borderColor = viewModel.noteBorderColor.cgColor noteBorderView.layer.borderWidth = 1 - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } } diff --git a/AlphaWallet/Transfer/ViewControllers/TransferTokensCardQuantitySelectionViewController.swift b/AlphaWallet/Transfer/ViewControllers/TransferTokensCardQuantitySelectionViewController.swift index 6458d83d9..707ecdaa9 100644 --- a/AlphaWallet/Transfer/ViewControllers/TransferTokensCardQuantitySelectionViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/TransferTokensCardQuantitySelectionViewController.swift @@ -13,7 +13,7 @@ class TransferTokensCardQuantitySelectionViewController: UIViewController, Token private let subtitleLabel = UILabel() private let quantityStepper = NumberStepper() private let tokenRowView: TokenRowView & UIView - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: TransferTokensCardQuantitySelectionViewModel private let token: TokenObject @@ -52,10 +52,6 @@ class TransferTokensCardQuantitySelectionViewController: UIViewController, Token subtitleLabel.translatesAutoresizingMaskIntoConstraints = false - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - tokenRowView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(tokenRowView) @@ -75,16 +71,12 @@ class TransferTokensCardQuantitySelectionViewController: UIViewController, Token stackView.translatesAutoresizingMaskIntoConstraints = false roundedBackground.addSubview(stackView) - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ header.heightAnchor.constraint(equalToConstant: 90), @@ -98,14 +90,14 @@ class TransferTokensCardQuantitySelectionViewController: UIViewController, Token stackView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor), stackView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) } @@ -161,11 +153,10 @@ class TransferTokensCardQuantitySelectionViewController: UIViewController, Token tokenRowView.stateLabel.isHidden = true - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } private func getTokenHolderFromQuantity() -> TokenHolder { diff --git a/AlphaWallet/Transfer/ViewControllers/TransferTokensCardViaWalletAddressViewController.swift b/AlphaWallet/Transfer/ViewControllers/TransferTokensCardViaWalletAddressViewController.swift index b5763a6f7..6821485a0 100644 --- a/AlphaWallet/Transfer/ViewControllers/TransferTokensCardViaWalletAddressViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/TransferTokensCardViaWalletAddressViewController.swift @@ -14,7 +14,7 @@ class TransferTokensCardViaWalletAddressViewController: UIViewController, TokenV private let header = TokensCardViewControllerTitleHeader() private let tokenRowView: TokenRowView & UIView private let targetAddressTextField = AddressTextField() - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: TransferTokensCardViaWalletAddressViewControllerViewModel private var tokenHolder: TokenHolder private var paymentFlow: PaymentFlow @@ -59,10 +59,6 @@ class TransferTokensCardViaWalletAddressViewController: UIViewController, TokenV targetAddressTextField.delegate = self targetAddressTextField.returnKeyType = .done - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - tokenRowView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(tokenRowView) @@ -77,16 +73,12 @@ class TransferTokensCardViaWalletAddressViewController: UIViewController, TokenV stackView.translatesAutoresizingMaskIntoConstraints = false roundedBackground.addSubview(stackView) - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ header.heightAnchor.constraint(equalToConstant: 90), @@ -101,14 +93,14 @@ class TransferTokensCardViaWalletAddressViewController: UIViewController, TokenV stackView.trailingAnchor.constraint(equalTo: roundedBackground.trailingAnchor), stackView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) } @@ -148,11 +140,10 @@ class TransferTokensCardViaWalletAddressViewController: UIViewController, TokenV targetAddressTextField.configureOnce() - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } } diff --git a/AlphaWallet/Transfer/ViewControllers/TransferTokensCardViewController.swift b/AlphaWallet/Transfer/ViewControllers/TransferTokensCardViewController.swift index af3ebad5a..8a7e03a48 100644 --- a/AlphaWallet/Transfer/ViewControllers/TransferTokensCardViewController.swift +++ b/AlphaWallet/Transfer/ViewControllers/TransferTokensCardViewController.swift @@ -12,7 +12,7 @@ class TransferTokensCardViewController: UIViewController, TokenVerifiableStatusV private let roundedBackground = RoundedBackground() private let header = TokensCardViewControllerTitleHeader() private let tableView = UITableView(frame: .zero, style: .plain) - private var nextButtonContainer = ContainerViewWithShadow(aroundView: UIButton(type: .system)) + private let buttonsBar = ButtonsBar(numberOfButtons: 1) private var viewModel: TransferTokensCardViewModel private let token: TokenObject @@ -47,20 +47,12 @@ class TransferTokensCardViewController: UIViewController, TokenVerifiableStatusV tableView.estimatedRowHeight = TokensCardViewController.anArbitaryRowHeightSoAutoSizingCellsWorkIniOS10 roundedBackground.addSubview(tableView) - let nextButton = nextButtonContainer.childView - nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) - nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) - - let buttonsStackView = [.spacerWidth(20), nextButtonContainer, .spacerWidth(20)].asStackView(contentHuggingPriority: .required) - buttonsStackView.translatesAutoresizingMaskIntoConstraints = false - let footerBar = UIView() footerBar.translatesAutoresizingMaskIntoConstraints = false footerBar.backgroundColor = .clear roundedBackground.addSubview(footerBar) - let buttonsHeight = Metrics.greenButtonHeight - footerBar.addSubview(buttonsStackView) + footerBar.addSubview(buttonsBar) NSLayoutConstraint.activate([ tableView.leadingAnchor.constraint(equalTo: roundedBackground.leadingAnchor), @@ -68,14 +60,14 @@ class TransferTokensCardViewController: UIViewController, TokenVerifiableStatusV tableView.topAnchor.constraint(equalTo: roundedBackground.topAnchor), tableView.bottomAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.leadingAnchor.constraint(equalTo: footerBar.leadingAnchor), - buttonsStackView.trailingAnchor.constraint(equalTo: footerBar.trailingAnchor), - buttonsStackView.topAnchor.constraint(equalTo: footerBar.topAnchor), - buttonsStackView.heightAnchor.constraint(equalToConstant: buttonsHeight), + 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: -buttonsHeight - 3), + footerBar.topAnchor.constraint(equalTo: view.layoutGuide.bottomAnchor, constant: -ButtonsBar.buttonsHeight - ButtonsBar.marginAtBottomScreen), footerBar.bottomAnchor.constraint(equalTo: view.bottomAnchor), ] + roundedBackground.createConstraintsWithContainer(view: view)) } @@ -94,11 +86,10 @@ class TransferTokensCardViewController: UIViewController, TokenVerifiableStatusV header.configure(title: viewModel.title) tableView.tableHeaderView = header - nextButtonContainer.configureShadow(color: viewModel.actionButtonShadowColor, offset: viewModel.actionButtonShadowOffset, opacity: viewModel.actionButtonShadowOpacity, radius: viewModel.actionButtonShadowRadius, cornerRadius: viewModel.actionButtonCornerRadius) - let nextButton = nextButtonContainer.childView - nextButton.setTitleColor(viewModel.buttonTitleColor, for: .normal) - nextButton.backgroundColor = viewModel.buttonBackgroundColor - nextButton.titleLabel?.font = viewModel.buttonFont + buttonsBar.configure() + let nextButton = buttonsBar.buttons[0] + nextButton.setTitle(R.string.localizable.aWalletNextButtonTitle(), for: .normal) + nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside) } @objc diff --git a/AlphaWallet/Transfer/ViewModels/ChooseTokenCardTransferModeViewControllerViewModel.swift b/AlphaWallet/Transfer/ViewModels/ChooseTokenCardTransferModeViewControllerViewModel.swift index f04dd7aad..c3717d9d0 100644 --- a/AlphaWallet/Transfer/ViewModels/ChooseTokenCardTransferModeViewControllerViewModel.swift +++ b/AlphaWallet/Transfer/ViewModels/ChooseTokenCardTransferModeViewControllerViewModel.swift @@ -16,14 +16,6 @@ struct ChooseTokenCardTransferModeViewControllerViewModel { return Colors.appBackground } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - var buttonFont: UIFont { if ScreenChecker().isNarrowScreen() { return Fonts.regular(size: 13)! @@ -31,24 +23,4 @@ struct ChooseTokenCardTransferModeViewControllerViewModel { return Fonts.regular(size: 16)! } } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Transfer/ViewModels/SendViewModel.swift b/AlphaWallet/Transfer/ViewModels/SendViewModel.swift index e86a949bc..801d72f7f 100644 --- a/AlphaWallet/Transfer/ViewModels/SendViewModel.swift +++ b/AlphaWallet/Transfer/ViewModels/SendViewModel.swift @@ -53,34 +53,4 @@ struct SendViewModel { var textFieldsLabelFont: UIFont { return Fonts.regular(size: 10)! } - - var buttonTitleColor: UIColor { - return Colors.appWhite - } - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Transfer/ViewModels/SetTransferTokensCardExpiryDateViewControllerViewModel.swift b/AlphaWallet/Transfer/ViewModels/SetTransferTokensCardExpiryDateViewControllerViewModel.swift index 72463c106..9b97630f9 100644 --- a/AlphaWallet/Transfer/ViewModels/SetTransferTokensCardExpiryDateViewControllerViewModel.swift +++ b/AlphaWallet/Transfer/ViewModels/SetTransferTokensCardExpiryDateViewControllerViewModel.swift @@ -16,18 +16,6 @@ struct SetTransferTokensCardExpiryDateViewControllerViewModel { return Colors.appBackground } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - var descriptionLabelText: String { return R.string.localizable.aWalletTokenTransferMagicLinkDescriptionTitle() } @@ -83,24 +71,4 @@ struct SetTransferTokensCardExpiryDateViewControllerViewModel { var linkExpiryTimeLabelText: String { return R.string.localizable.aWalletTokenSellLinkExpiryTimeTitle() } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Transfer/ViewModels/TransferTokensCardQuantitySelectionViewModel.swift b/AlphaWallet/Transfer/ViewModels/TransferTokensCardQuantitySelectionViewModel.swift index 3388d96ea..3913880df 100644 --- a/AlphaWallet/Transfer/ViewModels/TransferTokensCardQuantitySelectionViewModel.swift +++ b/AlphaWallet/Transfer/ViewModels/TransferTokensCardQuantitySelectionViewModel.swift @@ -20,18 +20,6 @@ struct TransferTokensCardQuantitySelectionViewModel { return Colors.appBackground } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - var subtitleColor: UIColor { return Colors.appGrayLabelColor } @@ -48,24 +36,4 @@ struct TransferTokensCardQuantitySelectionViewModel { let tokenTypeName = XMLHandler(contract: token.address.eip55String).getTokenTypeName() return R.string.localizable.aWalletTokenTransferQuantityTitle(tokenTypeName.localizedUppercase) } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Transfer/ViewModels/TransferTokensCardViaWalletAddressViewControllerViewModel.swift b/AlphaWallet/Transfer/ViewModels/TransferTokensCardViaWalletAddressViewControllerViewModel.swift index d4c5d9e72..932d081fe 100644 --- a/AlphaWallet/Transfer/ViewModels/TransferTokensCardViaWalletAddressViewControllerViewModel.swift +++ b/AlphaWallet/Transfer/ViewModels/TransferTokensCardViaWalletAddressViewControllerViewModel.swift @@ -15,36 +15,4 @@ struct TransferTokensCardViaWalletAddressViewControllerViewModel { var backgroundColor: UIColor { return Colors.appBackground } - - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/Transfer/ViewModels/TransferTokensCardViewModel.swift b/AlphaWallet/Transfer/ViewModels/TransferTokensCardViewModel.swift index 9a83eae9b..409ad23b2 100644 --- a/AlphaWallet/Transfer/ViewModels/TransferTokensCardViewModel.swift +++ b/AlphaWallet/Transfer/ViewModels/TransferTokensCardViewModel.swift @@ -25,18 +25,6 @@ struct TransferTokensCardViewModel { return R.string.localizable.aWalletTokenTransferSelectTokensTitle(tokenTypeName) } - var buttonTitleColor: UIColor { - return Colors.appWhite - } - - var buttonBackgroundColor: UIColor { - return Colors.appActionButtonGreen - } - - var buttonFont: UIFont { - return Fonts.regular(size: 20)! - } - func toggleSelection(for indexPath: IndexPath) -> [IndexPath] { let tokenHolder = item(for: indexPath) var changed = [indexPath] @@ -54,24 +42,4 @@ struct TransferTokensCardViewModel { } return changed } - - var actionButtonCornerRadius: CGFloat { - return 16 - } - - var actionButtonShadowColor: UIColor { - return Colors.appActionButtonShadow - } - - var actionButtonShadowOffset: CGSize { - return .init(width: 1, height: 2) - } - - var actionButtonShadowOpacity: Float { - return 0.3 - } - - var actionButtonShadowRadius: CGFloat { - return 5 - } } diff --git a/AlphaWallet/UI/ButtonsBar.swift b/AlphaWallet/UI/ButtonsBar.swift new file mode 100644 index 000000000..e95635e30 --- /dev/null +++ b/AlphaWallet/UI/ButtonsBar.swift @@ -0,0 +1,97 @@ +// Copyright © 2018 Stormbird PTE. LTD. + +import Foundation +import UIKit + +class ButtonsBar: UIView { + static let buttonsHeight = CGFloat(48) + //A gap so it doesn't stick to the bottom of devices without a bottom safe area + static let marginAtBottomScreen = CGFloat(3) + + private let buttonContainerViews: [ContainerViewWithShadow] + + var buttons: [UIButton] { + return buttonContainerViews.map { $0.childView } + } + + init(numberOfButtons: Int, buttonsDistribution: UIStackView.Distribution = .fillEqually) { + buttonContainerViews = (0..