Skip to content

Commit

Permalink
Added layoutMode to BlueprintViewRenderMetrics to expose which la…
Browse files Browse the repository at this point in the history
…yout mode was used to render a Blueprint view. (square#452)
  • Loading branch information
robmaceachern authored Apr 14, 2023
1 parent 5dfe4b9 commit 75763cc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions BlueprintUI/Sources/BlueprintView/BlueprintView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public final class BlueprintView: UIView {
metricsDelegate?.blueprintView(
self,
completedRenderWith: .init(
layoutMode: layoutMode,
totalDuration: viewUpdateEndTime - startTime,
layoutDuration: layoutEndTime - startTime,
viewUpdateDuration: viewUpdateEndTime - layoutEndTime
Expand Down Expand Up @@ -530,10 +531,15 @@ public protocol BlueprintViewMetricsDelegate: AnyObject {

public struct BlueprintViewRenderMetrics {

/// The layout mode used to render the view.
public var layoutMode: LayoutMode

/// The total time it took to apply a new element.
public var totalDuration: TimeInterval

/// The time it took to lay out and measure the new element.
public var layoutDuration: TimeInterval

/// The time it took to update the on-screen views for the element.
public var viewUpdateDuration: TimeInterval
}
Expand Down
10 changes: 10 additions & 0 deletions BlueprintUI/Sources/Layout/LayoutMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public enum LayoutMode: Equatable {
/// A newer layout system with some optimizations made possible by ensuring elements adhere
/// to a certain contract for behavior.
public static let caffeinated = Self.caffeinated()

/// The name of the layout mode.
public var name: String {
switch self {
case .legacy:
return "Legacy"
case .caffeinated:
return "Caffeinated"
}
}
}

extension LayoutMode: CustomStringConvertible {
Expand Down
12 changes: 12 additions & 0 deletions BlueprintUI/Tests/LayoutModeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import XCTest
@testable import BlueprintUI

class LayoutModeTests: XCTestCase {

func testName() {
// These names may end up being propagated as analytics properties,
// so be aware that renaming them can impact existing queries/reports.
XCTAssertEqual(LayoutMode.caffeinated.name, "Caffeinated")
XCTAssertEqual(LayoutMode.legacy.name, "Legacy")
}
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `layoutMode` to `BlueprintViewRenderMetrics` to expose which layout mode was used to render a Blueprint view.

### Removed

### Changed
Expand Down

0 comments on commit 75763cc

Please sign in to comment.