Skip to content

Commit 46c64af

Browse files
committed
Replace privace modifier with privacy view
1 parent 6683600 commit 46c64af

File tree

7 files changed

+98
-79
lines changed

7 files changed

+98
-79
lines changed

BenchmarkTests/CatalogSwiftUI/ContentView.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ public struct ContentView: View {
7777

7878
private var topHeaderRow: some View {
7979
Group {
80-
Text("A catalog of components, controls, effects, styles and accessibility elements you can use to develop SwiftUI Interfaces in iOS and iPadOS.")
81-
.font(.footnote)
82-
.fontWeight(.light)
83-
.font(.title2)
84-
.padding(.top, 24)
85-
.padding(.bottom, 16)
86-
.foregroundColor(.white)
87-
.privacyOverride(text: .maskAll)
80+
PrivacyView(text: .maskAll) {
81+
Text("A catalog of components, controls, effects, styles and accessibility elements you can use to develop SwiftUI Interfaces in iOS and iPadOS.")
82+
.font(.footnote)
83+
.fontWeight(.light)
84+
.font(.title2)
85+
.padding(.top, 24)
86+
.padding(.bottom, 16)
87+
.foregroundColor(.white)
88+
}
8889

8990
HStack(alignment: .center, spacing: 2) {
9091
Spacer()

BenchmarkTests/CatalogSwiftUI/DatadogMonitor.swift

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,65 +26,79 @@ import SwiftUI
2626
public protocol DatadogMonitor {
2727
func viewModifier(name: String) -> AnyViewModifier
2828
func actionModifier(name: String) -> AnyViewModifier
29-
func privacyOverride(
29+
func privacyView<Content: View>(
3030
text: TextPrivacyLevel?,
3131
image: ImagePrivacyLevel?,
3232
touch: TouchPrivacyLevel?,
33-
hide: Bool?
34-
) -> AnyViewModifier
33+
hide: Bool?,
34+
@ViewBuilder content: @escaping () -> Content
35+
) -> AnyView
3536
}
3637

3738
struct NOPDatadogMonitor: DatadogMonitor {
3839
func viewModifier(name: String) -> AnyViewModifier { AnyViewModifier() }
3940
func actionModifier(name: String) -> AnyViewModifier { AnyViewModifier() }
40-
func privacyOverride(
41-
text _: TextPrivacyLevel?,
42-
image _: ImagePrivacyLevel?,
43-
touch _: TouchPrivacyLevel?,
44-
hide _: Bool?
45-
) -> AnyViewModifier {
46-
AnyViewModifier()
41+
func privacyView<Content: View>(
42+
text: TextPrivacyLevel?,
43+
image: ImagePrivacyLevel?,
44+
touch: TouchPrivacyLevel?,
45+
hide: Bool?,
46+
content: @escaping () -> Content
47+
) -> AnyView {
48+
AnyView(content())
4749
}
4850
}
4951

5052
extension EnvironmentValues {
5153
@Entry public var datadogMonitor: any DatadogMonitor = NOPDatadogMonitor()
5254
}
5355

54-
extension View {
55-
func trackView(name: String) -> some View {
56-
modifier(TrackViewModifier(name: name))
57-
}
56+
struct PrivacyView<Content: View>: View {
57+
@Environment(\.datadogMonitor) private var monitor
58+
59+
private var text: TextPrivacyLevel?
60+
private var image: ImagePrivacyLevel?
61+
private var touch: TouchPrivacyLevel?
62+
private var hide: Bool?
63+
private let content: () -> Content
5864

59-
func privacyOverride(
65+
init(
6066
text: TextPrivacyLevel? = nil,
6167
image: ImagePrivacyLevel? = nil,
6268
touch: TouchPrivacyLevel? = nil,
63-
hide: Bool? = nil
64-
) -> some View {
65-
modifier(PrivacyOverrideModifier(text: text, image: image, touch: touch, hide: hide))
69+
hide: Bool? = nil,
70+
@ViewBuilder content: @escaping () -> Content
71+
) {
72+
self.text = text
73+
self.image = image
74+
self.touch = touch
75+
self.hide = hide
76+
self.content = content
77+
}
78+
79+
var body: some View {
80+
monitor.privacyView(
81+
text: text,
82+
image: image,
83+
touch: touch,
84+
hide: hide,
85+
content: content
86+
)
6687
}
6788
}
6889

69-
private struct TrackViewModifier: ViewModifier {
70-
@Environment(\.datadogMonitor) private var monitor
71-
72-
var name: String
73-
74-
func body(content: Content) -> some View {
75-
content.modifier(monitor.viewModifier(name: name))
90+
extension View {
91+
func trackView(name: String) -> some View {
92+
modifier(TrackViewModifier(name: name))
7693
}
7794
}
7895

79-
private struct PrivacyOverrideModifier: ViewModifier {
96+
private struct TrackViewModifier: ViewModifier {
8097
@Environment(\.datadogMonitor) private var monitor
8198

82-
var text: TextPrivacyLevel?
83-
var image: ImagePrivacyLevel?
84-
var touch: TouchPrivacyLevel?
85-
var hide: Bool?
99+
var name: String
86100

87101
func body(content: Content) -> some View {
88-
content.modifier(monitor.privacyOverride(text: text, image: image, touch: touch, hide: hide))
102+
content.modifier(monitor.viewModifier(name: name))
89103
}
90104
}

BenchmarkTests/CatalogSwiftUI/Views/Sections/Controls/ButtonsView.swift

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,30 @@ struct ButtonsComponentsView: View, Comparable {
8787
.font(.title2)
8888
.padding(.bottom)
8989
// MARK: - basics of buttons
90-
Group {
91-
customizableButton
92-
.modifier(Divided())
93-
roundedButtons
94-
.modifier(Divided())
95-
customShapeButtons
96-
.modifier(Divided())
97-
labelStyledButton
98-
.modifier(Divided())
99-
strokedBorderButtons
100-
.modifier(Divided())
101-
plainBackgroundButtons
102-
.modifier(Divided())
103-
imagesInButtons
104-
.modifier(Divided())
105-
buttonsWithIcons
106-
.modifier(Divided())
107-
buttonWithLabels
108-
.modifier(Divided())
109-
styledButtons
110-
.modifier(Divided())
90+
PrivacyView(touch: .hide) {
91+
Group {
92+
customizableButton
93+
.modifier(Divided())
94+
roundedButtons
95+
.modifier(Divided())
96+
customShapeButtons
97+
.modifier(Divided())
98+
labelStyledButton
99+
.modifier(Divided())
100+
strokedBorderButtons
101+
.modifier(Divided())
102+
plainBackgroundButtons
103+
.modifier(Divided())
104+
imagesInButtons
105+
.modifier(Divided())
106+
buttonsWithIcons
107+
.modifier(Divided())
108+
buttonWithLabels
109+
.modifier(Divided())
110+
styledButtons
111+
.modifier(Divided())
112+
}
111113
}
112-
.privacyOverride(touch: .hide)
113114

114115
ContributedByView(name: "Barbara Martina",
115116
link: "https://github.com/barbaramartina")

BenchmarkTests/CatalogSwiftUI/Views/Sections/Controls/ImagesView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ struct ImagesComponentView: View, Comparable {
5050
.modifier(Divided())
5151
imagesFromBundle
5252
.modifier(Divided())
53-
fixedFrameImages
54-
.modifier(Divided())
55-
.privacyOverride(image: .maskAll)
53+
PrivacyView(image: .maskAll) {
54+
fixedFrameImages
55+
}
56+
.modifier(Divided())
5657

5758
ContributedByView(name: "Barbara Martina",
5859
link: "https://github.com/barbaramartina")

BenchmarkTests/CatalogSwiftUI/Views/Sections/Controls/TextsView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ struct TextsComponentsView: View, Comparable {
6060
.modifier(Divided())
6161
textDates
6262
.modifier(Divided())
63-
textControls
64-
.privacyOverride(text: .maskAllInputs)
65-
63+
PrivacyView(text: .maskAllInputs) {
64+
textControls
65+
}
66+
6667
ContributedByView(name: "Barbara Martina",
6768
link: "https://github.com/barbaramartina")
6869
.padding(.top, 80)

BenchmarkTests/CatalogSwiftUI/Views/Sections/View Layouts/ListsView.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ struct ListsComponentView: View, Comparable {
5454
.fontWeight(.light)
5555
.font(.title2)
5656

57-
list1
58-
.modifier(Divided())
59-
.privacyOverride(text: .maskAll)
57+
PrivacyView(text: .maskAll) {
58+
list1
59+
}
60+
.modifier(Divided())
6061
list2
6162
.modifier(Divided())
6263
list3

BenchmarkTests/Runner/Scenarios/SessionReplay/SessionReplaySwiftUI/SessionReplaySwiftUIScenario.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ private struct DatadogMonitor: CatalogSwiftUI.DatadogMonitor {
6161
}
6262
}
6363

64-
func privacyOverride(
64+
func privacyView<Content: View>(
6565
text: CatalogSwiftUI.TextPrivacyLevel?,
6666
image: CatalogSwiftUI.ImagePrivacyLevel?,
6767
touch: CatalogSwiftUI.TouchPrivacyLevel?,
68-
hide: Bool?
69-
) -> AnyViewModifier {
70-
AnyViewModifier { content in
68+
hide: Bool?,
69+
content: @escaping () -> Content
70+
) -> AnyView {
71+
AnyView(
7172
SessionReplayPrivacyView(
7273
textAndInputPrivacy: .init(text),
7374
imagePrivacy: .init(image),
7475
touchPrivacy: .init(touch),
75-
hide: hide
76-
) {
77-
content
78-
}
79-
}
76+
hide: hide,
77+
content: content
78+
)
79+
)
8080
}
8181
}
8282

0 commit comments

Comments
 (0)