Open RLEE0731 opened 1 year ago
I wonder if the bug is actually here (https://github.com/pointfreeco/swift-snapshot-testing/blob/main/Sources/SnapshotTesting/Common/View.swift#L964) - since there's a special case for zero safeArea that doesn't seem to be undone (via the dispose pattern) like most of the other changes.
Describe the bug
For our use case, we need to enable
drawHierarchyInKeyWindow
to test 3rd party UI framework and generate visual diff results. As such, we're extendingswift-snapshot-testing/Sources/SnapshotTesting/Snapshotting/UIViewController
's image function, and passing in the boolean to enable drawHierarchyInKeyWindow:With
drawHierarchyInKeyWindow
enabled, when running snapshot tests on a mix of iPhone and iPad strategies in landscape, it seems that if previous device's safe area is .zero, it breaks the the next device's safe area.For example, from the provided project:
If the snapshot test runs the iPad Mini strategy first (which has 20 top offset), then the test will correctly generate the ref and test result view with the proper safe area guides. However, if the iPhone strategy is run first (which has 0 top offset), the following iPad run will also inherit the 0 offset.
This seems to originate from the following place:
In successful test run (iPad runs before iPhone), setting the
window
's rootViewController shows the safe area guides are applied. However, when iPhone test runs before iPad, the safe area guide seems to get zeroed out.To Reproduce MyApp.zip
Expected behavior The safe area guide should adjust when running multiple strategies with different orientations.
Screenshots This is the expected snapshot:
When run after iPhone strategy, the generated iPad Mini snapshot shows no offset:
The test then fails because the entire view is shifted due to the missing offset
Environment
Additional context I may be using this incorrectly to enable
drawHierarchyInKeyWindow
, and would love to hear any suggestion on an alternative approach 🙏