Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update with iPhone 15 devices #839

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions Sources/SnapshotTesting/Common/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -772,6 +841,106 @@
)
}
}

public static func iPhone15(_ orientation: ViewImageConfig.Orientation) -> UITraitCollection {
let base: [UITraitCollection] = [
.init(forceTouchCapability: .unavailable),
.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: .unavailable),
.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: .unavailable),
.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: .unavailable),
.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
Expand Down