-
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-7176 Record SwiftUI raster images
- Loading branch information
Showing
13 changed files
with
385 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
23 changes: 23 additions & 0 deletions
23
DatadogSessionReplay/Sources/Recorder/Utilities/CGImage+SessionReplay.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,23 @@ | ||
/* | ||
* 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 CoreGraphics | ||
|
||
/// Same heuristic as Android to determine if an image is likely bundled: | ||
/// Icons and small assets usually have dimensions <= 100 points. | ||
internal extension CGImage { | ||
func isLikelyBundled(scale: CGFloat) -> Bool { | ||
let renderedSize = self.renderedSize(scale: scale) | ||
let maxDimension: CGFloat = 100 | ||
return renderedSize.width <= maxDimension && renderedSize.height <= maxDimension | ||
} | ||
|
||
fileprivate func renderedSize(scale: CGFloat) -> CGSize { | ||
return CGSize(width: CGFloat(width) / scale, height: CGFloat(height) / scale) | ||
} | ||
} | ||
#endif |
26 changes: 26 additions & 0 deletions
26
DatadogSessionReplay/Sources/Recorder/Utilities/SwfitUIImage+SessionReplay.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,26 @@ | ||
/* | ||
* 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 SwiftUI | ||
|
||
/// Mapping SwiftUI orientation to UIImage orientation | ||
@available(iOS 13.0, tvOS 13.0, *) | ||
internal extension SwiftUI.Image.Orientation { | ||
var uiImageOrientation: UIImage.Orientation { | ||
switch self { | ||
case .up: return .up | ||
case .down: return .down | ||
case .left: return .left | ||
case .right: return .right | ||
case .upMirrored: return .upMirrored | ||
case .downMirrored: return .downMirrored | ||
case .leftMirrored: return .leftMirrored | ||
case .rightMirrored: return .rightMirrored | ||
} | ||
} | ||
} | ||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
#if os(iOS) | ||
#if os(iOS) | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
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
32 changes: 32 additions & 0 deletions
32
...er/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/SwiftUI/Image+Reflection.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,32 @@ | ||
/* | ||
* 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 CoreGraphics | ||
import SwiftUI | ||
|
||
@available(iOS 13.0, tvOS 13.0, *) | ||
extension GraphicsImage: Reflection { | ||
init(_ mirror: ReflectionMirror) throws { | ||
scale = try mirror.descendant("scale") | ||
orientation = try mirror.descendant("orientation") | ||
contents = try mirror.descendant("contents") | ||
} | ||
} | ||
|
||
@available(iOS 13.0, tvOS 13.0, *) | ||
extension GraphicsImage.Contents: Reflection { | ||
init(_ mirror: ReflectionMirror) throws { | ||
switch (mirror.displayStyle, mirror.descendant(0)) { | ||
case let (.enum("cgImage"), cgImage as CGImage): | ||
self = .cgImage(cgImage) | ||
default: | ||
self = .unknown | ||
} | ||
} | ||
} | ||
#endif |
37 changes: 37 additions & 0 deletions
37
...rces/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/SwiftUI/Image.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,37 @@ | ||
/* | ||
* 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 CoreGraphics | ||
import SwiftUI | ||
|
||
/// Represents a SwiftUI.GraphicsImage | ||
@available(iOS 13.0, tvOS 13.0, *) | ||
internal struct GraphicsImage { | ||
let contents: Contents | ||
let scale: CGFloat | ||
let orientation: SwiftUI.Image.Orientation | ||
|
||
enum Contents { | ||
case cgImage(CGImage) | ||
case unknown | ||
} | ||
} | ||
|
||
@available(iOS 13.0, tvOS 13.0, *) | ||
extension GraphicsImage.Contents: Equatable { | ||
static func == (lhs: GraphicsImage.Contents, rhs: GraphicsImage.Contents) -> Bool { | ||
switch (lhs, rhs) { | ||
case let (.cgImage(lImage), .cgImage(rImage)): | ||
return lImage === rImage | ||
case (.unknown, .unknown): | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
} | ||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* Copyright 2019-Present Datadog, Inc. | ||
*/ | ||
|
||
#if os(iOS) | ||
#if os(iOS) | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
Oops, something went wrong.