From a523b1dad9c3f882bcb79ee9d3859655184e50ba Mon Sep 17 00:00:00 2001 From: Maciej Burda Date: Mon, 10 Apr 2023 13:02:35 +0100 Subject: [PATCH] REPLAY-1508 Add support and tests for always template rendering mode of UIImage --- .../SRHost/Fixtures/Images.storyboard | 40 ++++++++++++------- .../Fixtures/ImagesViewControllers.swift | 16 ++++++++ .../SRSnapshotTests.xcodeproj/project.pbxproj | 4 ++ .../NodeRecorders/UIImageViewRecorder.swift | 16 +++++--- 4 files changed, 56 insertions(+), 20 deletions(-) create mode 100644 DatadogSessionReplay/SRSnapshotTests/SRHost/Fixtures/ImagesViewControllers.swift diff --git a/DatadogSessionReplay/SRSnapshotTests/SRHost/Fixtures/Images.storyboard b/DatadogSessionReplay/SRSnapshotTests/SRHost/Fixtures/Images.storyboard index c3e3bf4c9f..b2a0b4052a 100644 --- a/DatadogSessionReplay/SRSnapshotTests/SRHost/Fixtures/Images.storyboard +++ b/DatadogSessionReplay/SRSnapshotTests/SRHost/Fixtures/Images.storyboard @@ -1,31 +1,31 @@ - + - + - + - + - + - + @@ -33,7 +33,7 @@ - + @@ -183,7 +183,7 @@ - + @@ -198,7 +198,7 @@ - + @@ -209,25 +209,37 @@ + + + + + + + - + + - - + + - + - + + + + + diff --git a/DatadogSessionReplay/SRSnapshotTests/SRHost/Fixtures/ImagesViewControllers.swift b/DatadogSessionReplay/SRSnapshotTests/SRHost/Fixtures/ImagesViewControllers.swift new file mode 100644 index 0000000000..8ee2e0f98b --- /dev/null +++ b/DatadogSessionReplay/SRSnapshotTests/SRHost/Fixtures/ImagesViewControllers.swift @@ -0,0 +1,16 @@ +/* + * 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. + */ + +import UIKit + +internal class ImagesViewController: UIViewController { + @IBOutlet weak var customImageView: UIImageView! + + override func viewDidLoad() { + super.viewDidLoad() + customImageView.image = UIImage(named: "dd_logo")?.withRenderingMode(.alwaysTemplate) + } +} diff --git a/DatadogSessionReplay/SRSnapshotTests/SRSnapshotTests.xcodeproj/project.pbxproj b/DatadogSessionReplay/SRSnapshotTests/SRSnapshotTests.xcodeproj/project.pbxproj index 3ee20ed16e..4039899754 100644 --- a/DatadogSessionReplay/SRSnapshotTests/SRSnapshotTests.xcodeproj/project.pbxproj +++ b/DatadogSessionReplay/SRSnapshotTests/SRSnapshotTests.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ 61E7DFB9299A5A3E001D7A3A /* Basic.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 61E7DFB8299A5A3E001D7A3A /* Basic.storyboard */; }; 61E7DFBB299A5C9D001D7A3A /* BasicViewControllers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61E7DFBA299A5C9D001D7A3A /* BasicViewControllers.swift */; }; 61EC1A37299CFD7E00224FB6 /* TestUtilities in Frameworks */ = {isa = PBXBuildFile; productRef = 61EC1A36299CFD7E00224FB6 /* TestUtilities */; }; + A77C62F429E4298200AC923B /* ImagesViewControllers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A77C62F329E4298200AC923B /* ImagesViewControllers.swift */; }; A797A95029D5958400EE73EB /* Images.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A797A94F29D5958400EE73EB /* Images.storyboard */; }; A797A95229D59E7900EE73EB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A797A95129D59E7900EE73EB /* Assets.xcassets */; }; /* End PBXBuildFile section */ @@ -60,6 +61,7 @@ 61E7DFB6299A57A9001D7A3A /* MenuViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = ""; }; 61E7DFB8299A5A3E001D7A3A /* Basic.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Basic.storyboard; sourceTree = ""; }; 61E7DFBA299A5C9D001D7A3A /* BasicViewControllers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BasicViewControllers.swift; sourceTree = ""; }; + A77C62F329E4298200AC923B /* ImagesViewControllers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagesViewControllers.swift; sourceTree = ""; }; A797A94F29D5958400EE73EB /* Images.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Images.storyboard; sourceTree = ""; }; A797A95129D59E7900EE73EB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; /* End PBXFileReference section */ @@ -156,6 +158,7 @@ 61A735A929A5137400001820 /* InputViewControllers.swift */, 6196D32329AF7EB2002EACAF /* InputElements-DatePickers.storyboard */, A797A94F29D5958400EE73EB /* Images.storyboard */, + A77C62F329E4298200AC923B /* ImagesViewControllers.swift */, ); path = Fixtures; sourceTree = ""; @@ -279,6 +282,7 @@ 61B3BC4B2993BE2E0032C78A /* AppDelegate.swift in Sources */, 61E7DFBB299A5C9D001D7A3A /* BasicViewControllers.swift in Sources */, 61E7DFB7299A57A9001D7A3A /* MenuViewController.swift in Sources */, + A77C62F429E4298200AC923B /* ImagesViewControllers.swift in Sources */, 61B634EB299A5DB3002BEABE /* Fixtures.swift in Sources */, 61B3BC4D2993BE2E0032C78A /* SceneDelegate.swift in Sources */, 61A735AA29A5137400001820 /* InputViewControllers.swift in Sources */, diff --git a/DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIImageViewRecorder.swift b/DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIImageViewRecorder.swift index a5c3b8cebd..1e728f96fc 100644 --- a/DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIImageViewRecorder.swift +++ b/DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/UIImageViewRecorder.swift @@ -20,15 +20,15 @@ internal struct UIImageViewRecorder: NodeRecorder { internal init( tintColorProvider: @escaping (UIImageView) -> UIColor? = { imageView in - if #available(iOS 13.0, *) { - return imageView.image?.isSymbolImage == true ? imageView.tintColor : nil + if #available(iOS 13.0, *), let image = imageView.image { + return image.isSymbolImage || image.isAlwaysTemplate ? imageView.tintColor : nil } else { return nil } }, shouldRecordImagePredicate: @escaping (UIImageView) -> Bool = { imageView in - if #available(iOS 13.0, *) { - return imageView.image?.isSymbolImage == true || imageView.image?.description.isBundled == true + if #available(iOS 13.0, *), let image = imageView.image { + return image.isSymbolImage || image.isBundled || image.isAlwaysTemplate } else { return false } @@ -159,8 +159,12 @@ internal struct UIImageViewWireframesBuilder: NodeWireframesBuilder { } } -fileprivate extension String { +fileprivate extension UIImage { var isBundled: Bool { - return contains("named(") + return description.contains("named(") + } + + var isAlwaysTemplate: Bool { + return renderingMode == .alwaysTemplate } }