Skip to content

Commit

Permalink
Show invisible element on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Dec 18, 2023
1 parent 7b5918a commit 22e02c8
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 2 deletions.
4 changes: 3 additions & 1 deletion MoppApp/MoppApp/AccessibilityViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AccessibilityViewController : MoppViewController, UITextViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!

@IBOutlet weak var closeButton: UIButton!

@IBOutlet weak var titleLabel: UILabel!

@IBOutlet weak var contentView: UIView!
Expand All @@ -40,6 +40,8 @@ class AccessibilityViewController : MoppViewController, UITextViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()

scrollView.delegate = self

titleLabel.text = L(.accessibilityIntroductionTitle)

var previousLabel: UILabel?
Expand Down
1 change: 1 addition & 0 deletions MoppApp/MoppApp/AddresseeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class AddresseeViewController : MoppViewController {

override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
dismissKeyboard()
LandingViewController.shared.tabButtonsDelegate = self
LandingViewController.shared.presentButtons([])
Expand Down
1 change: 1 addition & 0 deletions MoppApp/MoppApp/ContainerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class ContainerViewController : MoppViewController, ContainerActions, PreviewAct

override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.contentInsetAdjustmentBehavior = .never
updateState(.loading)

Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/CryptoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class CryptoViewController : MoppViewController {
}

@IBAction func menuActivationSelector() {
let invisibleLabel = getInvisibleLabelInView(MoppApp.instance.rootViewController?.view, accessibilityIdentifier: invisibleElementAccessibilityIdentifier)
invisibleLabel?.isHidden = true
let menuViewController = UIStoryboard.menu.instantiateInitialViewController()!
menuViewController.modalPresentationStyle = .overFullScreen
MoppApp.instance.rootViewController?.present(menuViewController, animated: true, completion: nil)
Expand Down
3 changes: 3 additions & 0 deletions MoppApp/MoppApp/DiagnosticsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DiagnosticsViewController: MoppViewController, UIDocumentPickerDelegate {

private var isSavingOneTimeLog = false

@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var appVersionLabel: UILabel!
@IBOutlet weak var opSysVersionLabel: UILabel!
Expand Down Expand Up @@ -135,6 +136,8 @@ class DiagnosticsViewController: MoppViewController, UIDocumentPickerDelegate {

override func viewDidLoad() {
super.viewDidLoad()

scrollView.delegate = self

printLog("Setting up diagnostics data")

Expand Down
34 changes: 34 additions & 0 deletions MoppApp/MoppApp/Extensions/UIViewController+Additions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ extension UIViewController {
label.alpha = 0.0
label.isUserInteractionEnabled = false
label.isEnabled = false
return
}

let usedView = customView ?? view
Expand All @@ -155,6 +156,7 @@ extension UIViewController {
if let scrollView = subview as? UIScrollView,
let lastSubview = scrollView.subviews.last(where: { type(of: $0) == UIView.self }) {
addLabelToBottom(label: label, lastSubview: lastSubview)
changeInvisibleLabelVisibility(label, scrollView, false)
return
} else if let lastSubview = view.subviews.last(where: { type(of: $0) == UIView.self }) {
addLabelToBottom(label: label, lastSubview: lastSubview)
Expand Down Expand Up @@ -184,4 +186,36 @@ extension UIViewController {
label.topAnchor.constraint(equalTo: lastElement.bottomAnchor, constant: 16).isActive = true
label.centerXAnchor.constraint(equalTo: lastElement.centerXAnchor).isActive = true
}

func changeInvisibleLabelVisibility(_ invisibleLabel: UILabel, _ scrollView: UIScrollView?, _ isVisible: Bool? = nil) {
if let isVisible = isVisible {
invisibleLabel.isHidden = !isVisible
} else {
guard let scrollView = scrollView else {
invisibleLabel.isHidden = false
return
}

let visibleRect = CGRect(origin: scrollView.contentOffset, size: scrollView.bounds.size)
invisibleLabel.isHidden = !visibleRect.intersects(invisibleLabel.frame)
}
}

func getInvisibleLabelInView(_ view: UIView?, accessibilityIdentifier identifier: String) -> UILabel? {
guard let view = view else {
return nil
}

if let invisibleLabel = view.subviews.compactMap({ $0 as? UILabel }).first(where: { $0.accessibilityIdentifier == identifier }) {
return invisibleLabel
}

for subview in view.subviews {
if let invisibleLabel = getInvisibleLabelInView(subview, accessibilityIdentifier: identifier) {
return invisibleLabel
}
}

return nil
}
}
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/IdCardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class IdCardViewController : MoppViewController, TokenFlowSigning {

override func viewDidLoad() {
super.viewDidLoad()

scrollView.delegate = self

MoppLibCardReaderManager.sharedInstance().delegate = self

Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/MenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ extension MenuViewController : UITableViewDelegate {

extension MenuViewController : MenuHeaderDelegate {
func menuHeaderDismiss() {
let invisibleLabel = getInvisibleLabelInView(MoppApp.instance.rootViewController?.view, accessibilityIdentifier: invisibleElementAccessibilityIdentifier)
invisibleLabel?.isHidden = false
dismiss(animated: true, completion: nil)
}
}
Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/MobileIDEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class MobileIDEditViewController : MoppViewController, TokenFlowSigning {

override func viewDidLoad() {
super.viewDidLoad()

scrollView.delegate = self

idCodeTextField.moppPresentDismissButton()
phoneTextField.moppPresentDismissButton()
Expand Down
12 changes: 11 additions & 1 deletion MoppApp/MoppApp/MoppViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
class MoppViewController : UIViewController {
class MoppViewController : UIViewController, UIScrollViewDelegate {

@IBOutlet weak var myLabel: UILabel!

Expand Down Expand Up @@ -172,4 +172,14 @@ class MoppViewController : UIViewController {
}
return nil
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if DefaultsHelper.isDebugMode {
guard let label = getInvisibleLabelInView(view, accessibilityIdentifier: invisibleElementAccessibilityIdentifier) else {
return
}

changeInvisibleLabelVisibility(label, scrollView)
}
}
}
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/MyEid.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
</constraints>
</view>
<connections>
<outlet property="tableView" destination="YRp-KX-D2F" id="jIh-pb-Wn3"/>
<outlet property="ui" destination="BwH-nR-tQl" id="z1S-FG-kGa"/>
</connections>
</viewController>
Expand Down Expand Up @@ -589,6 +590,7 @@
</view>
<size key="freeformSize" width="375" height="767"/>
<connections>
<outlet property="scrollView" destination="UZI-z6-jr7" id="iCh-XK-l2J"/>
<outlet property="ui" destination="Pbk-gd-VHp" id="ywA-Rp-vxk"/>
</connections>
</viewController>
Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/MyeIDChangeCodesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
*/
class MyeIDChangeCodesViewController: MoppViewController {
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var ui: MyeIDChangeCodesViewControllerUI!
var model = MyeIDChangeCodesModel()

Expand All @@ -35,6 +36,7 @@ class MyeIDChangeCodesViewController: MoppViewController {
override func viewDidLoad() {
super.viewDidLoad()
LandingViewController.shared.presentButtons([])
scrollView.delegate = self
ui.delegate = self
}

Expand Down
3 changes: 3 additions & 0 deletions MoppApp/MoppApp/MyeIDInfoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import Foundation

class MyeIDInfoViewController: MoppViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var ui: MyeIDInfoViewControllerUI!

weak var infoManager: MyeIDInfoManager!
Expand Down Expand Up @@ -56,6 +57,8 @@ class MyeIDInfoViewController: MoppViewController {
}
ui.setupOnce()
ui.delegate = self

tableView.delegate = self

NotificationCenter.default.addObserver(
self,
Expand Down
1 change: 1 addition & 0 deletions MoppApp/MoppApp/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@
<outlet property="rpUUIDInfo" destination="9M0-ZI-Vph" id="hFZ-Ln-SfA"/>
<outlet property="saveDiagnosticsLabel" destination="wJ6-Ui-Rim" id="oTD-d1-7Id"/>
<outlet property="saveLogButtonLabel" destination="YuQ-2C-isn" id="3ga-jj-Iq7"/>
<outlet property="scrollView" destination="Ki8-k3-cmp" id="b7L-RB-fck"/>
<outlet property="sivaURL" destination="mys-OT-GnR" id="urG-d8-7zH"/>
<outlet property="smartIdSKURL" destination="ruH-oH-HXZ" id="mkI-1f-AwI"/>
<outlet property="smartIdURL" destination="axW-Sz-ktm" id="Uc2-Sx-eU7"/>
Expand Down
3 changes: 3 additions & 0 deletions MoppApp/MoppApp/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
*/
class SettingsViewController: MoppViewController {

private(set) var timestampUrl: String!
@IBOutlet weak var tableView: UITableView!

Expand Down Expand Up @@ -99,6 +100,8 @@ class SettingsViewController: MoppViewController {
override func viewDidLoad() {
super.viewDidLoad()

tableView.delegate = self

timestampUrl = DefaultsHelper.timestampUrl
isDefaultTimestampValue = DefaultsHelper.defaultSettingsSwitch
}
Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/SigningViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class SigningViewController : MoppViewController {
}

@IBAction func menuActivationSelector() {
let invisibleLabel = getInvisibleLabelInView(MoppApp.instance.rootViewController?.view, accessibilityIdentifier: invisibleElementAccessibilityIdentifier)
invisibleLabel?.isHidden = true
let menuViewController = UIStoryboard.menu.instantiateInitialViewController()!
menuViewController.modalPresentationStyle = .overFullScreen
MoppApp.instance.rootViewController?.present(menuViewController, animated: true, completion: nil)
Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/SmartIDEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class SmartIDEditViewController : MoppViewController, TokenFlowSigning {

override func viewDidLoad() {
super.viewDidLoad()

scrollView.delegate = self

titleLabel.text = L(.smartIdTitle)
countryLabel.text = L(.smartIdCountryTitle)
Expand Down

0 comments on commit 22e02c8

Please sign in to comment.