Skip to content

Commit

Permalink
Readded then Address Cell View
Browse files Browse the repository at this point in the history
- Still have the issues the ModalViewController height

Signed-off-by: kcw-grunt <[email protected]>
  • Loading branch information
kcw-grunt committed Jan 16, 2024
1 parent 1356735 commit c70d7e3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 67 deletions.
1 change: 0 additions & 1 deletion litewallet/src/AnnounceUpdatesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions litewallet/src/Models/KeyboardNotificationInfo.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import UIKit

struct KeyboardNotificationInfo {
let endFrame: CGRect

let startFrame: CGRect

var deltaY: CGFloat {
return endFrame.minY - startFrame.minY
}
Expand All @@ -27,7 +31,5 @@ struct KeyboardNotificationInfo {
self.animationCurve = animationCurve.uintValue
}

private let endFrame: CGRect
private let startFrame: CGRect
private let animationCurve: UInt
}
2 changes: 1 addition & 1 deletion litewallet/src/ViewControllers/AmountViewController.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
58 changes: 32 additions & 26 deletions litewallet/src/ViewControllers/RootModals/SendViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
])
})
Expand Down Expand Up @@ -141,13 +141,17 @@ class SendViewController: UIViewController, Subscriber, ModalPresentable, Tracka
}

private func addButtonActions() {
// MARK: - MemoCell Callbacks

memoCell.didReturn = { textView in
textView.resignFirstResponder()
}
memoCell.didBeginEditing = { [weak self] in
self?.amountView.closePinPad()
}

// MARK: - AmountView Callbacks

amountView.balanceTextForAmount = { [weak self] amount, rate in
self?.balanceTextForAmount(amount: amount, rate: rate)
}
Expand All @@ -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()
Expand Down Expand Up @@ -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() {
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -305,15 +318,15 @@ 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(),
buttonLabel: S.Button.ok.localize())
}
} 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(),
Expand All @@ -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: {
Expand All @@ -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) {
Expand Down Expand Up @@ -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: {
Expand Down
44 changes: 8 additions & 36 deletions litewallet/src/Views/SendViewCells/AddressCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AddressCell: UIView {
}

var address: String? {
return contentLabel.text
return textField.text
}

var didBeginEditing: (() -> Void)?
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -47,8 +44,6 @@ class AddressCell: UIView {
}

private func addSubviews() {
addSubview(label)
addSubview(contentLabel)
addSubview(textField)
addSubview(tapView)
addSubview(border)
Expand All @@ -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([
Expand All @@ -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))
Expand All @@ -117,8 +95,6 @@ class AddressCell: UIView {

@objc private func didTap() {
textField.becomeFirstResponder()
contentLabel.isHidden = true
textField.isHidden = false
}

@available(*, unavailable)
Expand All @@ -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 {
Expand Down

0 comments on commit c70d7e3

Please sign in to comment.