Skip to content

Commit 149a1ac

Browse files
authored
Merge pull request #2333 from DataDog/gonzalezreal/RUM-10305/swiftui-session-replay-privacy-override
Add SwiftUI support for Session Replay privacy overrides
2 parents d4ca258 + b9be328 commit 149a1ac

File tree

14 files changed

+369
-40
lines changed

14 files changed

+369
-40
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- [FEATURE] Add SwiftUI support for Session Replay privacy overrides. See [#2333][]
4+
35
# 2.29.0 / 18-06-2025
46

57
- [FEATURE] Add SwiftUI auto-tracking for views and actions. See [#2237][] [#2315][]

Datadog/Datadog.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@
392392
49D8C0B82AC5D2160075E427 /* RUM+Internal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D8C0B62AC5D2160075E427 /* RUM+Internal.swift */; };
393393
49D8C0BD2AC5F2BB0075E427 /* Logs+Internal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D8C0B92AC5F21F0075E427 /* Logs+Internal.swift */; };
394394
49D8C0BE2AC5F2BC0075E427 /* Logs+Internal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49D8C0B92AC5F21F0075E427 /* Logs+Internal.swift */; };
395+
5BCBC0CD2DF85B6A0094DCC2 /* SessionReplayPrivacyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BCBC0CC2DF85AFE0094DCC2 /* SessionReplayPrivacyView.swift */; };
395396
61020C2A2757AD91005EEAEA /* BackgroundLocationMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61020C292757AD91005EEAEA /* BackgroundLocationMonitor.swift */; };
396397
61020C2C2758E853005EEAEA /* DebugBackgroundEventsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61020C2B2758E853005EEAEA /* DebugBackgroundEventsViewController.swift */; };
397398
61054E612A6EE10A00AAA894 /* SRCompression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61054E082A6EE10A00AAA894 /* SRCompression.swift */; };
@@ -2469,6 +2470,7 @@
24692470
49274908288048F400ECD49B /* RUMInternalProxyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RUMInternalProxyTests.swift; sourceTree = "<group>"; };
24702471
49D8C0B62AC5D2160075E427 /* RUM+Internal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RUM+Internal.swift"; sourceTree = "<group>"; };
24712472
49D8C0B92AC5F21F0075E427 /* Logs+Internal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Logs+Internal.swift"; sourceTree = "<group>"; };
2473+
5BCBC0CC2DF85AFE0094DCC2 /* SessionReplayPrivacyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionReplayPrivacyView.swift; sourceTree = "<group>"; };
24722474
61020C292757AD91005EEAEA /* BackgroundLocationMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundLocationMonitor.swift; sourceTree = "<group>"; };
24732475
61020C2B2758E853005EEAEA /* DebugBackgroundEventsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugBackgroundEventsViewController.swift; sourceTree = "<group>"; };
24742476
61054E082A6EE10A00AAA894 /* SRCompression.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SRCompression.swift; sourceTree = "<group>"; };
@@ -4031,6 +4033,7 @@
40314033
966253B52C98807400B90B63 /* SessionReplayPrivacyOverrides.swift */,
40324034
A795069B2B974C8100AC4814 /* SessionReplay+objc.swift */,
40334035
96F25A802CC7EA4300459567 /* SessionReplayPrivacyOverrides+objc.swift */,
4036+
5BCBC0CC2DF85AFE0094DCC2 /* SessionReplayPrivacyView.swift */,
40344037
96F25A812CC7EA4300459567 /* UIView+SessionReplayPrivacyOverrides+objc.swift */,
40354038
61054E3B2A6EE10A00AAA894 /* Feature */,
40364039
61054E482A6EE10A00AAA894 /* Processor */,
@@ -8610,6 +8613,7 @@
86108613
D2AD1CC62CE4AE6600106C74 /* Color.swift in Sources */,
86118614
D2AD1CC72CE4AE6600106C74 /* Text+Reflection.swift in Sources */,
86128615
D2AD1CC82CE4AE6600106C74 /* Text.swift in Sources */,
8616+
5BCBC0CD2DF85B6A0094DCC2 /* SessionReplayPrivacyView.swift in Sources */,
86138617
D2AD1CC92CE4AE6600106C74 /* SwiftUIWireframesBuilder.swift in Sources */,
86148618
969B3B212C33F80500D62400 /* UIActivityIndicatorRecorder.swift in Sources */,
86158619
61054EA22A6EE10B00AAA894 /* Scheduler.swift in Sources */,

