From b2a1e085c28c61e027cdc6bd11905f67ad6863c1 Mon Sep 17 00:00:00 2001 From: Kazuhiro Hayashi Date: Fri, 10 Jan 2020 12:43:54 +0900 Subject: [PATCH 1/6] delete initialLoad from viewWillTransitionToSize --- PagingKit/PagingContentViewController.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/PagingKit/PagingContentViewController.swift b/PagingKit/PagingContentViewController.swift index fa446a9..5bf23ef 100644 --- a/PagingKit/PagingContentViewController.swift +++ b/PagingKit/PagingContentViewController.swift @@ -319,8 +319,6 @@ public class PagingContentViewController: UIViewController { } override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { - removeAll() - initialLoad(with: leftSidePageIndex) coordinator.animate(alongsideTransition: { [weak self] (context) in guard let _self = self else { return } _self.scroll(to: _self.leftSidePageIndex, animated: false) From 34e5c7e55cc66d68a83d444af558cc1d9607a45a Mon Sep 17 00:00:00 2001 From: Kazuhiro Hayashi Date: Fri, 24 Jan 2020 11:57:22 +0900 Subject: [PATCH 2/6] reset appearance handler when rotating --- PagingKit/PagingContentViewController.swift | 36 +++++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/PagingKit/PagingContentViewController.swift b/PagingKit/PagingContentViewController.swift index 5bf23ef..42413de 100644 --- a/PagingKit/PagingContentViewController.swift +++ b/PagingKit/PagingContentViewController.swift @@ -133,7 +133,7 @@ public class PagingContentViewController: UIViewController { fileprivate var numberOfPages: Int = 0 fileprivate var explicitPaging: ExplicitPaging? - var appearanceHandler: ContentsAppearanceHandlerProtocol = ContentsAppearanceHandler() + var appearanceHandler: ContentsAppearanceHandlerProtocol? /// The object that acts as the delegate of the content view controller. public weak var delegate: PagingContentViewControllerDelegate? @@ -165,7 +165,7 @@ public class PagingContentViewController: UIViewController { /// - Parameter page: An index to show after reloading. public func reloadData(with page: Int? = nil, completion: (() -> Void)? = nil) { removeAll() - appearanceHandler.preReload(at: leftSidePageIndex) + appearanceHandler?.preReload(at: leftSidePageIndex) let preferredPage = page ?? leftSidePageIndex leftSidePageIndex = preferredPage initialLoad(with: preferredPage) @@ -176,7 +176,7 @@ public class PagingContentViewController: UIViewController { }, completion: { [weak self] _ in self?.scroll(to: preferredPage, needsCallAppearance: false, animated: false) { _ in - self?.appearanceHandler.postReload(at: preferredPage) + self?.appearanceHandler?.postReload(at: preferredPage) completion?() } } @@ -197,7 +197,7 @@ public class PagingContentViewController: UIViewController { delegate?.contentViewController(viewController: self, willBeginPagingAt: leftSidePageIndex, animated: animated) if needsCallAppearance { - appearanceHandler.beginDragging(at: leftSidePageIndex) + appearanceHandler?.beginDragging(at: leftSidePageIndex) } loadPagesIfNeeded(page: page) @@ -208,7 +208,7 @@ public class PagingContentViewController: UIViewController { guard let _self = self, finished else { return } if needsCallAppearance { - _self.appearanceHandler.stopScrolling(at: _self.leftSidePageIndex) + _self.appearanceHandler?.stopScrolling(at: _self.leftSidePageIndex) } completion?(finished) @@ -274,29 +274,34 @@ public class PagingContentViewController: UIViewController { view.addConstraints([.top, .bottom, .leading, .trailing].anchor(from: scrollView, to: view)) view.backgroundColor = .clear - appearanceHandler.contentsDequeueHandler = { [weak self] in + setupAppearanceHandler() + } + + private func setupAppearanceHandler() { + appearanceHandler = ContentsAppearanceHandler() + appearanceHandler?.contentsDequeueHandler = { [weak self] in self?.cachedViewControllers } } public override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - appearanceHandler.callApparance(.viewWillAppear, animated: animated, at: leftSidePageIndex) + appearanceHandler?.callApparance(.viewWillAppear, animated: animated, at: leftSidePageIndex) } public override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - appearanceHandler.callApparance(.viewDidAppear, animated: animated, at: leftSidePageIndex) + appearanceHandler?.callApparance(.viewDidAppear, animated: animated, at: leftSidePageIndex) } public override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) - appearanceHandler.callApparance(.viewWillDisappear, animated: animated, at: leftSidePageIndex) + appearanceHandler?.callApparance(.viewWillDisappear, animated: animated, at: leftSidePageIndex) } public override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) - appearanceHandler.callApparance(.viewDidDisappear, animated: animated, at: leftSidePageIndex) + appearanceHandler?.callApparance(.viewDidDisappear, animated: animated, at: leftSidePageIndex) } override public func viewDidLayoutSubviews() { @@ -319,10 +324,13 @@ public class PagingContentViewController: UIViewController { } override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + appearanceHandler = nil coordinator.animate(alongsideTransition: { [weak self] (context) in guard let _self = self else { return } _self.scroll(to: _self.leftSidePageIndex, animated: false) - }, completion: nil) + }, completion: { [weak self] _ in + self?.setupAppearanceHandler() + }) super.viewWillTransition(to: size, with: coordinator) } @@ -386,7 +394,7 @@ extension PagingContentViewController: UIScrollViewDelegate { guard let _self = self else { return } _self.delegate?.contentViewController(viewController: _self, willBeginPagingAt: leftSidePageIndex, animated: false) _self.explicitPaging?.start() - _self.appearanceHandler.beginDragging(at: leftSidePageIndex) + _self.appearanceHandler?.beginDragging(at: leftSidePageIndex) }) leftSidePageIndex = Int(scrollView.contentOffset.x / scrollView.bounds.width) delegate?.contentViewController(viewController: self, willBeginManualScrollOn: leftSidePageIndex) @@ -413,7 +421,7 @@ extension PagingContentViewController: UIScrollViewDelegate { loadPagesIfNeeded() delegate?.contentViewController(viewController: self, didEndManualScrollOn: leftSidePageIndex) if explicitPaging.isPaging { - appearanceHandler.stopScrolling(at: leftSidePageIndex) + appearanceHandler?.stopScrolling(at: leftSidePageIndex) delegate?.contentViewController(viewController: self, didFinishPagingAt: leftSidePageIndex, animated: true) } @@ -429,7 +437,7 @@ extension PagingContentViewController: UIScrollViewDelegate { loadPagesIfNeeded() delegate?.contentViewController(viewController: self, didEndManualScrollOn: leftSidePageIndex) if explicitPaging.isPaging { - appearanceHandler.stopScrolling(at: leftSidePageIndex) + appearanceHandler?.stopScrolling(at: leftSidePageIndex) delegate?.contentViewController(viewController: self, willFinishPagingAt: leftSidePageIndex, animated: false) delegate?.contentViewController(viewController: self, didFinishPagingAt: leftSidePageIndex, animated: false) From b983d81959d48c0acc599193a3233ac53e0e2bfe Mon Sep 17 00:00:00 2001 From: Kazuhiro Hayashi Date: Fri, 31 Jan 2020 13:41:37 +0900 Subject: [PATCH 3/6] support multitask --- PagingKit/PagingContentViewController.swift | 38 ++++++++------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/PagingKit/PagingContentViewController.swift b/PagingKit/PagingContentViewController.swift index 42413de..a2231bd 100644 --- a/PagingKit/PagingContentViewController.swift +++ b/PagingKit/PagingContentViewController.swift @@ -133,7 +133,7 @@ public class PagingContentViewController: UIViewController { fileprivate var numberOfPages: Int = 0 fileprivate var explicitPaging: ExplicitPaging? - var appearanceHandler: ContentsAppearanceHandlerProtocol? + var appearanceHandler: ContentsAppearanceHandlerProtocol = ContentsAppearanceHandler() /// The object that acts as the delegate of the content view controller. public weak var delegate: PagingContentViewControllerDelegate? @@ -165,7 +165,7 @@ public class PagingContentViewController: UIViewController { /// - Parameter page: An index to show after reloading. public func reloadData(with page: Int? = nil, completion: (() -> Void)? = nil) { removeAll() - appearanceHandler?.preReload(at: leftSidePageIndex) + appearanceHandler.preReload(at: leftSidePageIndex) let preferredPage = page ?? leftSidePageIndex leftSidePageIndex = preferredPage initialLoad(with: preferredPage) @@ -176,7 +176,7 @@ public class PagingContentViewController: UIViewController { }, completion: { [weak self] _ in self?.scroll(to: preferredPage, needsCallAppearance: false, animated: false) { _ in - self?.appearanceHandler?.postReload(at: preferredPage) + self?.appearanceHandler.postReload(at: preferredPage) completion?() } } @@ -197,7 +197,7 @@ public class PagingContentViewController: UIViewController { delegate?.contentViewController(viewController: self, willBeginPagingAt: leftSidePageIndex, animated: animated) if needsCallAppearance { - appearanceHandler?.beginDragging(at: leftSidePageIndex) + appearanceHandler.beginDragging(at: leftSidePageIndex) } loadPagesIfNeeded(page: page) @@ -208,7 +208,7 @@ public class PagingContentViewController: UIViewController { guard let _self = self, finished else { return } if needsCallAppearance { - _self.appearanceHandler?.stopScrolling(at: _self.leftSidePageIndex) + _self.appearanceHandler.stopScrolling(at: _self.leftSidePageIndex) } completion?(finished) @@ -274,34 +274,29 @@ public class PagingContentViewController: UIViewController { view.addConstraints([.top, .bottom, .leading, .trailing].anchor(from: scrollView, to: view)) view.backgroundColor = .clear - setupAppearanceHandler() - } - - private func setupAppearanceHandler() { - appearanceHandler = ContentsAppearanceHandler() - appearanceHandler?.contentsDequeueHandler = { [weak self] in + appearanceHandler.contentsDequeueHandler = { [weak self] in self?.cachedViewControllers } } public override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - appearanceHandler?.callApparance(.viewWillAppear, animated: animated, at: leftSidePageIndex) + appearanceHandler.callApparance(.viewWillAppear, animated: animated, at: leftSidePageIndex) } public override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - appearanceHandler?.callApparance(.viewDidAppear, animated: animated, at: leftSidePageIndex) + appearanceHandler.callApparance(.viewDidAppear, animated: animated, at: leftSidePageIndex) } public override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) - appearanceHandler?.callApparance(.viewWillDisappear, animated: animated, at: leftSidePageIndex) + appearanceHandler.callApparance(.viewWillDisappear, animated: animated, at: leftSidePageIndex) } public override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) - appearanceHandler?.callApparance(.viewDidDisappear, animated: animated, at: leftSidePageIndex) + appearanceHandler.callApparance(.viewDidDisappear, animated: animated, at: leftSidePageIndex) } override public func viewDidLayoutSubviews() { @@ -324,13 +319,10 @@ public class PagingContentViewController: UIViewController { } override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { - appearanceHandler = nil coordinator.animate(alongsideTransition: { [weak self] (context) in guard let _self = self else { return } - _self.scroll(to: _self.leftSidePageIndex, animated: false) - }, completion: { [weak self] _ in - self?.setupAppearanceHandler() - }) + _self.scroll(to: _self.leftSidePageIndex, needsCallAppearance: false, animated: false) + }, completion: nil) super.viewWillTransition(to: size, with: coordinator) } @@ -394,7 +386,7 @@ extension PagingContentViewController: UIScrollViewDelegate { guard let _self = self else { return } _self.delegate?.contentViewController(viewController: _self, willBeginPagingAt: leftSidePageIndex, animated: false) _self.explicitPaging?.start() - _self.appearanceHandler?.beginDragging(at: leftSidePageIndex) + _self.appearanceHandler.beginDragging(at: leftSidePageIndex) }) leftSidePageIndex = Int(scrollView.contentOffset.x / scrollView.bounds.width) delegate?.contentViewController(viewController: self, willBeginManualScrollOn: leftSidePageIndex) @@ -421,7 +413,7 @@ extension PagingContentViewController: UIScrollViewDelegate { loadPagesIfNeeded() delegate?.contentViewController(viewController: self, didEndManualScrollOn: leftSidePageIndex) if explicitPaging.isPaging { - appearanceHandler?.stopScrolling(at: leftSidePageIndex) + appearanceHandler.stopScrolling(at: leftSidePageIndex) delegate?.contentViewController(viewController: self, didFinishPagingAt: leftSidePageIndex, animated: true) } @@ -437,7 +429,7 @@ extension PagingContentViewController: UIScrollViewDelegate { loadPagesIfNeeded() delegate?.contentViewController(viewController: self, didEndManualScrollOn: leftSidePageIndex) if explicitPaging.isPaging { - appearanceHandler?.stopScrolling(at: leftSidePageIndex) + appearanceHandler.stopScrolling(at: leftSidePageIndex) delegate?.contentViewController(viewController: self, willFinishPagingAt: leftSidePageIndex, animated: false) delegate?.contentViewController(viewController: self, didFinishPagingAt: leftSidePageIndex, animated: false) From 05d9b516e3bad5d7321ab628c0544521b3ea96c0 Mon Sep 17 00:00:00 2001 From: Kazuhiro Hayashi Date: Sun, 9 Feb 2020 12:17:35 +0900 Subject: [PATCH 4/6] add host application for unit test --- PagingKit.xcodeproj/project.pbxproj | 179 +++++++++++++++++- UnitTestHostApplication/AppDelegate.swift | 37 ++++ .../AppIcon.appiconset/Contents.json | 98 ++++++++++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 25 +++ .../Base.lproj/Main.storyboard | 24 +++ UnitTestHostApplication/Info.plist | 64 +++++++ UnitTestHostApplication/SceneDelegate.swift | 53 ++++++ UnitTestHostApplication/ViewController.swift | 20 ++ 9 files changed, 501 insertions(+), 5 deletions(-) create mode 100644 UnitTestHostApplication/AppDelegate.swift create mode 100644 UnitTestHostApplication/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 UnitTestHostApplication/Assets.xcassets/Contents.json create mode 100644 UnitTestHostApplication/Base.lproj/LaunchScreen.storyboard create mode 100644 UnitTestHostApplication/Base.lproj/Main.storyboard create mode 100644 UnitTestHostApplication/Info.plist create mode 100644 UnitTestHostApplication/SceneDelegate.swift create mode 100644 UnitTestHostApplication/ViewController.swift diff --git a/PagingKit.xcodeproj/project.pbxproj b/PagingKit.xcodeproj/project.pbxproj index 8928026..01d6046 100644 --- a/PagingKit.xcodeproj/project.pbxproj +++ b/PagingKit.xcodeproj/project.pbxproj @@ -8,6 +8,12 @@ /* Begin PBXBuildFile section */ 2B283F051FA8A2BD00DA2FE4 /* Array+NSLayoutConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B283F041FA8A2BD00DA2FE4 /* Array+NSLayoutConstraint.swift */; }; + 2B28FBB923EFAF90007101B9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B28FBB823EFAF90007101B9 /* AppDelegate.swift */; }; + 2B28FBBB23EFAF90007101B9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B28FBBA23EFAF90007101B9 /* SceneDelegate.swift */; }; + 2B28FBBD23EFAF90007101B9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B28FBBC23EFAF90007101B9 /* ViewController.swift */; }; + 2B28FBC023EFAF90007101B9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2B28FBBE23EFAF90007101B9 /* Main.storyboard */; }; + 2B28FBC223EFAF93007101B9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2B28FBC123EFAF93007101B9 /* Assets.xcassets */; }; + 2B28FBC523EFAF93007101B9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2B28FBC323EFAF93007101B9 /* LaunchScreen.storyboard */; }; 2B463D261F958C0D00F241E1 /* PagingMenuFocusView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2B463D251F958C0D00F241E1 /* PagingMenuFocusView.xib */; }; 2B4F03431F8FA0230015FCC8 /* PagingMenuViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B4F03421F8FA0230015FCC8 /* PagingMenuViewControllerTests.swift */; }; 2B4F03451F8FA0760015FCC8 /* PagingMenuViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B4F03441F8FA0760015FCC8 /* PagingMenuViewTests.swift */; }; @@ -17,10 +23,10 @@ 2BC16A321FFE355F00CB884A /* UnderlineFocusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BC16A311FFE355F00CB884A /* UnderlineFocusView.swift */; }; 2BC16A341FFE35AA00CB884A /* PagingKitProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BC16A331FFE35AA00CB884A /* PagingKitProxy.swift */; }; 2BC16A361FFE3B3E00CB884A /* TitleLabelMenuViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BC16A351FFE3B3E00CB884A /* TitleLabelMenuViewCell.swift */; }; - 2BE185F623AB7AAE00B457ED /* ContentAppearanceHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE185F523AB7AAE00B457ED /* ContentAppearanceHandler.swift */; }; - 2BE185F823AB7B2600B457ED /* ContentAppearanceHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE185F723AB7B2600B457ED /* ContentAppearanceHandlerTests.swift */; }; 2BD0FB23232F7ED600BA3894 /* OverlayMenuCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BD0FB21232F7ED600BA3894 /* OverlayMenuCell.swift */; }; 2BD0FB24232F7ED600BA3894 /* OverlayFocusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BD0FB22232F7ED600BA3894 /* OverlayFocusView.swift */; }; + 2BE185F623AB7AAE00B457ED /* ContentAppearanceHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE185F523AB7AAE00B457ED /* ContentAppearanceHandler.swift */; }; + 2BE185F823AB7B2600B457ED /* ContentAppearanceHandlerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE185F723AB7B2600B457ED /* ContentAppearanceHandlerTests.swift */; }; 6EC140C51F0940F40054B514 /* PagingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EC140BB1F0940F40054B514 /* PagingKit.framework */; }; 6EC140CC1F0940F40054B514 /* PagingKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EC140BE1F0940F40054B514 /* PagingKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6EC140D71F09410F0054B514 /* PagingMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EC140D51F09410F0054B514 /* PagingMenuViewController.swift */; }; @@ -28,6 +34,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 2B28FBCA23EFAF99007101B9 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 6EC140B21F0940F40054B514 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 2B28FBB523EFAF90007101B9; + remoteInfo = UnitTestHostApplication; + }; 6EC140C61F0940F40054B514 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 6EC140B21F0940F40054B514 /* Project object */; @@ -39,6 +52,14 @@ /* Begin PBXFileReference section */ 2B283F041FA8A2BD00DA2FE4 /* Array+NSLayoutConstraint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+NSLayoutConstraint.swift"; sourceTree = ""; }; + 2B28FBB623EFAF90007101B9 /* UnitTestHostApplication.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UnitTestHostApplication.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 2B28FBB823EFAF90007101B9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 2B28FBBA23EFAF90007101B9 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 2B28FBBC23EFAF90007101B9 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 2B28FBBF23EFAF90007101B9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 2B28FBC123EFAF93007101B9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 2B28FBC423EFAF93007101B9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 2B28FBC623EFAF93007101B9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 2B463D251F958C0D00F241E1 /* PagingMenuFocusView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PagingMenuFocusView.xib; sourceTree = ""; }; 2B4F03421F8FA0230015FCC8 /* PagingMenuViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingMenuViewControllerTests.swift; sourceTree = ""; }; 2B4F03441F8FA0760015FCC8 /* PagingMenuViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingMenuViewTests.swift; sourceTree = ""; }; @@ -48,10 +69,10 @@ 2BC16A311FFE355F00CB884A /* UnderlineFocusView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnderlineFocusView.swift; sourceTree = ""; }; 2BC16A331FFE35AA00CB884A /* PagingKitProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagingKitProxy.swift; sourceTree = ""; }; 2BC16A351FFE3B3E00CB884A /* TitleLabelMenuViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLabelMenuViewCell.swift; sourceTree = ""; }; - 2BE185F523AB7AAE00B457ED /* ContentAppearanceHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentAppearanceHandler.swift; sourceTree = ""; }; - 2BE185F723AB7B2600B457ED /* ContentAppearanceHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentAppearanceHandlerTests.swift; sourceTree = ""; }; 2BD0FB21232F7ED600BA3894 /* OverlayMenuCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OverlayMenuCell.swift; sourceTree = ""; }; 2BD0FB22232F7ED600BA3894 /* OverlayFocusView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OverlayFocusView.swift; sourceTree = ""; }; + 2BE185F523AB7AAE00B457ED /* ContentAppearanceHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentAppearanceHandler.swift; sourceTree = ""; }; + 2BE185F723AB7B2600B457ED /* ContentAppearanceHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentAppearanceHandlerTests.swift; sourceTree = ""; }; 6EC140BB1F0940F40054B514 /* PagingKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PagingKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6EC140BE1F0940F40054B514 /* PagingKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PagingKit.h; sourceTree = ""; }; 6EC140BF1F0940F40054B514 /* PagingKit-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PagingKit-Info.plist"; sourceTree = ""; }; @@ -62,6 +83,13 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 2B28FBB323EFAF90007101B9 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 6EC140B71F0940F40054B514 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -80,6 +108,20 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 2B28FBB723EFAF90007101B9 /* UnitTestHostApplication */ = { + isa = PBXGroup; + children = ( + 2B28FBB823EFAF90007101B9 /* AppDelegate.swift */, + 2B28FBBA23EFAF90007101B9 /* SceneDelegate.swift */, + 2B28FBBC23EFAF90007101B9 /* ViewController.swift */, + 2B28FBBE23EFAF90007101B9 /* Main.storyboard */, + 2B28FBC123EFAF93007101B9 /* Assets.xcassets */, + 2B28FBC323EFAF93007101B9 /* LaunchScreen.storyboard */, + 2B28FBC623EFAF93007101B9 /* Info.plist */, + ); + path = UnitTestHostApplication; + sourceTree = ""; + }; 2BD0FB25232F82B900BA3894 /* Menu Cells */ = { isa = PBXGroup; children = ( @@ -112,6 +154,7 @@ children = ( 6EC140BD1F0940F40054B514 /* PagingKit */, 6EC140C81F0940F40054B514 /* PagingKitTests */, + 2B28FBB723EFAF90007101B9 /* UnitTestHostApplication */, 6EC140BC1F0940F40054B514 /* Products */, ); sourceTree = ""; @@ -121,6 +164,7 @@ children = ( 6EC140BB1F0940F40054B514 /* PagingKit.framework */, 6EC140C41F0940F40054B514 /* PagingKitTests.xctest */, + 2B28FBB623EFAF90007101B9 /* UnitTestHostApplication.app */, ); name = Products; sourceTree = ""; @@ -169,6 +213,23 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 2B28FBB523EFAF90007101B9 /* UnitTestHostApplication */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2B28FBC923EFAF93007101B9 /* Build configuration list for PBXNativeTarget "UnitTestHostApplication" */; + buildPhases = ( + 2B28FBB223EFAF90007101B9 /* Sources */, + 2B28FBB323EFAF90007101B9 /* Frameworks */, + 2B28FBB423EFAF90007101B9 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = UnitTestHostApplication; + productName = UnitTestHostApplication; + productReference = 2B28FBB623EFAF90007101B9 /* UnitTestHostApplication.app */; + productType = "com.apple.product-type.application"; + }; 6EC140BA1F0940F40054B514 /* PagingKit */ = { isa = PBXNativeTarget; buildConfigurationList = 6EC140CF1F0940F40054B514 /* Build configuration list for PBXNativeTarget "PagingKit" */; @@ -199,6 +260,7 @@ ); dependencies = ( 6EC140C71F0940F40054B514 /* PBXTargetDependency */, + 2B28FBCB23EFAF99007101B9 /* PBXTargetDependency */, ); name = PagingKitTests; productName = PagingKitTests; @@ -211,10 +273,15 @@ 6EC140B21F0940F40054B514 /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0830; + LastSwiftUpdateCheck = 1130; LastUpgradeCheck = 0930; ORGANIZATIONNAME = "Kazuhiro Hayashi"; TargetAttributes = { + 2B28FBB523EFAF90007101B9 = { + CreatedOnToolsVersion = 11.3.1; + DevelopmentTeam = R33Y42SDDR; + ProvisioningStyle = Automatic; + }; 6EC140BA1F0940F40054B514 = { CreatedOnToolsVersion = 8.3.3; LastSwiftMigration = 0900; @@ -224,6 +291,7 @@ CreatedOnToolsVersion = 8.3.3; LastSwiftMigration = 1010; ProvisioningStyle = Automatic; + TestTargetID = 2B28FBB523EFAF90007101B9; }; }; }; @@ -243,11 +311,22 @@ targets = ( 6EC140BA1F0940F40054B514 /* PagingKit */, 6EC140C31F0940F40054B514 /* PagingKitTests */, + 2B28FBB523EFAF90007101B9 /* UnitTestHostApplication */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 2B28FBB423EFAF90007101B9 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2B28FBC523EFAF93007101B9 /* LaunchScreen.storyboard in Resources */, + 2B28FBC223EFAF93007101B9 /* Assets.xcassets in Resources */, + 2B28FBC023EFAF90007101B9 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 6EC140B91F0940F40054B514 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -267,6 +346,16 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 2B28FBB223EFAF90007101B9 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2B28FBBD23EFAF90007101B9 /* ViewController.swift in Sources */, + 2B28FBB923EFAF90007101B9 /* AppDelegate.swift in Sources */, + 2B28FBBB23EFAF90007101B9 /* SceneDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 6EC140B61F0940F40054B514 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -298,6 +387,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 2B28FBCB23EFAF99007101B9 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 2B28FBB523EFAF90007101B9 /* UnitTestHostApplication */; + targetProxy = 2B28FBCA23EFAF99007101B9 /* PBXContainerItemProxy */; + }; 6EC140C71F0940F40054B514 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 6EC140BA1F0940F40054B514 /* PagingKit */; @@ -305,7 +399,69 @@ }; /* End PBXTargetDependency section */ +/* Begin PBXVariantGroup section */ + 2B28FBBE23EFAF90007101B9 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 2B28FBBF23EFAF90007101B9 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 2B28FBC323EFAF93007101B9 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 2B28FBC423EFAF93007101B9 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ + 2B28FBC723EFAF93007101B9 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = R33Y42SDDR; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = UnitTestHostApplication/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.2; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = kazuhiro.hayashi.UnitTestHostApplication; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 2B28FBC823EFAF93007101B9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = R33Y42SDDR; + GCC_C_LANGUAGE_STANDARD = gnu11; + INFOPLIST_FILE = UnitTestHostApplication/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.2; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_FAST_MATH = YES; + PRODUCT_BUNDLE_IDENTIFIER = kazuhiro.hayashi.UnitTestHostApplication; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; 6EC140CD1F0940F40054B514 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -477,6 +633,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = PagingKitTests/Info.plist; @@ -486,6 +643,7 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestHostApplication.app/UnitTestHostApplication"; }; name = Debug; }; @@ -493,6 +651,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = PagingKitTests/Info.plist; @@ -502,12 +661,22 @@ PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_SWIFT3_OBJC_INFERENCE = On; SWIFT_VERSION = 5.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestHostApplication.app/UnitTestHostApplication"; }; name = Release; }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 2B28FBC923EFAF93007101B9 /* Build configuration list for PBXNativeTarget "UnitTestHostApplication" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2B28FBC723EFAF93007101B9 /* Debug */, + 2B28FBC823EFAF93007101B9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 6EC140B51F0940F40054B514 /* Build configuration list for PBXProject "PagingKit" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/UnitTestHostApplication/AppDelegate.swift b/UnitTestHostApplication/AppDelegate.swift new file mode 100644 index 0000000..7951013 --- /dev/null +++ b/UnitTestHostApplication/AppDelegate.swift @@ -0,0 +1,37 @@ +// +// AppDelegate.swift +// UnitTestHostApplication +// +// Created by kahayash on 2/9/2 R. +// Copyright © 2 Reiwa Kazuhiro Hayashi. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/UnitTestHostApplication/Assets.xcassets/AppIcon.appiconset/Contents.json b/UnitTestHostApplication/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/UnitTestHostApplication/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/UnitTestHostApplication/Assets.xcassets/Contents.json b/UnitTestHostApplication/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/UnitTestHostApplication/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/UnitTestHostApplication/Base.lproj/LaunchScreen.storyboard b/UnitTestHostApplication/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/UnitTestHostApplication/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UnitTestHostApplication/Base.lproj/Main.storyboard b/UnitTestHostApplication/Base.lproj/Main.storyboard new file mode 100644 index 0000000..25a7638 --- /dev/null +++ b/UnitTestHostApplication/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UnitTestHostApplication/Info.plist b/UnitTestHostApplication/Info.plist new file mode 100644 index 0000000..2a3483c --- /dev/null +++ b/UnitTestHostApplication/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/UnitTestHostApplication/SceneDelegate.swift b/UnitTestHostApplication/SceneDelegate.swift new file mode 100644 index 0000000..740eb49 --- /dev/null +++ b/UnitTestHostApplication/SceneDelegate.swift @@ -0,0 +1,53 @@ +// +// SceneDelegate.swift +// UnitTestHostApplication +// +// Created by kahayash on 2/9/2 R. +// Copyright © 2 Reiwa Kazuhiro Hayashi. All rights reserved. +// + +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + + var window: UIWindow? + + + func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { + // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. + // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. + // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). + guard let _ = (scene as? UIWindowScene) else { return } + } + + func sceneDidDisconnect(_ scene: UIScene) { + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). + } + + func sceneDidBecomeActive(_ scene: UIScene) { + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + } + + func sceneWillResignActive(_ scene: UIScene) { + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). + } + + func sceneWillEnterForeground(_ scene: UIScene) { + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. + } + + func sceneDidEnterBackground(_ scene: UIScene) { + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. + } + + +} + diff --git a/UnitTestHostApplication/ViewController.swift b/UnitTestHostApplication/ViewController.swift new file mode 100644 index 0000000..8cfc3a5 --- /dev/null +++ b/UnitTestHostApplication/ViewController.swift @@ -0,0 +1,20 @@ +// +// ViewController.swift +// UnitTestHostApplication +// +// Created by kahayash on 2/9/2 R. +// Copyright © 2 Reiwa Kazuhiro Hayashi. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view. + } + + +} + From cdfc0c4f7b26cc79276e5a7ec8842c8abf49a0dc Mon Sep 17 00:00:00 2001 From: Kazuhiro Hayashi Date: Sun, 9 Feb 2020 12:18:23 +0900 Subject: [PATCH 5/6] fix unit test with large width host application --- PagingKitTests/PagingMenuViewControllerTests.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/PagingKitTests/PagingMenuViewControllerTests.swift b/PagingKitTests/PagingMenuViewControllerTests.swift index bc80ea4..c751a73 100644 --- a/PagingKitTests/PagingMenuViewControllerTests.swift +++ b/PagingKitTests/PagingMenuViewControllerTests.swift @@ -145,6 +145,7 @@ class PagingMenuViewControllerTests: XCTestCase { func testHookCompletionHandlerAfterReloadData() { let dataSource = MenuViewControllerDataSourceMock() + dataSource.data = Array(repeating: "foo", count: 1000) let menuViewController = PagingMenuViewControllerTests.makeViewController(with: dataSource) dataSource.registerNib(to: menuViewController) From 742bedd8b7b59e2ecf63d3bb2c8fe5a7b3b05242 Mon Sep 17 00:00:00 2001 From: Kazuhiro Hayashi Date: Sun, 9 Feb 2020 13:21:19 +0900 Subject: [PATCH 6/6] add delegate spy to unit test --- .../PagingContentViewControllerTests.swift | 127 +++++++++++++----- 1 file changed, 93 insertions(+), 34 deletions(-) diff --git a/PagingKitTests/PagingContentViewControllerTests.swift b/PagingKitTests/PagingContentViewControllerTests.swift index 05edd1d..56de043 100644 --- a/PagingKitTests/PagingContentViewControllerTests.swift +++ b/PagingKitTests/PagingContentViewControllerTests.swift @@ -226,40 +226,6 @@ class PagingContentViewControllerTests: XCTestCase { } } -class PagingContentVcDataSourceMock: NSObject, PagingContentViewControllerDataSource { - let numberOfItemExpectation = XCTestExpectation(description: "call numberOfItemsForContentViewController") - let viewControllerExpectation = XCTestExpectation(description: "call viewController") - - func numberOfItemsForContentViewController(viewController: PagingContentViewController) -> Int { - numberOfItemExpectation.fulfill() - return 2 - } - - func contentViewController(viewController: PagingContentViewController, viewControllerAt index: Int) -> UIViewController { - viewControllerExpectation.fulfill() - return UIViewController() - } -} - -class PagingContentVcDataSourceSpy: NSObject, PagingContentViewControllerDataSource { - init(count: Int = 5) { - vcs = Array(repeating: UIViewController(), count: count) - super.init() - } - - let vcs: [UIViewController] - - func numberOfItemsForContentViewController(viewController: PagingContentViewController) -> Int { - return vcs.count - } - - func contentViewController(viewController: PagingContentViewController, viewControllerAt index: Int) -> UIViewController { - let vc = vcs[index] - vc.view.frame = CGRect(x: 0, y: 0, width: 1, height: 1) - return vc - } -} - // MARK:- Appearance extension PagingContentViewControllerTests { func test_Appear_callApparance() { @@ -369,10 +335,103 @@ extension PagingContentViewControllerTests { wait(for: [expectation], timeout: 0.2) } + + func test_UpdaingViewControllerSize_notCallApparance() { + let expectation = XCTestExpectation(description: "finish reloadData") + + XCUIDevice.shared.orientation = .portrait + + let dataSource = PagingContentVcDataSourceSpy() + let delegate = PagingContentVcDelegateSpy() + self.pagingContentViewController?.dataSource = dataSource + self.pagingContentViewController?.delegate = delegate + + UIApplication.shared.keyWindow?.rootViewController = self.pagingContentViewController + + XCTAssertNil(delegate.willBeginPagingAt_args) + XCTAssertNil(self.contentAppearanceHandler.beginDragging_args) + XCTAssertNil(self.contentAppearanceHandler.stopScrolling_args) + + XCUIDevice.shared.orientation = .landscapeLeft + + XCTAssertNotNil(delegate.willBeginPagingAt_args) + XCTAssertNil(self.contentAppearanceHandler.beginDragging_args) + XCTAssertNil(self.contentAppearanceHandler.stopScrolling_args) + expectation.fulfill() + + wait(for: [expectation], timeout: 1) + } } // MARK:- Test Double +class PagingContentVcDataSourceMock: NSObject, PagingContentViewControllerDataSource { + let numberOfItemExpectation = XCTestExpectation(description: "call numberOfItemsForContentViewController") + let viewControllerExpectation = XCTestExpectation(description: "call viewController") + + func numberOfItemsForContentViewController(viewController: PagingContentViewController) -> Int { + numberOfItemExpectation.fulfill() + return 2 + } + + func contentViewController(viewController: PagingContentViewController, viewControllerAt index: Int) -> UIViewController { + viewControllerExpectation.fulfill() + return UIViewController() + } +} + +class PagingContentVcDataSourceSpy: NSObject, PagingContentViewControllerDataSource { + init(count: Int = 5) { + vcs = Array(repeating: UIViewController(), count: count) + super.init() + } + + let vcs: [UIViewController] + + func numberOfItemsForContentViewController(viewController: PagingContentViewController) -> Int { + return vcs.count + } + + func contentViewController(viewController: PagingContentViewController, viewControllerAt index: Int) -> UIViewController { + let vc = vcs[index] + vc.view.frame = CGRect(x: 0, y: 0, width: 1, height: 1) + return vc + } +} + +class PagingContentVcDelegateSpy: NSObject, PagingContentViewControllerDelegate { + + var willBeginManualScrollOn_args: (PagingContentViewController, Int)? + func contentViewController(viewController: PagingContentViewController, willBeginManualScrollOn index: Int) { + willBeginManualScrollOn_args = (viewController, index) + } + + var didManualScrollOn_args: (PagingContentViewController, Int, CGFloat)? + func contentViewController(viewController: PagingContentViewController, didManualScrollOn index: Int, percent: CGFloat) { + didManualScrollOn_args = (viewController, index, percent) + } + + var didEndManualScrollOn_args: (PagingContentViewController, Int)? + func contentViewController(viewController: PagingContentViewController, didEndManualScrollOn index: Int) { + didEndManualScrollOn_args = (viewController, index) + } + + var willBeginPagingAt_args: (PagingContentViewController, Int, Bool)? + func contentViewController(viewController: PagingContentViewController, willBeginPagingAt index: Int, animated: Bool) { + willBeginPagingAt_args = (viewController, index, animated) + } + + var willFinishPagingAt_args: (PagingContentViewController, Int, Bool)? + func contentViewController(viewController: PagingContentViewController, willFinishPagingAt index: Int, animated: Bool) { + willFinishPagingAt_args = (viewController, index, animated) + } + + var didFinishPagingAt_args: (PagingContentViewController, Int, Bool)? + func contentViewController(viewController: PagingContentViewController, didFinishPagingAt index: Int, animated: Bool) { + didFinishPagingAt_args = (viewController, index, animated) + } +} + class ContentsAppearanceHandlerSpy: ContentsAppearanceHandlerProtocol { var contentsDequeueHandler: (() -> [UIViewController?]?)?