Skip to content

Commit 5c4fc49

Browse files
committed
pr suggestion: use computed var for scaleY
1 parent 5e342a9 commit 5c4fc49

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ElementX/Sources/Screens/Timeline/TimelineTableViewController.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ class TimelineTableViewController: UIViewController {
168168
/// Whether or not the view has been shown on screen yet.
169169
private var hasAppearedOnce = false
170170

171+
/// Value that determines if the table view is flipped or not according to the VoiceOver status.
172+
private var scaleY: CGFloat {
173+
UIAccessibility.isVoiceOverRunning ? 1 : -1
174+
}
175+
171176
init(coordinator: TimelineViewRepresentable.Coordinator,
172177
isScrolledToBottom: Binding<Bool>,
173178
scrollToBottomPublisher: PassthroughSubject<Void, Never>) {
@@ -185,7 +190,7 @@ class TimelineTableViewController: UIViewController {
185190

186191
// The tableview should be flipped to display the newest items at the top
187192
// the only exception is VoiceOver, where we want to keep the latest item at the top as Android.
188-
tableView.transform = CGAffineTransform(scaleX: 1, y: UIAccessibility.isVoiceOverRunning ? 1 : -1)
193+
tableView.transform = CGAffineTransform(scaleX: 1, y: scaleY)
189194
view.addSubview(tableView)
190195

191196
// Prevents XCUITest from invoking the diffable dataSource's cellProvider
@@ -223,7 +228,7 @@ class TimelineTableViewController: UIViewController {
223228
NotificationCenter.default.publisher(for: UIAccessibility.voiceOverStatusDidChangeNotification)
224229
.sink { [weak self] _ in
225230
guard let self else { return }
226-
tableView.transform = CGAffineTransform(scaleX: 1, y: UIAccessibility.isVoiceOverRunning ? 1 : -1)
231+
tableView.transform = CGAffineTransform(scaleX: 1, y: scaleY)
227232
tableView.reloadData()
228233
}
229234
.store(in: &cancellables)
@@ -273,7 +278,7 @@ class TimelineTableViewController: UIViewController {
273278
.background(Color.clear)
274279

275280
// Flipping the cell can create some issues with cell resizing, so flip the content View
276-
cell.contentView.transform = CGAffineTransform(scaleX: 1, y: UIAccessibility.isVoiceOverRunning ? 1 : -1)
281+
cell.contentView.transform = CGAffineTransform(scaleX: 1, y: scaleY)
277282
cell.accessibilityElements = [cell.contentView] // Ensure VoiceOver reads the content view only
278283

279284
return cell
@@ -300,7 +305,7 @@ class TimelineTableViewController: UIViewController {
300305
.background(Color.clear)
301306

302307
// Flipping the cell can create some issues with cell resizing, so flip the content View
303-
cell.contentView.transform = CGAffineTransform(scaleX: 1, y: UIAccessibility.isVoiceOverRunning ? 1 : -1)
308+
cell.contentView.transform = CGAffineTransform(scaleX: 1, y: scaleY)
304309
return cell
305310
}
306311
}

0 commit comments

Comments
 (0)