Skip to content

Commit

Permalink
RUM-4149 [SR] Add suport for UIProgressView
Browse files Browse the repository at this point in the history
  • Loading branch information
mariedm committed Jun 24, 2024
1 parent 85f4abe commit 5b74591
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum Fixture: CaseIterable {
case basicShapes
case basicTexts
case sliders
case progressViews
case segments
case pickers
case switches
Expand Down Expand Up @@ -54,6 +55,8 @@ public enum Fixture: CaseIterable {
return UIStoryboard.basic.instantiateViewController(withIdentifier: "Texts")
case .sliders:
return UIStoryboard.inputElements.instantiateViewController(withIdentifier: "Sliders")
case .progressViews:
return UIStoryboard.inputElements.instantiateViewController(withIdentifier: "ProgressViews")
case .segments:
return UIStoryboard.inputElements.instantiateViewController(withIdentifier: "Segments")
case .pickers:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
Expand Down Expand Up @@ -544,6 +543,96 @@
</objects>
<point key="canvasLocation" x="1063" y="675"/>
</scene>
<!--View Controller-->
<scene sceneID="hPi-MX-LhE">
<objects>
<viewController storyboardIdentifier="ProgressViews" id="lfg-1k-4io" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="kks-t0-Aqv">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="tiN-zd-FNP">
<rect key="frame" x="8" y="67" width="377" height="234"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Default" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Amm-9k-Fl9">
<rect key="frame" x="0.0" y="0.0" width="377" height="20.333333333333332"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.20000000000000001" translatesAutoresizingMaskIntoConstraints="NO" id="tCM-vy-hbO">
<rect key="frame" x="0.0" y="28.333333333333329" width="377" height="4"/>
</progressView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Background Color" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YAG-id-IUj">
<rect key="frame" x="0.0" y="40.333333333333329" width="377" height="20.333333333333329"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.29999999999999999" translatesAutoresizingMaskIntoConstraints="NO" id="pjd-Wx-7yX">
<rect key="frame" x="0.0" y="68.666666666666657" width="377" height="4"/>
<color key="backgroundColor" systemColor="systemYellowColor"/>
</progressView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Track Tint Colors" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gus-fU-u9U">
<rect key="frame" x="0.0" y="80.666666666666657" width="377" height="20.333333333333329"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.40000000000000002" translatesAutoresizingMaskIntoConstraints="NO" id="rdj-4K-LCI">
<rect key="frame" x="0.0" y="109" width="377" height="4"/>
<color key="progressTintColor" systemColor="systemPurpleColor"/>
<color key="trackTintColor" systemColor="systemTealColor"/>
</progressView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Track Tint Color + BG Color" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Rrs-qe-9Fi" userLabel="Track Tint Color + BG Color">
<rect key="frame" x="0.0" y="120.99999999999999" width="377" height="20.333333333333329"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="8so-YS-eiK">
<rect key="frame" x="0.0" y="149.33333333333334" width="377" height="4"/>
<color key="backgroundColor" systemColor="systemPinkColor"/>
<color key="progressTintColor" systemColor="systemPurpleColor"/>
<color key="trackTintColor" systemColor="systemTealColor"/>
</progressView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Tint Color" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sjd-ql-vEv">
<rect key="frame" x="0.0" y="161.33333333333334" width="377" height="20.333333333333343"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.59999999999999998" translatesAutoresizingMaskIntoConstraints="NO" id="f6I-ad-KS1">
<rect key="frame" x="0.0" y="189.66666666666669" width="377" height="4"/>
<color key="tintColor" systemColor="systemIndigoColor"/>
</progressView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Bar Style" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UKy-aQ-Cig">
<rect key="frame" x="0.0" y="201.66666666666669" width="377" height="20.333333333333343"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.69999999999999996" translatesAutoresizingMaskIntoConstraints="NO" id="Lpo-Q4-bIn">
<rect key="frame" x="0.0" y="230" width="377" height="4"/>
<color key="progressTintColor" systemColor="systemMintColor"/>
<color key="trackTintColor" name="BAD7E9"/>
</progressView>
</subviews>
</stackView>
</subviews>
<viewLayoutGuide key="safeArea" id="uNP-eI-CPR"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="tiN-zd-FNP" firstAttribute="leading" secondItem="uNP-eI-CPR" secondAttribute="leading" constant="8" id="VqG-cQ-W84"/>
<constraint firstItem="uNP-eI-CPR" firstAttribute="trailing" secondItem="tiN-zd-FNP" secondAttribute="trailing" constant="8" id="Yym-y4-ndQ"/>
<constraint firstItem="tiN-zd-FNP" firstAttribute="top" secondItem="uNP-eI-CPR" secondAttribute="top" constant="8" id="idz-Y9-9pd"/>
</constraints>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="sgf-DX-5I4" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1897" y="682"/>
</scene>
</scenes>
<resources>
<image name="cloud.fill" catalog="system" width="128" height="87"/>
Expand All @@ -561,6 +650,12 @@
<systemColor name="systemGreenColor">
<color red="0.20392156862745098" green="0.7803921568627451" blue="0.34901960784313724" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemIndigoColor">
<color red="0.34509803921568627" green="0.33725490196078434" blue="0.83921568627450982" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemMintColor">
<color red="0.0" green="0.7803921568627451" blue="0.74509803921568629" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemOrangeColor">
<color red="1" green="0.58431372549019611" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
Expand All @@ -570,6 +665,9 @@
<systemColor name="systemPurpleColor">
<color red="0.68627450980392157" green="0.32156862745098042" blue="0.87058823529411766" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemTealColor">
<color red="0.18823529411764706" green="0.69019607843137254" blue="0.7803921568627451" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemYellowColor">
<color red="1" green="0.80000000000000004" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal extension Fixture {
return "Basic Texts"
case .sliders:
return "Sliders"
case .progressViews:
return "Progress Views"
case .segments:
return "Segments"
case .pickers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ final class SRSnapshotTests: SnapshotTestCase {
}
}

func testProgressViews() throws {
show(fixture: .progressViews)

try forPrivacyModes([.allow, .mask]) { privacyMode in
let image = try takeSnapshot(with: privacyMode)
DDAssertSnapshotTest(
newImage: image,
snapshotLocation: .folder(named: snapshotsFolderPath, fileNameSuffix: "-\(privacyMode)-privacy"),
record: recordingMode
)
}
}

func testSegments() throws {
show(fixture: .segments)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"b9d1161cdce6da4d4d314ba64300feaf84dcf6c3"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"hash":"b7ede114b25c7c4bf5fcb8e9434652a097ee8989"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2019-Present Datadog, Inc.
*/

#if os(iOS)
import UIKit

internal struct UIProgressViewRecorder: NodeRecorder {
let identifier = UUID()

func semantics(of view: UIView, with attributes: ViewAttributes, in context: ViewTreeRecordingContext) -> NodeSemantics? {
guard let progressView = view as? UIProgressView else {
return nil
}

guard attributes.isVisible else {
return InvisibleElement.constant
}

let ids = context.ids.nodeIDs(2, view: progressView, nodeRecorder: self)

let builder = UIProgressViewWireframesBuilder(
wireframeRect: attributes.frame,
attributes: attributes,
backgroundWireframeID: ids[0],
progressTrackWireframeID: ids[1],
progress: progressView.progress,
progressTintColor: progressView.progressTintColor?.cgColor ?? progressView.tintColor.cgColor,
backgroundColor: progressView.trackTintColor?.cgColor ?? progressView.backgroundColor?.cgColor
)
let node = Node(viewAttributes: attributes, wireframesBuilder: builder)
return SpecificElement(subtreeStrategy: .ignore, nodes: [node])
}
}

internal struct UIProgressViewWireframesBuilder: NodeWireframesBuilder {
var wireframeRect: CGRect
let attributes: ViewAttributes

let backgroundWireframeID: WireframeID
let progressTrackWireframeID: WireframeID
let progress: Float
let progressTintColor: CGColor
let backgroundColor: CGColor?

func buildWireframes(with builder: WireframesBuilder) -> [SRWireframe] {
guard progress >= 0 && progress <= 1 else {
return [] // illegal, should not happen
}

let background = builder.createShapeWireframe(
id: backgroundWireframeID,
frame: wireframeRect,
backgroundColor: backgroundColor ?? SystemColors.tertiarySystemFill,
cornerRadius: wireframeRect.height/2
)

// Create progress wireframe
let (progressRect, _) = wireframeRect
.divided(atDistance: CGFloat(progress) * wireframeRect.width, from: .minXEdge)
let progressTrackFrame = progressRect.putInside(wireframeRect, horizontalAlignment: .left, verticalAlignment: .middle)

let progressTrack = builder.createShapeWireframe(
id: progressTrackWireframeID,
frame: progressTrackFrame,
borderColor: nil,
borderWidth: nil,
backgroundColor: progressTintColor,
cornerRadius: wireframeRect.height/2,
opacity: attributes.alpha
)

return [background, progressTrack]
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ internal struct UnsupportedViewRecorder: NodeRecorder {
{ _, context in context.viewControllerContext.isRootView(of: .safari) },
{ _, context in context.viewControllerContext.isRootView(of: .activity) },
{ _, context in context.viewControllerContext.isRootView(of: .swiftUI) },
{ view, _ in view is UIProgressView },
{ view, _ in view is UIActivityIndicatorView }
]
// swiftlint:enable opening_brace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ internal func createDefaultNodeRecorders() -> [NodeRecorder] {
UITabBarRecorder(),
UIPickerViewRecorder(),
UIDatePickerRecorder(),
WKWebViewRecorder()
WKWebViewRecorder(),
UIProgressViewRecorder()
]
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class UnsupportedViewRecorderTests: XCTestCase {
private let recorder = UnsupportedViewRecorder()

private let unsupportedViews: [UIView] = [
UIProgressView(), UIActivityIndicatorView()
UIActivityIndicatorView()
].compactMap { $0 }
private let expectedUnsupportedViewsClassNames = [
"UIProgressView", "UIActivityIndicatorView", "WKWebView"
"UIActivityIndicatorView", "WKWebView"
]
private let otherViews = [UILabel(), UIView(), UIImageView(), UIScrollView(), WKWebView()]

Expand Down

0 comments on commit 5b74591

Please sign in to comment.