From 99ae1573dc8d9e47b0b570d8404eddf6f8ec743e Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Wed, 18 Jun 2025 11:30:16 +0200 Subject: [PATCH] pr suggestion: use computed var for scaleY --- .../Timeline/TimelineTableViewController.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift b/ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift index 0d3d9e4ac..59292ff5b 100644 --- a/ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift +++ b/ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift @@ -168,6 +168,11 @@ class TimelineTableViewController: UIViewController { /// Whether or not the view has been shown on screen yet. private var hasAppearedOnce = false + /// Value that determines if the table view is flipped or not according to the VoiceOver status. + private var scaleY: CGFloat { + UIAccessibility.isVoiceOverRunning ? 1 : -1 + } + init(coordinator: TimelineViewRepresentable.Coordinator, isScrolledToBottom: Binding, scrollToBottomPublisher: PassthroughSubject) { @@ -185,7 +190,7 @@ class TimelineTableViewController: UIViewController { // The tableview should be flipped to display the newest items at the top // the only exception is VoiceOver, where we want to keep the latest item at the top as Android. - tableView.transform = CGAffineTransform(scaleX: 1, y: UIAccessibility.isVoiceOverRunning ? 1 : -1) + tableView.transform = CGAffineTransform(scaleX: 1, y: scaleY) view.addSubview(tableView) // Prevents XCUITest from invoking the diffable dataSource's cellProvider @@ -223,7 +228,7 @@ class TimelineTableViewController: UIViewController { NotificationCenter.default.publisher(for: UIAccessibility.voiceOverStatusDidChangeNotification) .sink { [weak self] _ in guard let self else { return } - tableView.transform = CGAffineTransform(scaleX: 1, y: UIAccessibility.isVoiceOverRunning ? 1 : -1) + tableView.transform = CGAffineTransform(scaleX: 1, y: scaleY) tableView.reloadData() } .store(in: &cancellables) @@ -273,7 +278,7 @@ class TimelineTableViewController: UIViewController { .background(Color.clear) // Flipping the cell can create some issues with cell resizing, so flip the content View - cell.contentView.transform = CGAffineTransform(scaleX: 1, y: UIAccessibility.isVoiceOverRunning ? 1 : -1) + cell.contentView.transform = CGAffineTransform(scaleX: 1, y: scaleY) cell.accessibilityElements = [cell.contentView] // Ensure VoiceOver reads the content view only return cell @@ -300,7 +305,7 @@ class TimelineTableViewController: UIViewController { .background(Color.clear) // Flipping the cell can create some issues with cell resizing, so flip the content View - cell.contentView.transform = CGAffineTransform(scaleX: 1, y: UIAccessibility.isVoiceOverRunning ? 1 : -1) + cell.contentView.transform = CGAffineTransform(scaleX: 1, y: scaleY) return cell } }