Skip to content

Commit 51276d8

Browse files
Merge pull request #2236 from DataDog/maxep/RUM-8847/fix-uikit-swiftui-navigation-tracking
RUM-8847 Remove automatic `RUMUntrackedModal` Co-authored-by: maxep <maxime.epain@datadoghq.com>
2 parents 988d24b + 4bfaecc commit 51276d8

File tree

3 files changed

+16
-64
lines changed

3 files changed

+16
-64
lines changed

DatadogRUM/Sources/Instrumentation/Views/RUMViewsHandler.swift

-11
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,6 @@ extension RUMViewsHandler: UIViewControllerHandler {
242242
instrumentationType: .swiftui
243243
)
244244
)
245-
} else if #available(iOS 13, tvOS 13, *), viewController.isModalInPresentation {
246-
add(
247-
view: .init(
248-
identity: identity,
249-
name: "RUMUntrackedModal",
250-
path: viewController.canonicalClassName,
251-
isUntrackedModal: true,
252-
attributes: [:],
253-
instrumentationType: .uikit
254-
)
255-
)
256245
}
257246
}
258247

DatadogRUM/Tests/Instrumentation/Views/RUMViewsHandlerTests.swift

-51
Original file line numberDiff line numberDiff line change
@@ -440,57 +440,6 @@ class RUMViewsHandlerTests: XCTestCase {
440440
XCTAssertTrue(startCommand2.identity == ViewIdentifier(someView))
441441
}
442442

443-
func testGiveniOS13AppearedView_whenTransitioningToModal_viewDoesStop() throws {
444-
if #available(iOS 13, tvOS 13, *) {
445-
// Given
446-
let someView = createMockViewInWindow()
447-
let untrackedModal = createMockViewInWindow()
448-
untrackedModal.isModalInPresentation = true
449-
450-
let uiKitPredicate = UIKitPredicateWithModalMock(untrackedModal: untrackedModal)
451-
let handler = createHandler(uiKitPredicate: uiKitPredicate)
452-
453-
// When
454-
handler.notify_viewDidAppear(viewController: someView, animated: .mockAny())
455-
handler.notify_viewDidAppear(viewController: untrackedModal, animated: .mockAny())
456-
457-
XCTAssertEqual(commandSubscriber.receivedCommands.count, 2)
458-
459-
let startCommand = try XCTUnwrap(commandSubscriber.receivedCommands[0] as? RUMStartViewCommand)
460-
let stopCommand = try XCTUnwrap(commandSubscriber.receivedCommands[1] as? RUMStopViewCommand)
461-
462-
XCTAssertTrue(startCommand.identity == ViewIdentifier(someView))
463-
XCTAssertTrue(stopCommand.identity == ViewIdentifier(someView))
464-
}
465-
}
466-
467-
func testGiveniOS13Modal_whenTransitioningToAppearedView_viewDoesStart() throws {
468-
if #available(iOS 13, tvOS 13, *) {
469-
// Given
470-
let someView = createMockViewInWindow()
471-
let untrackedModal = createMockViewInWindow()
472-
untrackedModal.isModalInPresentation = true
473-
474-
let uiKitPredicate = UIKitPredicateWithModalMock(untrackedModal: untrackedModal)
475-
let handler = createHandler(uiKitPredicate: uiKitPredicate)
476-
477-
// When
478-
handler.notify_viewDidAppear(viewController: someView, animated: .mockAny())
479-
handler.notify_viewDidAppear(viewController: untrackedModal, animated: .mockAny())
480-
handler.notify_viewDidAppear(viewController: someView, animated: .mockAny())
481-
482-
XCTAssertEqual(commandSubscriber.receivedCommands.count, 3)
483-
484-
let startCommand = try XCTUnwrap(commandSubscriber.receivedCommands[0] as? RUMStartViewCommand)
485-
let stopCommand = try XCTUnwrap(commandSubscriber.receivedCommands[1] as? RUMStopViewCommand)
486-
let startCommand2 = try XCTUnwrap(commandSubscriber.receivedCommands[2] as? RUMStartViewCommand)
487-
488-
XCTAssertTrue(startCommand.identity == ViewIdentifier(someView))
489-
XCTAssertTrue(stopCommand.identity == ViewIdentifier(someView))
490-
XCTAssertTrue(startCommand2.identity == ViewIdentifier(someView))
491-
}
492-
}
493-
494443
// MARK: - Handling Manual SwiftUI Instrumentation `.onAppear`
495444

496445
func testWhenOnAppear_itStartsRUMView() throws {

IntegrationTests/Runner/Scenarios/RUM/SwiftUIInstrumentation/SwiftUIRootViewController.swift

+16-2
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ struct ScreenView: View {
9494

9595
var body: some View {
9696
VStack(spacing: 32) {
97-
NavigationLink("Push to Next View", destination: destination)
98-
.trackRUMTapAction(name: "Tap Push to Next View")
97+
NavigationLink(
98+
"Push to Next View",
99+
destination: destination.dd_interactiveDismissDisabled()
100+
)
101+
.trackRUMTapAction(name: "Tap Push to Next View")
99102

100103
Text("This is a Label")
101104

@@ -189,3 +192,14 @@ class UIScreenViewController: UIViewController {
189192
}
190193
}
191194

195+
@available(iOS 13, *)
196+
extension View {
197+
func dd_interactiveDismissDisabled(_ isDisabled: Bool = true) -> some View {
198+
if #available(iOS 15.0, *) {
199+
return interactiveDismissDisabled(isDisabled)
200+
} else {
201+
return self
202+
}
203+
}
204+
}
205+

0 commit comments

Comments
 (0)