Skip to content

Commit 1c35206

Browse files
imvmstephencelis
authored andcommitted
Add iPhone 12 and iPhone 12 Pro Max configs (pointfreeco#418)
Co-authored-by: Stephen Celis <[email protected]>
1 parent 3ac9e56 commit 1c35206

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

Sources/SnapshotTesting/Common/View.swift

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,38 @@ public struct ViewImageConfig {
146146
return .init(safeArea: safeArea, size: size, traits: .iPhoneXr(orientation))
147147
}
148148

149+
public static let iPhone12 = ViewImageConfig.iPhone12(.portrait)
150+
151+
public static func iPhone12(_ orientation: Orientation) -> ViewImageConfig {
152+
let safeArea: UIEdgeInsets
153+
let size: CGSize
154+
switch orientation {
155+
case .landscape:
156+
safeArea = .init(top: 0, left: 47, bottom: 21, right: 47)
157+
size = .init(width: 844, height: 390)
158+
case .portrait:
159+
safeArea = .init(top: 47, left: 0, bottom: 34, right: 0)
160+
size = .init(width: 390, height: 844)
161+
}
162+
return .init(safeArea: safeArea, size: size, traits: .iPhone12(orientation))
163+
}
164+
165+
public static let iPhone12ProMax = ViewImageConfig.iPhone12ProMax(.portrait)
166+
167+
public static func iPhone12ProMax(_ orientation: Orientation) -> ViewImageConfig {
168+
let safeArea: UIEdgeInsets
169+
let size: CGSize
170+
switch orientation {
171+
case .landscape:
172+
safeArea = .init(top: 0, left: 47, bottom: 21, right: 47)
173+
size = .init(width: 926, height: 428)
174+
case .portrait:
175+
safeArea = .init(top: 47, left: 0, bottom: 34, right: 0)
176+
size = .init(width: 428, height: 926)
177+
}
178+
return .init(safeArea: safeArea, size: size, traits: .iPhone12ProMax(orientation))
179+
}
180+
149181
public static let iPadMini = ViewImageConfig.iPadMini(.landscape)
150182

151183
public static func iPadMini(_ orientation: Orientation) -> ViewImageConfig {
@@ -572,6 +604,62 @@ extension UITraitCollection {
572604
}
573605
}
574606

607+
public static func iPhone12(_ orientation: ViewImageConfig.Orientation)
608+
-> UITraitCollection {
609+
let base: [UITraitCollection] = [
610+
// .init(displayGamut: .P3),
611+
// .init(displayScale: 3),
612+
.init(forceTouchCapability: .available),
613+
.init(layoutDirection: .leftToRight),
614+
.init(preferredContentSizeCategory: .medium),
615+
.init(userInterfaceIdiom: .phone)
616+
]
617+
switch orientation {
618+
case .landscape:
619+
return .init(
620+
traitsFrom: base + [
621+
.init(horizontalSizeClass: .compact),
622+
.init(verticalSizeClass: .compact)
623+
]
624+
)
625+
case .portrait:
626+
return .init(
627+
traitsFrom: base + [
628+
.init(horizontalSizeClass: .compact),
629+
.init(verticalSizeClass: .regular)
630+
]
631+
)
632+
}
633+
}
634+
635+
public static func iPhone12ProMax(_ orientation: ViewImageConfig.Orientation)
636+
-> UITraitCollection {
637+
let base: [UITraitCollection] = [
638+
// .init(displayGamut: .P3),
639+
// .init(displayScale: 3),
640+
.init(forceTouchCapability: .available),
641+
.init(layoutDirection: .leftToRight),
642+
.init(preferredContentSizeCategory: .medium),
643+
.init(userInterfaceIdiom: .phone)
644+
]
645+
switch orientation {
646+
case .landscape:
647+
return .init(
648+
traitsFrom: base + [
649+
.init(horizontalSizeClass: .regular),
650+
.init(verticalSizeClass: .compact)
651+
]
652+
)
653+
case .portrait:
654+
return .init(
655+
traitsFrom: base + [
656+
.init(horizontalSizeClass: .compact),
657+
.init(verticalSizeClass: .regular)
658+
]
659+
)
660+
}
661+
}
662+
575663
public static let iPadMini = iPad
576664
public static let iPadMini_Compact_SplitView = iPadCompactSplitView
577665
public static let iPad9_7 = iPad

0 commit comments

Comments
 (0)