Skip to content

Commit 484d6e1

Browse files
cltnschlosserReid Main
authored andcommitted
Use UIScreen over keyWindow to get size, so that size can be used wihout host application (#79)
1 parent a2cf63e commit 484d6e1

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

FBSnapshotTestCase/FBSnapshotTestCasePlatform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
2121
- FBSnapshotTestCaseFileNameIncludeOptionNone: Don't include any of these options at all.
2222
- FBSnapshotTestCaseFileNameIncludeOptionDevice: The file name should include the device name, as returned by UIDevice.currentDevice.model.
2323
- FBSnapshotTestCaseFileNameIncludeOptionOS: The file name should include the OS version, as returned by UIDevice.currentDevice.systemVersion.
24-
- FBSnapshotTestCaseFileNameIncludeOptionScreenSize: The file name should include the screen size of the current keyWindow, as returned by UIApplication.sharedApplication.keyWindow.bounds.size.
24+
- FBSnapshotTestCaseFileNameIncludeOptionScreenSize: The file name should include the screen size of the current device, as returned by UIScreen.mainScreen.bounds.size.
2525
- FBSnapshotTestCaseFileNameIncludeOptionScreenScale: The file name should include the scale of the current device, as returned by UIScreen.mainScreen.scale.
2626
*/
2727
typedef NS_OPTIONS(NSUInteger, FBSnapshotTestCaseFileNameIncludeOption) {

FBSnapshotTestCase/FBSnapshotTestCasePlatform.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ BOOL FBSnapshotTestCaseIs64Bit(void)
4242
}
4343

4444
if ((option & FBSnapshotTestCaseFileNameIncludeOptionScreenSize) == FBSnapshotTestCaseFileNameIncludeOptionScreenSize) {
45-
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
46-
CGSize screenSize = keyWindow.bounds.size;
45+
CGSize screenSize = [UIScreen mainScreen].bounds.size;
4746
fileName = [fileName stringByAppendingFormat:@"_%.0fx%.0f", screenSize.width, screenSize.height];
4847
}
4948

FBSnapshotTestCaseTests/FBSnapshotControllerTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ - (void)testFailedImageWithFileNameOptionShouldHaveAllOptionsInName
148148
XCTAssertTrue([filePath containsString:allOptionsIncludedReferencePath]);
149149

150150
// Manually constructing expected filePath to make sure it looks correct
151-
NSString *expectedFilePath = [NSString stringWithFormat:@"%@%@_%@_%@_%.0fx%.0f@%.fx.png", referenceImagesDirectory, NSStringFromSelector(selector), [UIDevice currentDevice].model, [[UIDevice currentDevice].systemVersion stringByReplacingOccurrencesOfString:@"." withString:@"_"], [[UIApplication sharedApplication] keyWindow].bounds.size.width, [[UIApplication sharedApplication] keyWindow].bounds.size.height, [[UIScreen mainScreen] scale]];
151+
NSString *expectedFilePath = [NSString stringWithFormat:@"%@%@_%@_%@_%.0fx%.0f@%.fx.png", referenceImagesDirectory, NSStringFromSelector(selector), [UIDevice currentDevice].model, [[UIDevice currentDevice].systemVersion stringByReplacingOccurrencesOfString:@"." withString:@"_"], [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height, [[UIScreen mainScreen] scale]];
152152
XCTAssertEqualObjects(expectedFilePath, filePath);
153153
}
154154

0 commit comments

Comments
 (0)