From 75efb53840364f35edbfb4691ce17ff575888ffe Mon Sep 17 00:00:00 2001
From: Bruno Muniz Azevedo Filho <bruno@elixxir.io>
Date: Sun, 11 Dec 2022 03:18:33 -0300
Subject: [PATCH] Fixes size of tappable area for profile button on menu

---
 .../Controllers/MenuController.swift          | 28 +++++-
 .../MenuFeature/Views/MenuHeaderView.swift    | 90 +++++++++----------
 2 files changed, 68 insertions(+), 50 deletions(-)

diff --git a/Sources/MenuFeature/Controllers/MenuController.swift b/Sources/MenuFeature/Controllers/MenuController.swift
index 06a5661a..a968c848 100644
--- a/Sources/MenuFeature/Controllers/MenuController.swift
+++ b/Sources/MenuFeature/Controllers/MenuController.swift
@@ -37,9 +37,29 @@ public final class MenuController: UIViewController {
 
   public override func viewDidLoad() {
     super.viewDidLoad()
-    screenView.headerView.set(
-      username: viewModel.username,
-      image: viewModel.avatar
+
+    let paragraphStyle = NSMutableParagraphStyle()
+    paragraphStyle.lineSpacing = 10
+
+    let attrString = NSMutableAttributedString(
+      string: "\(Localized.Menu.title)\n*\(viewModel.username)*",
+      attributes: [
+        .paragraphStyle: paragraphStyle,
+        .foregroundColor: Asset.neutralWeak.color,
+        .font: Fonts.Mulish.semiBold.font(size: 14.0) as UIFont
+      ]
+    )
+    attrString.addAttributes(attributes: [
+      .foregroundColor: Asset.neutralLine.color,
+      .font: Fonts.Mulish.bold.font(size: 18.0) as UIFont
+    ], betweenCharacters: "*")
+
+    screenView.headerView.textLabel.attributedText = attrString
+
+    screenView.headerView.avatarView.setupProfile(
+      title: viewModel.username,
+      image: viewModel.avatar,
+      size: .large
     )
 
     switch currentItem {
@@ -88,7 +108,7 @@ public final class MenuController: UIViewController {
 
     screenView
       .headerView
-      .nameButton
+      .profileButton
       .publisher(for: .touchUpInside)
       .receive(on: DispatchQueue.main)
       .sink { [unowned self] in
diff --git a/Sources/MenuFeature/Views/MenuHeaderView.swift b/Sources/MenuFeature/Views/MenuHeaderView.swift
index eaea1321..80d51636 100644
--- a/Sources/MenuFeature/Views/MenuHeaderView.swift
+++ b/Sources/MenuFeature/Views/MenuHeaderView.swift
@@ -3,52 +3,50 @@ import Shared
 import AppResources
 
 final class MenuHeaderView: UIView {
-    let nameButton = UIButton()
-    let scanButton = UIButton()
-    let stackView = UIStackView()
-    let avatarView = AvatarView()
-    let verticalStackView = UIStackView()
-
-    init() {
-        super.init(frame: .zero)
-
-        let helloLabel = UILabel()
-        helloLabel.text = Localized.Menu.title
-        helloLabel.textColor = Asset.neutralWeak.color
-        helloLabel.font = Fonts.Mulish.semiBold.font(size: 14.0)
-
-        nameButton.titleLabel?.font = Fonts.Mulish.bold.font(size: 18.0)
-        nameButton.setTitleColor(Asset.neutralLine.color, for: .normal)
-
-        let spacingView = UIView()
-        verticalStackView.axis = .vertical
-        verticalStackView.addArrangedSubview(spacingView)
-        verticalStackView.addArrangedSubview(helloLabel)
-        verticalStackView.addArrangedSubview(nameButton.pinning(at: .left(0)))
-
-        verticalStackView.setCustomSpacing(15, after: spacingView)
-        verticalStackView.setCustomSpacing(5, after: helloLabel)
-
-        scanButton.layer.cornerRadius = 14
-        scanButton.snp.makeConstraints { $0.width.height.equalTo(40) }
-        scanButton.setImage(Asset.menuScan.image, for: .normal)
-        scanButton.backgroundColor = Asset.neutralBody.color
-
-        stackView.spacing = 15
-        stackView.addArrangedSubview(avatarView)
-        stackView.addArrangedSubview(verticalStackView)
-        stackView.addArrangedSubview(scanButton.pinning(at: .top(0)))
-
-        addSubview(stackView)
-
-        avatarView.snp.makeConstraints { $0.width.height.equalTo(70) }
-        stackView.snp.makeConstraints { $0.edges.equalToSuperview() }
+  let textLabel = UILabel()
+  let scanButton = UIButton()
+  let avatarView = AvatarView()
+  let profileButton = UIControl()
+
+  init() {
+    super.init(frame: .zero)
+
+    textLabel.numberOfLines = 0
+    scanButton.layer.cornerRadius = 14
+    avatarView.isUserInteractionEnabled = false
+    scanButton.backgroundColor = Asset.neutralBody.color
+    scanButton.setImage(Asset.menuScan.image, for: .normal)
+
+    addSubview(scanButton)
+    addSubview(profileButton)
+    profileButton.addSubview(avatarView)
+    profileButton.addSubview(textLabel)
+
+    profileButton.snp.makeConstraints {
+      $0.top.equalToSuperview()
+      $0.left.equalToSuperview()
+      $0.bottom.equalToSuperview()
+      $0.right.lessThanOrEqualTo(scanButton.snp.left)
     }
-
-    required init?(coder: NSCoder) { nil  }
-
-    func set(username: String, image: Data? = nil) {
-        nameButton.setTitle(username, for: .normal)
-        avatarView.setupProfile(title: username, image: image, size: .large)
+    avatarView.snp.makeConstraints {
+      $0.top.equalToSuperview()
+      $0.left.equalToSuperview()
+      $0.width.equalTo(70)
+      $0.height.equalTo(70)
+      $0.bottom.equalToSuperview()
     }
+    scanButton.snp.makeConstraints {
+      $0.top.equalToSuperview()
+      $0.right.equalToSuperview()
+      $0.width.equalTo(40)
+      $0.height.equalTo(40)
+    }
+    textLabel.snp.makeConstraints {
+      $0.centerY.equalTo(avatarView)
+      $0.left.equalTo(avatarView.snp.right).offset(20)
+      $0.right.equalToSuperview()
+    }
+  }
+
+  required init?(coder: NSCoder) { nil  }
 }
-- 
GitLab