Skip to content

Commit

Permalink
Merge pull request #112 from kazuhiro4949/feature/lifecycle
Browse files Browse the repository at this point in the history
split screen support
  • Loading branch information
kazuhiro4949 authored Feb 9, 2020
2 parents c05a112 + 742bedd commit 5b941bb
Show file tree
Hide file tree
Showing 12 changed files with 596 additions and 40 deletions.
179 changes: 174 additions & 5 deletions PagingKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion PagingKit/PagingContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public class PagingContentViewController: UIViewController {
override public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animate(alongsideTransition: { [weak self] (context) in
guard let _self = self else { return }
_self.scroll(to: _self.leftSidePageIndex, animated: false)
_self.scroll(to: _self.leftSidePageIndex, needsCallAppearance: false, animated: false)
}, completion: nil)

super.viewWillTransition(to: size, with: coordinator)
Expand Down
127 changes: 93 additions & 34 deletions PagingKitTests/PagingContentViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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?]?)?

Expand Down
1 change: 1 addition & 0 deletions PagingKitTests/PagingMenuViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
37 changes: 37 additions & 0 deletions UnitTestHostApplication/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -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<UISceneSession>) {
// 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.
}


}

Original file line number Diff line number Diff line change
@@ -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"
}
}
6 changes: 6 additions & 0 deletions UnitTestHostApplication/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
25 changes: 25 additions & 0 deletions UnitTestHostApplication/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
24 changes: 24 additions & 0 deletions UnitTestHostApplication/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
Loading

0 comments on commit 5b941bb

Please sign in to comment.