From c70d7e390d5b758ba418804852827d54a2e09612 Mon Sep 17 00:00:00 2001 From: kcw-grunt Date: Mon, 15 Jan 2024 20:39:12 -0500 Subject: [PATCH] Readded then Address Cell View - Still have the issues the ModalViewController height Signed-off-by: kcw-grunt --- litewallet/src/AnnounceUpdatesView.swift | 1 - .../src/Models/KeyboardNotificationInfo.swift | 6 +- .../AmountViewController.swift | 2 +- .../RootModals/ModalViewController.swift | 1 - .../RootModals/SendViewController.swift | 58 ++++++++++--------- .../src/Views/SendViewCells/AddressCell.swift | 44 +++----------- 6 files changed, 45 insertions(+), 67 deletions(-) diff --git a/litewallet/src/AnnounceUpdatesView.swift b/litewallet/src/AnnounceUpdatesView.swift index f0565e5f2..3787f123c 100644 --- a/litewallet/src/AnnounceUpdatesView.swift +++ b/litewallet/src/AnnounceUpdatesView.swift @@ -32,7 +32,6 @@ struct AnnounceUpdatesView: View { let buttonHeight = 44.0 let pageHeight = 145.0 let hugeFont = Font.barlowBold(size: 30.0) - let smallerFont = Font.barlowLight(size: 15.0) let buttonLightFont: Font = .barlowLight(size: 20.0) let buttonFont: Font = .barlowSemiBold(size: 20.0) let appDelegate = UIApplication.shared.delegate as! AppDelegate diff --git a/litewallet/src/Models/KeyboardNotificationInfo.swift b/litewallet/src/Models/KeyboardNotificationInfo.swift index 319133496..73c007c09 100644 --- a/litewallet/src/Models/KeyboardNotificationInfo.swift +++ b/litewallet/src/Models/KeyboardNotificationInfo.swift @@ -1,6 +1,10 @@ import UIKit struct KeyboardNotificationInfo { + let endFrame: CGRect + + let startFrame: CGRect + var deltaY: CGFloat { return endFrame.minY - startFrame.minY } @@ -27,7 +31,5 @@ struct KeyboardNotificationInfo { self.animationCurve = animationCurve.uintValue } - private let endFrame: CGRect - private let startFrame: CGRect private let animationCurve: UInt } diff --git a/litewallet/src/ViewControllers/AmountViewController.swift b/litewallet/src/ViewControllers/AmountViewController.swift index beb90147f..02f89813f 100644 --- a/litewallet/src/ViewControllers/AmountViewController.swift +++ b/litewallet/src/ViewControllers/AmountViewController.swift @@ -1,7 +1,7 @@ import UIKit private let currencyToggleConstant: CGFloat = 20.0 -private let amountFont: UIFont = UIFont.barlowMedium(size: 14.0) +private let amountFont: UIFont = UIFont.barlowMedium(size: 18.0) class AmountViewController: UIViewController, Trackable { private let store: Store private let isPinPadExpandedAtLaunch: Bool diff --git a/litewallet/src/ViewControllers/RootModals/ModalViewController.swift b/litewallet/src/ViewControllers/RootModals/ModalViewController.swift index ca6abf6d8..01a6dcd13 100644 --- a/litewallet/src/ViewControllers/RootModals/ModalViewController.swift +++ b/litewallet/src/ViewControllers/RootModals/ModalViewController.swift @@ -68,7 +68,6 @@ class ModalViewController: UIViewController, Subscriber { // Two stage layout is required here because we need the height constant // of the content at initial layout view.layoutIfNeeded() - let height = scrollViewContent.bounds.size.height + 60.0 let minHeight = scrollView.heightAnchor.constraint(greaterThanOrEqualToConstant: height) let midHeight = scrollView.heightAnchor.constraint(equalTo: scrollViewContent.heightAnchor) diff --git a/litewallet/src/ViewControllers/RootModals/SendViewController.swift b/litewallet/src/ViewControllers/RootModals/SendViewController.swift index 673c177fc..6a13ff175 100644 --- a/litewallet/src/ViewControllers/RootModals/SendViewController.swift +++ b/litewallet/src/ViewControllers/RootModals/SendViewController.swift @@ -26,7 +26,7 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka private let sender: Sender private let walletManager: WalletManager private let amountView: AmountViewController - private let sendAddressCell = SendAddressHostingController() + private let sendAddressCell = AddressCell() private let memoCell = DescriptionSendCell(placeholder: S.Send.descriptionLabel.localize()) private var sendButtonCell = SendButtonHostingController() private let currency: ShadowButton @@ -83,17 +83,17 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka memoCell.backgroundColor = UIColor.litecoinGray amountView.view.backgroundColor = UIColor.litecoinGray - view.addSubview(sendAddressCell.view) + view.addSubview(sendAddressCell) view.addSubview(memoCell) view.addSubview(sendButtonCell.view) - sendAddressCell.view.invalidateIntrinsicContentSize() - sendAddressCell.view.constrainTopCorners(height: SendCell.defaultHeight) + sendAddressCell.invalidateIntrinsicContentSize() + sendAddressCell.constrainTopCorners(height: SendCell.defaultHeight) addChildViewController(amountView, layout: { amountView.view.constrain([ amountView.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), - amountView.view.topAnchor.constraint(equalTo: sendAddressCell.view.bottomAnchor), + amountView.view.topAnchor.constraint(equalTo: sendAddressCell.bottomAnchor), amountView.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), ]) }) @@ -141,6 +141,8 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka } private func addButtonActions() { + // MARK: - MemoCell Callbacks + memoCell.didReturn = { textView in textView.resignFirstResponder() } @@ -148,6 +150,8 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka self?.amountView.closePinPad() } + // MARK: - AmountView Callbacks + amountView.balanceTextForAmount = { [weak self] amount, rate in self?.balanceTextForAmount(amount: amount, rate: rate) } @@ -171,18 +175,23 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka amountView.didChangeFirstResponder = { [weak self] isFirstResponder in if isFirstResponder { self?.memoCell.textView.resignFirstResponder() + self?.sendAddressCell.textField.resignFirstResponder() } } - // MARK: - SendAddressView Model Callbacks + // MARK: - SendAddressView Model Callbacks / Actions - sendAddressCell.rootView.viewModel.shouldPasteAddress = { - self.pasteTapped() - } + sendAddressCell.paste.addTarget(self, action: #selector(SendViewController.pasteTapped), for: .touchUpInside) + sendAddressCell.scan.addTarget(self, action: #selector(SendViewController.scanTapped), for: .touchUpInside) - sendAddressCell.rootView.viewModel.shouldScanAddress = { - self.scanTapped() + sendAddressCell.didBeginEditing = strongify(self) { myself in + myself.amountView.closePinPad() } + sendAddressCell.didReceivePaymentRequest = { [weak self] request in + self?.handleRequest(request) + } + + // MARK: - SendButton Model Callbacks / Actions sendButtonCell.rootView.doSendTransaction = { self.sendTapped() @@ -240,9 +249,8 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka return showAlert(title: S.Send.invalidAddressTitle.localize(), message: S.Send.invalidAddressOnPasteboard.localize(), buttonLabel: S.Button.ok.localize()) } - sendAddressCell.rootView.viewModel.addressString = pasteboard - handleRequest(request) + sendAddressCell.textField.text = pasteboard } @objc private func scanTapped() { @@ -252,15 +260,20 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka guard let request = paymentRequest else { return } guard let destinationAddress = paymentRequest?.toAddress else { return } - self?.sendAddressCell.rootView.viewModel.addressString = destinationAddress self?.handleRequest(request) + self?.sendAddressCell.textField.text = destinationAddress } } @objc private func sendTapped() { - let sendAddress = sendAddressCell.rootView.viewModel.addressString + if sendAddressCell.textField.isFirstResponder { + sendAddressCell.textField.resignFirstResponder() + } let bareAmount: Satoshis? if sender.transaction == nil { + guard let address = sendAddressCell.address else { + return showAlert(title: S.LitewalletAlert.error.localize(), message: S.Send.noAddress.localize(), buttonLabel: S.Button.ok.localize()) + } guard var amountToSend = amount else { return showAlert(title: S.LitewalletAlert.error.localize(), @@ -289,7 +302,7 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka buttonLabel: S.Button.ok.localize()) } } - guard !(walletManager.wallet?.containsAddress(sendAddress) ?? false) + guard !(walletManager.wallet?.containsAddress(address) ?? false) else { return showAlert(title: S.LitewalletAlert.error.localize(), message: S.Send.containsAddress.localize(), @@ -305,7 +318,7 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka /// Set Ops or Single Output if hasActivatedInlineFees { guard let bareAmt = bareAmount?.rawValue, - sender.createTransactionWithOpsOutputs(amount: bareAmt, to: sendAddress) + sender.createTransactionWithOpsOutputs(amount: bareAmt, to: address) else { return showAlert(title: S.LitewalletAlert.error.localize(), message: S.Send.createTransactionError.localize(), @@ -313,7 +326,7 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka } } else { guard let bareAmt = bareAmount?.rawValue, - sender.createTransaction(amount: bareAmt, to: sendAddress) + sender.createTransaction(amount: bareAmt, to: address) else { return showAlert(title: S.LitewalletAlert.error.localize(), message: S.Send.createTransactionError.localize(), @@ -327,7 +340,7 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka feeType: feeType ?? .regular, state: store.state, selectedRate: amountView.selectedRate, minimumFractionDigits: amountView.minimumFractionDigits, - address: sendAddress, isUsingBiometrics: sender.canUseBiometrics) + address: address, isUsingBiometrics: sender.canUseBiometrics) confirm.successCallback = { confirm.dismiss(animated: true, completion: { @@ -348,12 +361,6 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka } else { NSLog("Error: transaction is nil") } - - guard let amount = amount - else { - NSLog("Error: Amount is nil") - return - } } private func handleRequest(_ request: PaymentRequest) { @@ -509,7 +516,6 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka copyKeyboardChangeAnimation(notification: notification) } - // TODO: - maybe put this in ModalPresentable? private func copyKeyboardChangeAnimation(notification: Notification) { guard let info = KeyboardNotificationInfo(notification.userInfo) else { return } UIView.animate(withDuration: info.animationDuration, delay: 0, options: info.animationOptions, animations: { diff --git a/litewallet/src/Views/SendViewCells/AddressCell.swift b/litewallet/src/Views/SendViewCells/AddressCell.swift index 8d6daf68d..f9723d676 100644 --- a/litewallet/src/Views/SendViewCells/AddressCell.swift +++ b/litewallet/src/Views/SendViewCells/AddressCell.swift @@ -7,7 +7,7 @@ class AddressCell: UIView { } var address: String? { - return contentLabel.text + return textField.text } var didBeginEditing: (() -> Void)? @@ -22,8 +22,6 @@ class AddressCell: UIView { let textField = UITextField() let paste = ShadowButton(title: S.Send.pasteLabel.localize(), type: .tertiary) let scan = ShadowButton(title: S.Send.scanLabel.localize(), type: .tertiary) - fileprivate var contentLabel = UILabel(font: .customBody(size: 13.0), color: .darkText) - private var label = UILabel(font: .customBody(size: 16.0)) fileprivate let gr = UITapGestureRecognizer() fileprivate let tapView = UIView() private let border = UIView(color: .secondaryShadow) @@ -35,10 +33,9 @@ class AddressCell: UIView { NSLog("ERROR: Main color") return } - contentLabel.textColor = textColor - label.textColor = textColor + textField.textColor = textColor } else { - contentLabel.textColor = .darkText + textField.textColor = .darkText } addSubviews() @@ -47,8 +44,6 @@ class AddressCell: UIView { } private func addSubviews() { - addSubview(label) - addSubview(contentLabel) addSubview(textField) addSubview(tapView) addSubview(border) @@ -57,18 +52,9 @@ class AddressCell: UIView { } private func addConstraints() { - label.constrain([ - label.constraint(.centerY, toView: self), - label.constraint(.leading, toView: self, constant: C.padding[2]), - ]) - contentLabel.constrain([ - contentLabel.constraint(.leading, toView: label), - contentLabel.constraint(toBottom: label, constant: 0.0), - contentLabel.trailingAnchor.constraint(equalTo: paste.leadingAnchor, constant: -C.padding[1]), - ]) textField.constrain([ - textField.constraint(.leading, toView: label), - textField.constraint(toBottom: label, constant: 0.0), + textField.constraint(.leading, toView: self, constant: 11.0), + textField.constraint(.centerY, toView: self), textField.trailingAnchor.constraint(equalTo: paste.leadingAnchor, constant: -C.padding[1]), ]) tapView.constrain([ @@ -94,21 +80,13 @@ class AddressCell: UIView { } private func setInitialData() { - label.text = S.Send.enterLTCAddressLabel.localize() - textField.font = contentLabel.font + textField.font = .customBody(size: 15.0) textField.adjustsFontSizeToFitWidth = true textField.minimumFontSize = 10.0 - textField.textColor = contentLabel.textColor - textField.isHidden = true + textField.placeholder = S.Send.enterLTCAddressLabel.localize() textField.returnKeyType = .done textField.delegate = self textField.clearButtonMode = .whileEditing - label.textColor = .grayTextTint - contentLabel.lineBreakMode = .byTruncatingMiddle - - textField.editingChanged = strongify(self) { myself in - myself.contentLabel.text = myself.textField.text - } // GR to start editing label gr.addTarget(self, action: #selector(didTap)) @@ -117,8 +95,6 @@ class AddressCell: UIView { @objc private func didTap() { textField.becomeFirstResponder() - contentLabel.isHidden = true - textField.isHidden = false } @available(*, unavailable) @@ -130,17 +106,13 @@ class AddressCell: UIView { extension AddressCell: UITextFieldDelegate { func textFieldDidBeginEditing(_: UITextField) { didBeginEditing?() - contentLabel.isHidden = true gr.isEnabled = false tapView.isUserInteractionEnabled = false } - func textFieldDidEndEditing(_ textField: UITextField) { - contentLabel.isHidden = false - textField.isHidden = true + func textFieldDidEndEditing(_: UITextField) { gr.isEnabled = true tapView.isUserInteractionEnabled = true - contentLabel.text = textField.text } func textFieldShouldReturn(_ textField: UITextField) -> Bool {