From b179b332a045c2fa588b649ee2d3c183f96064b5 Mon Sep 17 00:00:00 2001 From: max84 Date: Thu, 14 Mar 2024 10:38:10 +0100 Subject: [PATCH 1/2] update with iPhone 15 devices --- Sources/SnapshotTesting/Common/View.swift | 169 ++++++++++++++++++++++ 1 file changed, 169 insertions(+) diff --git a/Sources/SnapshotTesting/Common/View.swift b/Sources/SnapshotTesting/Common/View.swift index 111f6af29..f21c7d02d 100644 --- a/Sources/SnapshotTesting/Common/View.swift +++ b/Sources/SnapshotTesting/Common/View.swift @@ -242,6 +242,75 @@ return .init(safeArea: safeArea, size: size, traits: .iPhone13ProMax(orientation)) } + //https://useyourloaf.com/blog/iphone-15-screen-sizes/ + public static let iPhone15 = ViewImageConfig.iPhone15(.portrait) + + public static func iPhone15(_ orientation: Orientation) -> ViewImageConfig { + let safeArea: UIEdgeInsets + let size: CGSize + switch orientation { + case .landscape: + safeArea = .init(top: 0, left: 59, bottom: 21, right: 59) + size = .init(width: 852, height: 393) + case .portrait: + safeArea = .init(top: 59, left: 0, bottom: 34, right: 0) + size = .init(width: 393, height: 852) + } + + return .init(safeArea: safeArea, size: size, traits: .iPhone15(orientation)) + } + + public static let iPhone15Plus = ViewImageConfig.iPhone15Plus(.portrait) + + public static func iPhone15Plus(_ orientation: Orientation) -> ViewImageConfig { + let safeArea: UIEdgeInsets + let size: CGSize + switch orientation { + case .landscape: + safeArea = .init(top: 0, left: 59, bottom: 21, right: 59) + size = .init(width: 932, height: 430) + case .portrait: + safeArea = .init(top: 59, left: 0, bottom: 34, right: 0) + size = .init(width: 430, height: 932) + } + + return .init(safeArea: safeArea, size: size, traits: .iPhone15Plus(orientation)) + } + + public static let iPhone15Pro = ViewImageConfig.iPhone15Pro(.portrait) + + public static func iPhone15Pro(_ orientation: Orientation) -> ViewImageConfig { + let safeArea: UIEdgeInsets + let size: CGSize + switch orientation { + case .landscape: + safeArea = .init(top: 0, left: 59, bottom: 21, right: 59) + size = .init(width: 852, height: 393) + case .portrait: + safeArea = .init(top: 59, left: 0, bottom: 34, right: 0) + size = .init(width: 393, height: 852) + } + + return .init(safeArea: safeArea, size: size, traits: .iPhone15Pro(orientation)) + } + + public static let iPhone15ProMax = ViewImageConfig.iPhone15ProMax(.portrait) + + public static func iPhone15ProMax(_ orientation: Orientation) -> ViewImageConfig { + let safeArea: UIEdgeInsets + let size: CGSize + switch orientation { + case .landscape: + safeArea = .init(top: 0, left: 59, bottom: 21, right: 59) + size = .init(width: 932, height: 430) + case .portrait: + safeArea = .init(top: 59, left: 0, bottom: 34, right: 0) + size = .init(width: 430, height: 932) + } + + return .init(safeArea: safeArea, size: size, traits: .iPhone15ProMax(orientation)) + } + public static let iPadMini = ViewImageConfig.iPadMini(.landscape) public static func iPadMini(_ orientation: Orientation) -> ViewImageConfig { @@ -772,6 +841,106 @@ ) } } + + public static func iPhone15(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection { + let base: [UITraitCollection] = [ + .init(forceTouchCapability: .available), + .init(layoutDirection: .leftToRight), + .init(preferredContentSizeCategory: .medium), + .init(userInterfaceIdiom: .phone) + ] + switch orientation { + case .landscape: + return .init( + traitsFrom: base + [ + .init(horizontalSizeClass: .regular), + .init(verticalSizeClass: .compact) + ] + ) + case .portrait: + return .init( + traitsFrom: base + [ + .init(horizontalSizeClass: .compact), + .init(verticalSizeClass: .regular) + ] + ) + } + } + + public static func iPhone15Plus(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection { + let base: [UITraitCollection] = [ + .init(forceTouchCapability: .available), + .init(layoutDirection: .leftToRight), + .init(preferredContentSizeCategory: .medium), + .init(userInterfaceIdiom: .phone) + ] + switch orientation { + case .landscape: + return .init( + traitsFrom: base + [ + .init(horizontalSizeClass: .regular), + .init(verticalSizeClass: .compact) + ] + ) + case .portrait: + return .init( + traitsFrom: base + [ + .init(horizontalSizeClass: .compact), + .init(verticalSizeClass: .regular) + ] + ) + } + } + + public static func iPhone15Pro(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection { + let base: [UITraitCollection] = [ + .init(forceTouchCapability: .available), + .init(layoutDirection: .leftToRight), + .init(preferredContentSizeCategory: .medium), + .init(userInterfaceIdiom: .phone) + ] + switch orientation { + case .landscape: + return .init( + traitsFrom: base + [ + .init(horizontalSizeClass: .regular), + .init(verticalSizeClass: .compact) + ] + ) + case .portrait: + return .init( + traitsFrom: base + [ + .init(horizontalSizeClass: .compact), + .init(verticalSizeClass: .regular) + ] + ) + } + } + + public static func iPhone15ProMax(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection { + let base: [UITraitCollection] = [ + .init(forceTouchCapability: .available), + .init(layoutDirection: .leftToRight), + .init(preferredContentSizeCategory: .medium), + .init(userInterfaceIdiom: .phone) + ] + switch orientation { + case .landscape: + return .init( + traitsFrom: base + [ + .init(horizontalSizeClass: .regular), + .init(verticalSizeClass: .compact) + ] + ) + case .portrait: + return .init( + traitsFrom: base + [ + .init(horizontalSizeClass: .compact), + .init(verticalSizeClass: .regular) + ] + ) + } + } public static let iPadMini = iPad public static let iPadMini_Compact_SplitView = iPadCompactSplitView From 6cb6815fefcc4d8d14ddea3d43918f5e29ad6fd0 Mon Sep 17 00:00:00 2001 From: Massimiliano Di Mella Date: Sun, 31 Mar 2024 06:59:00 +0200 Subject: [PATCH 2/2] Update View.swift --- Sources/SnapshotTesting/Common/View.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/SnapshotTesting/Common/View.swift b/Sources/SnapshotTesting/Common/View.swift index f21c7d02d..5c4ee039f 100644 --- a/Sources/SnapshotTesting/Common/View.swift +++ b/Sources/SnapshotTesting/Common/View.swift @@ -844,7 +844,7 @@ public static func iPhone15(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection { let base: [UITraitCollection] = [ - .init(forceTouchCapability: .available), + .init(forceTouchCapability: .unavailable), .init(layoutDirection: .leftToRight), .init(preferredContentSizeCategory: .medium), .init(userInterfaceIdiom: .phone) @@ -869,7 +869,7 @@ public static func iPhone15Plus(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection { let base: [UITraitCollection] = [ - .init(forceTouchCapability: .available), + .init(forceTouchCapability: .unavailable), .init(layoutDirection: .leftToRight), .init(preferredContentSizeCategory: .medium), .init(userInterfaceIdiom: .phone) @@ -894,7 +894,7 @@ public static func iPhone15Pro(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection { let base: [UITraitCollection] = [ - .init(forceTouchCapability: .available), + .init(forceTouchCapability: .unavailable), .init(layoutDirection: .leftToRight), .init(preferredContentSizeCategory: .medium), .init(userInterfaceIdiom: .phone) @@ -919,7 +919,7 @@ public static func iPhone15ProMax(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection { let base: [UITraitCollection] = [ - .init(forceTouchCapability: .available), + .init(forceTouchCapability: .unavailable), .init(layoutDirection: .leftToRight), .init(preferredContentSizeCategory: .medium), .init(userInterfaceIdiom: .phone)