From ceb541b0f91ee97d5ce9f050edd2057f49270b5f Mon Sep 17 00:00:00 2001 From: Markus Hintersteiner Date: Fri, 16 Feb 2024 10:21:26 +0100 Subject: [PATCH] Fix Compose widgets are not being correctly identified for user interaction tracing (#3209) * Fix Compose widgets are not being correctly identified * Update Changelog --- CHANGELOG.md | 4 ++++ .../gestures/ComposeGestureTargetLocator.java | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91fd51e42b..afb4f439c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - Add new threshold parameters to monitor config ([#3181](https://github.com/getsentry/sentry-java/pull/3181)) - Report process init time as a span for app start performance ([#3159](https://github.com/getsentry/sentry-java/pull/3159)) +## Fixes + +- Fix Jetpack Compose widgets are not being correctly identified for user interaction tracing ([#3209](https://github.com/getsentry/sentry-java/pull/3209)) + ## 7.3.0 ### Features diff --git a/sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java b/sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java index 24f0bab95a..8f8ab283e9 100644 --- a/sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java +++ b/sentry-compose-helper/src/jvmMain/java/io/sentry/compose/gestures/ComposeGestureTargetLocator.java @@ -48,8 +48,6 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) { } } - @Nullable String targetTag = null; - if (!(root instanceof Owner)) { return null; } @@ -57,6 +55,11 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) { final @NotNull Queue queue = new LinkedList<>(); queue.add(((Owner) root).getRoot()); + // the final tag to return + @Nullable String targetTag = null; + + // the last known tag when iterating the node tree + @Nullable String lastKnownTag = null; while (!queue.isEmpty()) { final @Nullable LayoutNode node = queue.poll(); if (node == null) { @@ -66,7 +69,6 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) { if (node.isPlaced() && layoutNodeBoundsContain(composeHelper, node, x, y)) { boolean isClickable = false; boolean isScrollable = false; - @Nullable String testTag = null; final List modifiers = node.getModifierInfo(); for (ModifierInfo modifierInfo : modifiers) { @@ -83,7 +85,7 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) { isClickable = true; } else if ("SentryTag".equals(key) || "TestTag".equals(key)) { if (entry.getValue() instanceof String) { - testTag = (String) entry.getValue(); + lastKnownTag = (String) entry.getValue(); } } } @@ -100,10 +102,10 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) { } if (isClickable && targetType == UiElement.Type.CLICKABLE) { - targetTag = testTag; + targetTag = lastKnownTag; } if (isScrollable && targetType == UiElement.Type.SCROLLABLE) { - targetTag = testTag; + targetTag = lastKnownTag; // skip any children for scrollable targets break; }