Skip to content

Commit

Permalink
walk view hierarchy, get view identifier used by storybook for each view
Browse files Browse the repository at this point in the history
  • Loading branch information
MustafaHaddara committed Dec 4, 2024
1 parent 578cbab commit 1f31d5e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
12 changes: 6 additions & 6 deletions Examples/SmokeTest/SmokeTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
452B71DD2CE52C8600C27FB2 /* ViewInstrumentationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 452B71DC2CE52C8600C27FB2 /* ViewInstrumentationView.swift */; };
366309102CE51BDC00B97612 /* UIKitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3663090F2CE51BDC00B97612 /* UIKitView.swift */; };
366309122CE51EF000B97612 /* UIKitView.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 366309112CE51EF000B97612 /* UIKitView.storyboard */; };
366309122CE51EF000B97612 /* UIKitViewStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 366309112CE51EF000B97612 /* UIKitViewStoryboard.storyboard */; };
452B71DD2CE52C8600C27FB2 /* ViewInstrumentationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 452B71DC2CE52C8600C27FB2 /* ViewInstrumentationView.swift */; };
452B71E12CE6A52600C27FB2 /* NavigationExamplesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 452B71E02CE6A52600C27FB2 /* NavigationExamplesView.swift */; };
AF6DEFEA2C8D3CE000363027 /* SmokeTestApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF6DEFE92C8D3CE000363027 /* SmokeTestApp.swift */; };
AF6DEFEC2C8D3CE000363027 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF6DEFEB2C8D3CE000363027 /* ContentView.swift */; };
Expand Down Expand Up @@ -41,9 +41,9 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
452B71DC2CE52C8600C27FB2 /* ViewInstrumentationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewInstrumentationView.swift; sourceTree = "<group>"; };
3663090F2CE51BDC00B97612 /* UIKitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitView.swift; sourceTree = "<group>"; };
366309112CE51EF000B97612 /* UIKitView.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = UIKitView.storyboard; sourceTree = "<group>"; };
366309112CE51EF000B97612 /* UIKitViewStoryboard.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = UIKitViewStoryboard.storyboard; sourceTree = "<group>"; };
452B71DC2CE52C8600C27FB2 /* ViewInstrumentationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewInstrumentationView.swift; sourceTree = "<group>"; };
452B71E02CE6A52600C27FB2 /* NavigationExamplesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationExamplesView.swift; sourceTree = "<group>"; };
AF6DEFE62C8D3CE000363027 /* SmokeTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SmokeTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
AF6DEFE92C8D3CE000363027 /* SmokeTestApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmokeTestApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -118,7 +118,7 @@
AF6DEFED2C8D3CE100363027 /* Assets.xcassets */,
AF6DEFEF2C8D3CE100363027 /* Preview Content */,
3663090F2CE51BDC00B97612 /* UIKitView.swift */,
366309112CE51EF000B97612 /* UIKitView.storyboard */,
366309112CE51EF000B97612 /* UIKitViewStoryboard.storyboard */,
);
path = SmokeTest;
sourceTree = "<group>";
Expand Down Expand Up @@ -263,7 +263,7 @@
buildActionMask = 2147483647;
files = (
AF6DEFF12C8D3CE100363027 /* Preview Assets.xcassets in Resources */,
366309122CE51EF000B97612 /* UIKitView.storyboard in Resources */,
366309122CE51EF000B97612 /* UIKitViewStoryboard.storyboard in Resources */,
AF6DEFEE2C8D3CE100363027 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
4 changes: 2 additions & 2 deletions Examples/SmokeTest/SmokeTest/UIKitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ struct UIKView_preview: PreviewProvider {

struct StoryboardViewControllerRepresentation: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> some UIViewController {
let storyboard = UIStoryboard(name: "UIKitView", bundle: Bundle.main)
let controller = storyboard.instantiateViewController(identifier: "UIKitView")
let storyboard = UIStoryboard(name: "UIKitViewStoryboard", bundle: Bundle.main)
let controller = storyboard.instantiateViewController(identifier: "UIKitView123")
return controller
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!--View Controller-->
<scene sceneID="s0d-6b-0kx">
<objects>
<viewController storyboardIdentifier="UIKitView" id="Y6W-OH-hqX" customClass="ViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="UIKitView123" id="Y6W-OH-hqX" customClass="ViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
31 changes: 22 additions & 9 deletions Sources/Honeycomb/UIKit/UIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@
import UIKit

extension UIViewController {
var storyboardId: String? {
return value(forKey: "storyboardIdentifier") as? String
}

private func viewStack() -> [String] {
let selfPath = self.storyboardId ?? NSStringFromClass(type(of: self))
if var parentPath = self.parent?.viewStack() {
parentPath.append(selfPath)
return parentPath
}
return [selfPath]
}

private func viewPath() -> String {
self.viewStack()
.filter { str in
!str.starts(with: ("_"))
}
.joined(separator: "/")
}

private func setAttributes(span: Span, className: String, animated: Bool) {
if let title = self.title {
span.setAttribute(key: "view.title", value: title)
Expand All @@ -24,20 +45,12 @@
setAttributes(span: span, className: className, animated: animated)
span.end()

HoneycombNavigationProcessor.shared.setCurrentNavigationPath(getScreenName())
HoneycombNavigationProcessor.shared.setCurrentNavigationPath(viewPath())
}

traceViewDidAppear(animated)
}

private func getScreenName() -> String {
var name = NSStringFromClass(type(of: self))
if let title = self.title {
name += " (\(title))"
}
return name
}

@objc func traceViewDidDisappear(_ animated: Bool) {

let className = NSStringFromClass(type(of: self))
Expand Down

0 comments on commit 1f31d5e

Please sign in to comment.