swift-snapshot-testing
swift-snapshot-testing copied to clipboard
Latest iOS device resolutions are missing
The issue
The ViewImageConfig struct should include static functions for all the latest devices.
I checked main, and they're not there either. (Note that struct is defined in a file named View.swift for some reason.)
Environment
- swift-snapshot-testing version [e.g. 1.9.0]
- Xcode [e.g. 13.3] (but it doesn't matter)
Workaround I added the following extension in my project, but I only need portrait, not landscape, so I didn't test for those safe area values. I would probably have created a PR, but there are already so many. I figured maybe this would help someone else looking for these.
extension ViewImageConfig {
public static let iPhone13 = ViewImageConfig.iPhone13(.portrait)
public static func iPhone13(_ orientation: Orientation) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
// warning: unverified (unused) values
safeArea = .init(top: 0, left: 44, bottom: 24, right: 44)
size = .init(width: 844, height: 390)
case .portrait:
safeArea = .init(top: 47, left: 0, bottom: 34, right: 0)
size = .init(width: 390, height: 844)
}
return .init(safeArea: safeArea, size: size, traits: .iPhoneX(orientation))
}
public static let iPhone13Mini = ViewImageConfig.iPhone13Mini(.portrait)
public static func iPhone13Mini(_ orientation: Orientation) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
// warning: unverified (unused) values
safeArea = .init(top: 0, left: 44, bottom: 24, right: 44)
size = .init(width: 812, height: 375)
case .portrait:
safeArea = .init(top: 50, left: 0, bottom: 34, right: 0)
size = .init(width: 375, height: 812)
}
return .init(safeArea: safeArea, size: size, traits: .iPhoneX(orientation))
}
/// This is the same as the `iPhone13`
public static let iPhone13Pro = ViewImageConfig.iPhone13(.portrait)
public static let iPhone13ProMax = ViewImageConfig.iPhone13ProMax(.portrait)
public static func iPhone13ProMax(_ orientation: Orientation) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
// warning: unverified (unused) values
safeArea = .init(top: 0, left: 44, bottom: 24, right: 44)
size = .init(width: 926, height: 428)
case .portrait:
safeArea = .init(top: 47, left: 0, bottom: 34, right: 0)
size = .init(width: 428, height: 926)
}
return .init(safeArea: safeArea, size: size, traits: .iPhoneX(orientation))
}
public static let iPhoneSe3rdGen = ViewImageConfig.iPhoneSe3rdGen(.portrait)
public static func iPhoneSe3rdGen(_ orientation: Orientation = .portrait) -> ViewImageConfig {
let safeArea: UIEdgeInsets
let size: CGSize
switch orientation {
case .landscape:
safeArea = .zero
size = .init(width: 667, height: 375)
case .portrait:
safeArea = .init(top: 20, left: 0, bottom: 0, right: 0)
size = .init(width: 375, height: 667)
}
return .init(safeArea: safeArea, size: size, traits: .iPhoneSe(orientation))
}
}
I just realized most of the functions in my extension are using the same values for the traits property, and I have no idea how accurate those are to the new devices. I would love it if someone more knowledgeable could chime-in with how to "find" those per device.