diff --git a/SnappyShrimp.xcodeproj/project.pbxproj b/SnappyShrimp.xcodeproj/project.pbxproj index 993f520..41f1740 100644 --- a/SnappyShrimp.xcodeproj/project.pbxproj +++ b/SnappyShrimp.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 065B45BC20605201001E1F41 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 065B45BB20605201001E1F41 /* ViewController.xib */; }; 065B45BE20605323001E1F41 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 065B45BD20605323001E1F41 /* ViewController.swift */; }; + 06C01E1C206647CF00C63FBB /* iPhone4S.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06C01E1B206647CF00C63FBB /* iPhone4S.swift */; }; + 06C01E692067032C00C63FBB /* iPadPro12_2nd_generation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06C01E682067032C00C63FBB /* iPadPro12_2nd_generation.swift */; }; 06CF33A11FE81F90007B0B74 /* FBSnapshotTestCase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06CF33A01FE81F90007B0B74 /* FBSnapshotTestCase.framework */; }; 06F6C6581FF3F73B00E055F0 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 06F6C6571FF3F73B00E055F0 /* Media.xcassets */; }; 06F6C6601FF3FE6F00E055F0 /* SnappyShrimpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F6C65F1FF3FE6F00E055F0 /* SnappyShrimpTests.swift */; }; @@ -52,6 +54,8 @@ /* Begin PBXFileReference section */ 065B45BB20605201001E1F41 /* ViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ViewController.xib; sourceTree = ""; }; 065B45BD20605323001E1F41 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 06C01E1B206647CF00C63FBB /* iPhone4S.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = iPhone4S.swift; path = iPhone/iPhone4S.swift; sourceTree = ""; }; + 06C01E682067032C00C63FBB /* iPadPro12_2nd_generation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = iPadPro12_2nd_generation.swift; path = iPad/iPadPro12_2nd_generation.swift; sourceTree = ""; }; 06CF33A01FE81F90007B0B74 /* FBSnapshotTestCase.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FBSnapshotTestCase.framework; path = Carthage/Build/iOS/FBSnapshotTestCase.framework; sourceTree = ""; }; 06F6C6571FF3F73B00E055F0 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = ""; }; 06F6C65D1FF3FE6F00E055F0 /* SnappyShrimpTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SnappyShrimpTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -195,6 +199,7 @@ 427E96251FF2A09000B4A2B4 /* iPadPro9.swift */, 427E96221FF2A09000B4A2B4 /* iPadPro10.swift */, 427E96241FF2A09000B4A2B4 /* iPadPro12.swift */, + 06C01E682067032C00C63FBB /* iPadPro12_2nd_generation.swift */, ); name = iPad; sourceTree = ""; @@ -210,6 +215,7 @@ 427E96101FF2A08600B4A2B4 /* iPhone7Plus.swift */, 427E960D1FF2A08600B4A2B4 /* iPhone8.swift */, 427E960A1FF2A08600B4A2B4 /* iPhone8Plus.swift */, + 06C01E1B206647CF00C63FBB /* iPhone4S.swift */, 427E960C1FF2A08600B4A2B4 /* iPhoneSE.swift */, 427E96121FF2A08600B4A2B4 /* iPhoneX.swift */, ); @@ -390,6 +396,8 @@ 427E96191FF2A08600B4A2B4 /* iPhone7.swift in Sources */, 427E962B1FF2A09000B4A2B4 /* iPadMini.swift in Sources */, 427E96161FF2A08600B4A2B4 /* iPhoneSE.swift in Sources */, + 06C01E1C206647CF00C63FBB /* iPhone4S.swift in Sources */, + 06C01E692067032C00C63FBB /* iPadPro12_2nd_generation.swift in Sources */, 4214CC2C1FDFE62700C7AB61 /* Specifications.swift in Sources */, 4214CC2D1FDFE62700C7AB61 /* SnapshotTest.swift in Sources */, 427E961A1FF2A08600B4A2B4 /* iPhone7Plus.swift in Sources */, diff --git a/SnappyShrimp/Device/iPad/iPadAir.swift b/SnappyShrimp/Device/iPad/iPadAir.swift index 5d84f04..18c7cff 100644 --- a/SnappyShrimp/Device/iPad/iPadAir.swift +++ b/SnappyShrimp/Device/iPad/iPadAir.swift @@ -8,10 +8,10 @@ extension Device { public static let portrait = Presentation( name: "iPad Air FullScreen", size: CGSize.iPadPro9, - traitCollection: UITraitCollection.iPadOld.fullScreen) + traitCollection: UITraitCollection.iPadOld.portrait) public static let landscape = Presentation( name: "iPad Air Landscape FullScreen", size: CGSize.iPadPro9.rotated, - traitCollection: UITraitCollection.iPadOld.fullScreen) + traitCollection: UITraitCollection.iPadOld.landscape) } } diff --git a/SnappyShrimp/Device/iPad/iPadAir2.swift b/SnappyShrimp/Device/iPad/iPadAir2.swift index 9181757..4862642 100644 --- a/SnappyShrimp/Device/iPad/iPadAir2.swift +++ b/SnappyShrimp/Device/iPad/iPadAir2.swift @@ -8,10 +8,10 @@ extension Device { public static let portrait = Presentation( name: "iPad Air2 FullScreen", size: CGSize.iPadPro9, - traitCollection: UITraitCollection.iPadOld.fullScreen) + traitCollection: UITraitCollection.iPadOld.portrait) public static let landscape = Presentation( name: "iPad Air2 Landscape FullScreen", size: CGSize.iPadPro9.rotated, - traitCollection: UITraitCollection.iPadOld.fullScreen) + traitCollection: UITraitCollection.iPadOld.landscape) } } diff --git a/SnappyShrimp/Device/iPad/iPadMini.swift b/SnappyShrimp/Device/iPad/iPadMini.swift index b880815..e918076 100644 --- a/SnappyShrimp/Device/iPad/iPadMini.swift +++ b/SnappyShrimp/Device/iPad/iPadMini.swift @@ -8,10 +8,10 @@ extension Device { public static let portrait = Presentation( name: "iPad mini FullScreen", size: CGSize.iPadPro9, - traitCollection: UITraitCollection.iPadOld.fullScreen) + traitCollection: UITraitCollection.iPadOld.portrait) public static let landscape = Presentation( name: "iPad mini Landscape FullScreen", size: CGSize.iPadPro9.rotated, - traitCollection: UITraitCollection.iPadOld.fullScreen) + traitCollection: UITraitCollection.iPadOld.landscape) } } diff --git a/SnappyShrimp/Device/iPad/iPadPro12_2nd_generation.swift b/SnappyShrimp/Device/iPad/iPadPro12_2nd_generation.swift new file mode 100644 index 0000000..47f6526 --- /dev/null +++ b/SnappyShrimp/Device/iPad/iPadPro12_2nd_generation.swift @@ -0,0 +1,67 @@ +// Copyright 2018, Roman Tysiachnik, Andrii Doroshko. +// Licensed under the terms of the MIT License. See LICENSE.md file in project root for terms. + +import Foundation + +extension Device { + @available(iOS 10.0, *) + public enum iPadPro12_2nd_generation { + public enum portrait { + public static let fullScreen = Presentation( + name: "iPad Pro12 Portrait FullScreen", + size: CGSize.iPadPro12, + traitCollection: UITraitCollection( + traitsFrom: [UITraitCollection.iPad.portrait.fullScreen, + UITraitCollection.Compability.ForceTouch.available, + UITraitCollection.Compability.DisplayGamut.P3])) + public static let twoThirds = Presentation( + name: "iPad Pro12 Portrait Two Third", + size: CGSize.iPadPro12.splitViewTwoThirds, + traitCollection: UITraitCollection( + traitsFrom: [UITraitCollection.iPad.portrait.splitTwoThirds, + UITraitCollection.Compability.ForceTouch.available, + UITraitCollection.Compability.DisplayGamut.P3])) + public static let oneThird = Presentation( + name: "iPad Pro12 Portrait SplitView One Third", + size: CGSize.iPadPro12.splitViewOneThird, + traitCollection: UITraitCollection( + traitsFrom: [UITraitCollection.iPad.portrait.splitOneThird, + UITraitCollection.Compability.ForceTouch.available, + UITraitCollection.Compability.DisplayGamut.P3])) + } + public enum landscape { + public static let fullScreen = Presentation( + name: "iPad Pro12 Landscape FullScreen", + size: CGSize.iPadPro12.rotated, + traitCollection: UITraitCollection( + traitsFrom: [UITraitCollection.iPad.landscape.fullScreen, + UITraitCollection.Compability.ForceTouch.available, + UITraitCollection.Compability.DisplayGamut.P3])) + public static let half = Presentation( + name: "iPad Pro12 Landscape SplitView Half", + size: CGSize.iPadPro12.rotated.splitViewHalf, + traitCollection: UITraitCollection( + traitsFrom: [UITraitCollection.Display.InterfaceIdiom.pad, + UITraitCollection.Display.SizeClass.Vertical.regular, + UITraitCollection.Display.SizeClass.Horizontal.regular, + UITraitCollection.Display.Scale.x2, + UITraitCollection.Compability.ForceTouch.available, + UITraitCollection.Compability.DisplayGamut.P3])) + public static let twoThird = Presentation( + name: "iPad Pro12 Landscape SplitView Two-Thirds", + size: CGSize.iPadPro12.rotated.splitViewTwoThirds, + traitCollection: UITraitCollection( + traitsFrom: [UITraitCollection.iPad.landscape.splitTwoThirds, + UITraitCollection.Compability.ForceTouch.available, + UITraitCollection.Compability.DisplayGamut.P3])) + public static let oneThird = Presentation( + name: "iPad Pro12 Landscape SplitView One Third", + size: CGSize.iPadPro12.rotated.splitViewOneThird, + traitCollection: UITraitCollection( + traitsFrom: [UITraitCollection.iPad.landscape.splitOneThird, + UITraitCollection.Compability.ForceTouch.available, + UITraitCollection.Compability.DisplayGamut.P3])) + } + } +} + diff --git a/SnappyShrimp/Device/iPhone/iPhone4S.swift b/SnappyShrimp/Device/iPhone/iPhone4S.swift new file mode 100644 index 0000000..aaeb619 --- /dev/null +++ b/SnappyShrimp/Device/iPhone/iPhone4S.swift @@ -0,0 +1,18 @@ +// Copyright 2018, Roman Tysiachnik, Andrii Doroshko. +// Licensed under the terms of the MIT License. See LICENSE.md file in project root for terms. + +import Foundation + +extension Device { + public enum iPhone4S { + public static let portrait = Presentation( + name: "iPhone 4S Portrait", + size: CGSize.iPhone4S, + traitCollection: UITraitCollection.iPhone.portrait) + public static let landscape = Presentation( + name: "iPhone 4S Landscape", + size: CGSize.iPhone4S.rotated, + traitCollection: UITraitCollection.iPhone.landscape) + } +} + diff --git a/SnappyShrimp/Presentation.swift b/SnappyShrimp/Presentation.swift index d19a2b2..0299a16 100644 --- a/SnappyShrimp/Presentation.swift +++ b/SnappyShrimp/Presentation.swift @@ -29,4 +29,8 @@ extension Presentation { var scale: CGFloat { return self.traitCollection.displayScale } + @available(iOS 10.0, *) + var gamut: UIDisplayGamut { + return self.traitCollection.displayGamut + } } diff --git a/SnappyShrimp/SnapshotTest.swift b/SnappyShrimp/SnapshotTest.swift index 853302d..9584ffb 100644 --- a/SnappyShrimp/SnapshotTest.swift +++ b/SnappyShrimp/SnapshotTest.swift @@ -6,6 +6,8 @@ import UIKit ///The base class of view snapshotting tests on all possible screens. By default, you have to create schemes for testing and for record. Both of them must contain enviroment arguments with paths to save images and with a value that indicates the record mode state ("RECORD_MODE" by default). For your own implementation of setting record mode true or false, override the setUp method and design your own way of running tests. open class SnapshotTest: FBSnapshotTestCase{ + open var isGamutSupportEnabled = false + ///Settings for snapshot testing. override open func setUp() { super.setUp() @@ -24,6 +26,10 @@ open class SnapshotTest: FBSnapshotTestCase{ guard presentation.userInterfaceIdiom == UIDevice.current.userInterfaceIdiom else { return } guard presentation.scale == UIScreen.main.scale else { return } + if isGamutSupportEnabled, #available(iOS 10.0, *) { + guard presentation.gamut == UIScreen.main.traitCollection.displayGamut else { return } + } + let window = HostWindow(presentation: presentation, context: context) window.addSubview(controller.view) diff --git a/SnappyShrimp/Specifications.swift b/SnappyShrimp/Specifications.swift index a50011a..e8bcdfd 100644 --- a/SnappyShrimp/Specifications.swift +++ b/SnappyShrimp/Specifications.swift @@ -154,22 +154,29 @@ extension UITraitCollection { } } enum iPadOld { - static let fullScreen = iPad.portrait.fullScreen + static let portrait = UITraitCollection( + traitsFrom: [Display.InterfaceIdiom.pad, + Display.SizeClass.Vertical.regular, + Display.SizeClass.Horizontal.regular, + Display.Scale.x2]) + static let landscape = UITraitCollection( + traitsFrom: [Display.InterfaceIdiom.pad, + Display.SizeClass.Vertical.regular, + Display.SizeClass.Horizontal.regular, + Display.Scale.x2]) } } extension CGSize { - static let iPhoneSE = CGSize(width: 320, height: 568) - static let iPhoneX = CGSize(width: 375, height: 812) - static let iPhone = CGSize(width: 375, height: 667) - static let iPhonePlus = CGSize(width: 414, height: 736) - - static let iPadPro9 = CGSize(width: 768, height: 1024) - static let iPadPro10 = CGSize(width: 834, height: 1112) - static let iPadPro12 = CGSize(width: 1024, height: 1366) + static let iPhone4S = CGSize(width: 320, height: 480) + static let iPhoneSE = CGSize(width: 320, height: 568) + static let iPhoneX = CGSize(width: 375, height: 812) + static let iPhone = CGSize(width: 375, height: 667) + static let iPhonePlus = CGSize(width: 414, height: 736) - static let watch38mm = CGSize(width: 272, height: 340) - static let watch42mm = CGSize(width: 312, height: 390) + static let iPadPro9 = CGSize(width: 768, height: 1024) + static let iPadPro10 = CGSize(width: 834, height: 1112) + static let iPadPro12 = CGSize(width: 1024, height: 1366) } extension CGSize { var rotated: CGSize {