import SwiftUI struct AppIconPickerNavigation { static let columns = 4 static func destination( from choice: AppIconChoice, direction: MoveCommandDirection, rightToLeft: Bool = false ) -> AppIconChoice { let choices = AppIconChoice.allCases guard let index = choices.firstIndex(of: choice) else { preconditionFailure("Unknown app icon") } let next: Int switch direction { case .left: next = index + (rightToLeft ? 1 : -1) case .right: next = index + (rightToLeft ? -1 : 1) case .up: next = index - columns case .down: next = index + columns @unknown default: return choice } guard choices.indices.contains(next) else { return choice } if direction == .left || direction == .right, next / columns != index / columns { return choice } return choices[next] } }