Left margin is not respected in view controller snapshot images on iPhone 8/SE in landscape
tinder-cfuller opened this issue · 1 comments
tinder-cfuller commented
Describe the bug
Left margin is not respected in view controller snapshot images on iPhone 8/SE in landscape even though the left margin is reflected in the recursive description (and respected when running the app in the simulator).
To Reproduce
Sample Project:
View Controller:
class ViewController: UIViewController {
let blueView: UIView = {
let view = UIView()
view.backgroundColor = .blue
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
view.addSubview(blueView)
NSLayoutConstraint.activate([
blueView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
blueView.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
blueView.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),
blueView.bottomAnchor.constraint(equalTo: view.layoutMarginsGuide.bottomAnchor)
])
}
}
Test:
final class SampleTests: XCTestCase {
func testViewController() throws {
let device: ViewImageConfig = .iPhone8(.landscape)
let vc = ViewController()
assertSnapshot(matching: vc, as: .recursiveDescription(on: device))
assertSnapshot(matching: vc, as: .image(on: device))
}
}
Recursive Description:
The left margin of 20 is reflected in the x
of the frame
.
<UIView; frame = (20 0; 627 375); backgroundColor = UIExtendedSRGBColorSpace 0 0 1 1; layer = <CALayer>>
Snapshot Image:
The left margin is incorrectly not respected.
Expected behavior
The left margin should be correctly respected in view controller snapshot images on iPhone 8/SE in landscape.
For example, the left margin is respected when running the app in the simulator.
Simulator Screenshot:
Environment
- swift-snapshot-testing version
1.11.1
- Xcode
14.3.1
- Swift
5.8
- OS:
iOS 16.4
tinder-cfuller commented
I just tested the above ☝️ proposed fix in the sample app attached to this issue and it worked 👍
Thank you @leohemanth!