DatadogSessionReplay/SRSnapshotTests/SRFixtures/Sources/SRFixtures/Fixtures.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import UIKit
88
import SwiftUI
99

10-
public enum Fixture: CaseIterable {
10+
public protocol FixtureProtocol {
11+
func instantiateViewController() -> UIViewController
12+
}
13+
14+
public enum Fixture: FixtureProtocol, CaseIterable {
1115
case basicShapes
1216
case basicTexts
1317
case sliders
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2019-Present Datadog, Inc.
5+
*/
6+
7+
import SwiftUI
8+
9+
@available(iOS 13.0, *)
10+
extension Image {
11+
public static var datadogLogo: Image {
12+
Image("dd_logo", bundle: .module)
13+
}
14+
15+
public static var flowers: Image {
16+
Image("Flowers_1", bundle: .module)
17+
}
18+
}

DatadogSessionReplay/SRSnapshotTests/SRHost/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2020
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {}
2121

2222
/// Presents view controller for given fixture in full screen.
23-
func show(fixture: Fixture, completion: @escaping (UIViewController) -> Void) {
23+
func show(fixture: any FixtureProtocol, completion: @escaping (UIViewController) -> Void) {
2424
let vc = fixture.instantiateViewController()
2525
vc.modalPresentationStyle = .fullScreen
2626

DatadogSessionReplay/SRSnapshotTests/SRSnapshotTests.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
5BB746152E02ABB900B568F1 /* SwiftUIFixture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BB746142E02ABB500B568F1 /* SwiftUIFixture.swift */; };
11+
5BB746182E02B4CD00B568F1 /* SwiftUIViewWithPrivacyOverrides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BB746172E02B4CD00B568F1 /* SwiftUIViewWithPrivacyOverrides.swift */; };
1012
614396642A5E8C0600197326 /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614396632A5E8C0600197326 /* Environment.swift */; };
1113
614396652A5E8C0600197326 /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614396632A5E8C0600197326 /* Environment.swift */; };
1214
619C49B429952E12006B66A6 /* SnapshotTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 619C49B329952E12006B66A6 /* SnapshotTestCase.swift */; };
@@ -38,6 +40,8 @@
3840
/* End PBXContainerItemProxy section */
3941

4042
/* Begin PBXFileReference section */
43+
5BB746142E02ABB500B568F1 /* SwiftUIFixture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIFixture.swift; sourceTree = "<group>"; };
44+
5BB746172E02B4CD00B568F1 /* SwiftUIViewWithPrivacyOverrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIViewWithPrivacyOverrides.swift; sourceTree = "<group>"; };
4145
614396632A5E8C0600197326 /* Environment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Environment.swift; path = SRHost/Environment.swift; sourceTree = "<group>"; };
4246
619C49B329952E12006B66A6 /* SnapshotTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnapshotTestCase.swift; sourceTree = "<group>"; };
4347
619C49B62995512A006B66A6 /* ImageComparison.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageComparison.swift; sourceTree = "<group>"; };
@@ -86,9 +90,18 @@
8690
/* End PBXFrameworksBuildPhase section */
8791

