@@ -8,6 +8,7 @@ import Foundation
8
8
import UIKit
9
9
import DatadogInternal
10
10
11
+ // MARK: - RUMViewsHandler
11
12
internal final class RUMViewsHandler {
12
13
/// RUM representation of a View.
13
14
private struct View {
@@ -33,9 +34,17 @@ internal final class RUMViewsHandler {
33
34
/// The current date provider.
34
35
private let dateProvider : DateProvider
35
36
36
- /// `UIKit` view predicate. `nil`, if `UIKit` auto-instrumentations is
37
+ /// `UIKit` view predicate. `nil` if `UIKit` auto-instrumentations is
37
38
/// disabled.
38
- private let predicate : UIKitRUMViewsPredicate ?
39
+ private let uiKitPredicate : UIKitRUMViewsPredicate ?
40
+
41
+ /// `SwiftUI` view predicate. `nil` if `SwiftUI` auto-instrumentations is
42
+ /// disabled.
43
+ private let swiftUIPredicate : SwiftUIRUMViewsPredicate ?
44
+
45
+ /// `SwiftUI` view name extractor.
46
+ /// Extracts `SwiftUI` view name from view hierarchy.
47
+ private let swiftUIViewNameExtractor : SwiftUIViewNameExtractor ?
39
48
40
49
/// The notification center where this handler observes following `UIApplication` notifications:
41
50
/// - `.didEnterBackgroundNotification`
@@ -64,11 +73,15 @@ internal final class RUMViewsHandler {
64
73
/// a set of `UIApplication` notifications.
65
74
init (
66
75
dateProvider: DateProvider ,
67
- predicate: UIKitRUMViewsPredicate ? ,
76
+ uiKitPredicate: UIKitRUMViewsPredicate ? ,
77
+ swiftUIPredicate: SwiftUIRUMViewsPredicate ? ,
78
+ swiftUIViewNameExtractor: SwiftUIViewNameExtractor ? ,
68
79
notificationCenter: NotificationCenter
69
80
) {
70
81
self . dateProvider = dateProvider
71
- self . predicate = predicate
82
+ self . uiKitPredicate = uiKitPredicate
83
+ self . swiftUIPredicate = swiftUIPredicate
84
+ self . swiftUIViewNameExtractor = swiftUIViewNameExtractor
72
85
self . notificationCenter = notificationCenter
73
86
74
87
notificationCenter. addObserver (
@@ -196,14 +209,15 @@ internal final class RUMViewsHandler {
196
209
}
197
210
}
198
211
212
+ // MARK: - UIViewControllerHandler
199
213
extension RUMViewsHandler : UIViewControllerHandler {
200
214
func notify_viewDidAppear( viewController: UIViewController , animated: Bool ) {
201
215
let identity = ViewIdentifier ( viewController)
202
216
if let view = stack. first ( where: { $0. identity == identity } ) {
203
217
// If the stack already contains the view controller, just restarts the view.
204
218
// This prevents from calling the predicate when unnecessary.
205
219
add ( view: view)
206
- } else if let rumView = predicate ? . rumView ( for: viewController) {
220
+ } else if let rumView = uiKitPredicate ? . rumView ( for: viewController) {
207
221
add (
208
222
view: . init(
209
223
identity: identity,
@@ -214,6 +228,20 @@ extension RUMViewsHandler: UIViewControllerHandler {
214
228
instrumentationType: . uikit
215
229
)
216
230
)
231
+ } else if let swiftUIPredicate,
232
+ let swiftUIViewNameExtractor,
233
+ let rumViewName = swiftUIViewNameExtractor. extractName ( from: viewController) ,
234
+ let rumView = swiftUIPredicate. rumView ( for: rumViewName) {
235
+ add (
236
+ view: . init(
237
+ identity: identity,
238
+ name: rumView. name,
239
+ path: rumView. path ?? viewController. canonicalClassName,
240
+ isUntrackedModal: rumView. isUntrackedModal,
241
+ attributes: rumView. attributes,
242
+ instrumentationType: . swiftui
243
+ )
244
+ )
217
245
} else if #available( iOS 13 , tvOS 13 , * ) , viewController. isModalInPresentation {
218
246
add (
219
247
view: . init(
@@ -233,6 +261,7 @@ extension RUMViewsHandler: UIViewControllerHandler {
233
261
}
234
262
}
235
263
264
+ // MARK: - SwiftUIViewHandler
236
265
extension RUMViewsHandler : SwiftUIViewHandler {
237
266
/// Respond to a `SwiftUI.View.onAppear` event.
238
267
///
0 commit comments