-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RUM-4149 [SR] Add suport for UIProgressView
- Loading branch information
Showing
10 changed files
with
203 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...shotTests/SRSnapshotTests/_snapshots_/pointers/testProgressViews()-allow-privacy.png.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"hash":"b9d1161cdce6da4d4d314ba64300feaf84dcf6c3"} |
1 change: 1 addition & 0 deletions
1
...pshotTests/SRSnapshotTests/_snapshots_/pointers/testProgressViews()-mask-privacy.png.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"hash":"b7ede114b25c7c4bf5fcb8e9434652a097ee8989"} |
78 changes: 78 additions & 0 deletions
78
...rder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIProgressViewRecorder.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters