Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Fix reloading issue when performing batch updates #205

Merged
merged 2 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Family.podspec
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
33 changes: 15 additions & 18 deletions Sources/iOS+tvOS/Classes/FamilyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,6 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
CATransaction.begin()
CATransaction.setAnimationDuration(0.0)
CATransaction.setDisableActions(true)
defer {
CATransaction.commit()
}
}

scrollView.isPerformingBatchUpdates = true
Expand All @@ -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
Expand Down Expand Up @@ -494,8 +495,6 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
registry.removeValue(forKey: controller)
}

scrollView.purgeWrapperViews()

return self
}

Expand All @@ -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)
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/iOS+tvOS/FamilyViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class FamilyViewControllerTests: XCTestCase {
familyViewController.prepareViewController()
}

override func tearDown() {
super.tearDown()
familyViewController = nil
}

func testAddingChildViewController() {
let viewController = UIViewController()
familyViewController.addChild(viewController)
Expand Down Expand Up @@ -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)
Expand Down