diff --git a/Family.podspec b/Family.podspec index d67ec7a..d6e29ce 100644 --- a/Family.podspec +++ b/Family.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "Family" s.summary = "A child view controller framework that makes setting up your parent controllers as easy as pie." - s.version = "2.1.1" + s.version = "2.1.2" s.homepage = "https://github.com/zenangst/Family" s.license = 'MIT' s.author = { "Christoffer Winterkvist" => "christoffer@winterkvist.com" } diff --git a/Sources/iOS+tvOS/Classes/FamilyViewController.swift b/Sources/iOS+tvOS/Classes/FamilyViewController.swift index 6c40e20..878ebc9 100644 --- a/Sources/iOS+tvOS/Classes/FamilyViewController.swift +++ b/Sources/iOS+tvOS/Classes/FamilyViewController.swift @@ -405,9 +405,6 @@ open class FamilyViewController: UIViewController, FamilyFriendly { CATransaction.begin() CATransaction.setAnimationDuration(0.0) CATransaction.setDisableActions(true) - defer { - CATransaction.commit() - } } scrollView.isPerformingBatchUpdates = true @@ -420,15 +417,19 @@ open class FamilyViewController: UIViewController, FamilyFriendly { _viewControllersInLayoutOrder = [] scrollView.isPerformingBatchUpdates = false - purgeRemovedViews() if duration == 0 { - scrollView.setNeedsLayout() - completion?(self, true) + scrollView.setNeedsLayout() + scrollView.layoutIfNeeded() + completion?(self, true) + CATransaction.commit() } else { - scrollView.layoutViews(withDuration: duration, animation: animation) { completed in + scrollView.layoutViews( + withDuration: duration, + animation: animation, + completion: { completed in completion?(self, completed) - } + }) } return self @@ -494,8 +495,6 @@ open class FamilyViewController: UIViewController, FamilyFriendly { registry.removeValue(forKey: controller) } - scrollView.purgeWrapperViews() - return self } @@ -522,14 +521,12 @@ open class FamilyViewController: UIViewController, FamilyFriendly { scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor) ]) } else { - if #available(iOS 9.0, *) { - constraints.append(contentsOf: [ - scrollView.topAnchor.constraint(equalTo: topLayoutGuide.topAnchor), - scrollView.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor), - scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), - scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor) - ]) - } + constraints.append(contentsOf: [ + scrollView.topAnchor.constraint(equalTo: topLayoutGuide.topAnchor), + scrollView.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor), + scrollView.leadingAnchor.constraint(equalTo: view.leadingAnchor), + scrollView.trailingAnchor.constraint(equalTo: view.trailingAnchor) + ]) } NSLayoutConstraint.activate(constraints) } diff --git a/Tests/iOS+tvOS/FamilyViewControllerTests.swift b/Tests/iOS+tvOS/FamilyViewControllerTests.swift index b111641..c97c9a2 100644 --- a/Tests/iOS+tvOS/FamilyViewControllerTests.swift +++ b/Tests/iOS+tvOS/FamilyViewControllerTests.swift @@ -27,6 +27,11 @@ class FamilyViewControllerTests: XCTestCase { familyViewController.prepareViewController() } + override func tearDown() { + super.tearDown() + familyViewController = nil + } + func testAddingChildViewController() { let viewController = UIViewController() familyViewController.addChild(viewController) @@ -103,6 +108,15 @@ class FamilyViewControllerTests: XCTestCase { XCTAssertTrue(familyViewController.children.isEmpty) } + func testRemovingChildViewControllersWithPatchUpdating() { + let viewController = UIViewController() + familyViewController.addChild(viewController) + familyViewController.performBatchUpdates({ _ in + viewController.removeFromParent() + }, completion: { _, _ in }) + XCTAssertTrue(familyViewController.children.isEmpty) + } + func testFamilyControllerWithTabBar() { let tabBarController = UITabBarController() tabBarController.setViewControllers([familyViewController], animated: false)