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

Commit

Permalink
Only invoke signposting when it is set to be enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
zenangst committed Jan 25, 2021
1 parent c278f00 commit c77caa4
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 71 deletions.
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.2.1"
s.version = "2.2.2"
s.homepage = "https://github.com/zenangst/Family"
s.license = 'MIT'
s.author = { "Christoffer Winterkvist" => "christoffer@winterkvist.com" }
Expand Down
79 changes: 47 additions & 32 deletions Sources/UIKit/FamilyScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,11 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
}
}

let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

if backgrounds.values.contains(view) {
super.addSubview(view)
Expand Down Expand Up @@ -211,9 +213,11 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
}
}

let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

if backgrounds.values.contains(view) {
super.addSubview(view)
Expand Down Expand Up @@ -251,9 +255,12 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
}

private func addSubviewsInLayoutOrder() {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

for (index, view) in subviewsInLayoutOrder.reversed().enumerated() {
super.insertSubview(view, at: index)
}
Expand Down Expand Up @@ -284,9 +291,12 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
/// - Parameter scrollView: The scroll view that should be configured
/// and observed.
func didAddScrollViewToContainer(_ scrollView: UIScrollView) {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

scrollView.autoresizingMask = [.flexibleWidth]

guard subviewsInLayoutOrder.contains(scrollView) else {
Expand All @@ -301,9 +311,11 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
///
/// - Parameter subview: The subview that got removed from the view heirarcy.
open override func willRemoveSubview(_ subview: UIView) {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

if subview.isSystemView {
isFastScrolling = false
Expand Down Expand Up @@ -380,9 +392,11 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
}

func adjustContentSize(for view: UIView, scrollView: UIScrollView, withAnimation animation: CAAnimation?) {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

guard let entry = cache.entry(for: view) else { return }
let validAttributes = getValidAttributes(in: discardableRect)
Expand Down Expand Up @@ -442,9 +456,11 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
///
/// - Parameter view: The view that should be observered.
private func observeView(view: UIScrollView) {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

observers.filter({ $0.view === view }).forEach({
observers.remove($0)
Expand Down Expand Up @@ -568,9 +584,11 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
func purgeWrapperViews() {
if isPerformingBatchUpdates { return }

let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

for case let wrapperView as FamilyWrapperView in subviews {
if wrapperView != wrapperView.view.superview {
Expand Down Expand Up @@ -745,9 +763,11 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
/// when a view changes size or origin. It also scales the frame of scroll views
/// in order to keep dequeuing for table and collection views.
internal func runLayoutSubviewsAlgorithm() {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self), signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

guard cache.state != .isRunning else { return }

Expand All @@ -756,10 +776,6 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
var newContentSize: CGSize = .zero

if cache.state == .empty {
let log = OSSignpostController(category: String(describing: FamilyScrollView.self),
name: "runLayoutSubviewsAlgorithm.caching",
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, "runLayoutSubviewsAlgorithm.caching")
cache.state = .isRunning
var yOffsetOfCurrentSubview: CGFloat = 0.0
for scrollView in subviewsInLayoutOrder where scrollView.isHidden == false {
Expand Down Expand Up @@ -838,7 +854,6 @@ public class FamilyScrollView: UIScrollView, UIGestureRecognizerDelegate {
}

newContentSize = CGSize(width: cache.contentSize.width, height: round(height))
log.signpost(.end, "runLayoutSubviewsAlgorithm.caching")
}

if cache.state == .isRunning {
Expand Down
96 changes: 58 additions & 38 deletions Sources/UIKit/FamilyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,12 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
///
/// - Parameter childController: The view controller to be added as a child.
open override func addChild(_ childController: UIViewController) {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

if childController.parent != nil {
childController.removeFromParent()
Expand Down Expand Up @@ -220,10 +222,12 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
insets: Insets? = nil,
height: CGFloat? = nil,
view handler: ((T) -> UIView)? = nil) -> Self {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

purgeRemovedViews()
childController.willMove(toParent: self)
Expand Down Expand Up @@ -282,10 +286,12 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
at index: Int? = nil,
insets: Insets? = nil,
height: CGFloat? = nil) -> Self {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

var newWidth = view.bounds.size.width

Expand Down Expand Up @@ -320,10 +326,12 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
///
/// - Returns: A collection of view controllers.
public func viewControllersInLayoutOrder() -> [ViewController] {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

if !_viewControllersInLayoutOrder.isEmpty {
return _viewControllersInLayoutOrder
Expand Down Expand Up @@ -397,18 +405,24 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
animation: CAAnimation? = nil,
_ handler: (FamilyViewController) -> Void,
completion: ((FamilyViewController, Bool) -> Void)? = nil) -> Self {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

scrollView.isPerformingBatchUpdates = true
let handlerLog = OSSignpostController(category: String(describing: FamilyViewController.self),
name: "performBatchupdates.handler",
signpostsEnabled: Self.signpostsEnabled)
handlerLog.signpost(.begin, "performBatchupdates.handler")
handler(self)
handlerLog.signpost(.end, "performBatchupdates.handler")
if Self.signpostsEnabled {
let handlerLog = OSSignpostController(category: String(describing: FamilyViewController.self),
name: "performBatchupdates.handler",
signpostsEnabled: Self.signpostsEnabled)
handlerLog.signpost(.begin, "performBatchupdates.handler")
handler(self)
handlerLog.signpost(.end, "performBatchupdates.handler")
} else {
handler(self)
}

_viewControllersInLayoutOrder = []
scrollView.isPerformingBatchUpdates = false
Expand Down Expand Up @@ -475,10 +489,12 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
public func purgeRemovedViews() -> Self {
if scrollView.isPerformingBatchUpdates { return self }

let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

for (controller, container) in registry where controller.parent == nil {
_removeChild(controller)
Expand Down Expand Up @@ -542,10 +558,12 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
/// on if an index is provided.
/// - index: An optional index for where the view should appear.
private func addOrInsertView(_ view: UIView, at index: Int? = nil) {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

if let index = index, index < scrollView.subviews.count {
scrollView.insertSubview(view, at: index)
Expand All @@ -567,10 +585,12 @@ open class FamilyViewController: UIViewController, FamilyFriendly {
/// - Returns: A view that matches the criteria depending on the
/// view controllers type.
private func viewToAdd(from childController: UIViewController) -> View {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
if Self.signpostsEnabled {
let log = OSSignpostController(category: String(describing: FamilyViewController.self),
signpostsEnabled: Self.signpostsEnabled)
log.signpost(.begin, #function)
defer { log.signpost(.end, #function) }
}

let view: UIView

Expand Down

0 comments on commit c77caa4

Please sign in to comment.