8892
/* Begin PBXGroup section */
93+
5BB746162E02B34600B568F1 /* Fixtures */ = {
94+
isa = PBXGroup;
95+
children = (
96+
5BB746172E02B4CD00B568F1 /* SwiftUIViewWithPrivacyOverrides.swift */,
97+
);
98+
path = Fixtures;
99+
sourceTree = "<group>";
100+
};
89101
619C49B529955106006B66A6 /* Utils */ = {
90102
isa = PBXGroup;
91103
children = (
104+
5BB746142E02ABB500B568F1 /* SwiftUIFixture.swift */,
92105
619C49B329952E12006B66A6 /* SnapshotTestCase.swift */,
93106
96363B2B2CD26AF3006FEC9D /* PrivacyOverrides.swift */,
94107
61BB975E2A5D675400AFFF86 /* ImageComposition.swift */,
@@ -137,6 +150,7 @@
137150
isa = PBXGroup;
138151
children = (
139152
61B3BC642993BEAF0032C78A /* SRSnapshotTests.swift */,
153+
5BB746162E02B34600B568F1 /* Fixtures */,
140154
619C49B529955106006B66A6 /* Utils */,
141155
619C49B8299551F5006B66A6 /* _snapshots_ */,
142156
);
@@ -293,8 +307,10 @@
293307
61B3BC652993BEAF0032C78A /* SRSnapshotTests.swift in Sources */,
294308
96363B2C2CD26AF3006FEC9D /* PrivacyOverrides.swift in Sources */,
295309
61BB975F2A5D675400AFFF86 /* ImageComposition.swift in Sources */,
310+
5BB746182E02B4CD00B568F1 /* SwiftUIViewWithPrivacyOverrides.swift in Sources */,
296311
619C49B72995512A006B66A6 /* ImageComparison.swift in Sources */,
297312
619C49B429952E12006B66A6 /* SnapshotTestCase.swift in Sources */,
313+
5BB746152E02ABB900B568F1 /* SwiftUIFixture.swift in Sources */,
298314
);
299315
runOnlyForDeploymentPostprocessing = 0;
300316
};
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
* Copyright 2019-Present Datadog, Inc.
5+
*/
6+
7+
import SwiftUI
8+
import DatadogSessionReplay
9+
import DatadogInternal
10+
import SRFixtures
11+
12+
@available(iOS 16.0, *)
13+
struct SwiftUIViewWithPrivacyOverrides: View {
14+
private let core: DatadogCoreProtocol
15+
16+
init(core: DatadogCoreProtocol) {
17+
self.core = core
18+
}
19+
20+
var body: some View {
21+
SessionReplayPrivacyView(imagePrivacy: .maskNonBundledOnly, core: core) {
22+
VStack(spacing: 10) {
23+
SessionReplayPrivacyView(textAndInputPrivacy: .maskAllInputs, core: core) {
24+
Text("Hello, SwiftUI!")
25+
.font(.headline)
26+
27+
Label("Label with Icon", systemImage: "star.fill")
28+
.font(.subheadline)
29+
.foregroundStyle(.secondary)
30+
31+
TextField("Enter text", text: .constant("Placeholder text"))
32+
.textFieldStyle(RoundedBorderTextFieldStyle())
33+
.padding(8)
34+
}
35+
36+
SessionReplayPrivacyView(hide: true, core: core) {
37+
Button(action: {}) {
38+
Text("SwiftUI Button")
39+
.padding()
40+
.foregroundStyle(.background)
41+
.background(Color.blue)
42+
.cornerRadius(8)
43+
}
44+
}
45+
46+
Divider()
47+
.frame(height: 2)
48+
.background(Color.purple)
49+
.padding(.horizontal, 20)
50+
.padding(.vertical, 6)
51+
52+
// "Bundled" image
53+
Image.datadogLogo
54+
.resizable()
55+
.scaledToFit()
56+
.background(Color.purple)
57+
.frame(width: 120, height: 120)
58+
.clipped()
59+
60+
// "Content" image
61+
Image.flowers
62+
.resizable()
63+
.scaledToFit()
64+
.background(Color.purple)
65+
.frame(width: 120, height: 120)
66+
.clipped()
67+
68+
List {
69+
Text("Item 1")
70+
SessionReplayPrivacyView(textAndInputPrivacy: .maskAll, core: core) {
71+
Text("Item 2")
72+
}
73+
}.frame(height: 140)
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)