Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Do not override user-defined `SentryOptions` ([#4262](https://github.com/getsentry/sentry-java/pull/4262))
- Fix tags missing for compose view hierarchies ([#4275](https://github.com/getsentry/sentry-java/pull/4275))

### Dependencies

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) {
boolean isClickable = false;
boolean isScrollable = false;

// needs to be in-sync with ComposeGestureTargetLocator
Comment thread
markushi marked this conversation as resolved.
Outdated
final List<ModifierInfo> modifiers = node.getModifierInfo();
for (ModifierInfo modifierInfo : modifiers) {
if (modifierInfo.getModifier() instanceof SemanticsModifier) {
Expand Down Expand Up @@ -103,7 +104,8 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) {
isClickable = true;
} else if ("androidx.compose.foundation.ScrollingLayoutElement".equals(type)) {
isScrollable = true;
} else if ("androidx.compose.ui.platform.TestTagElement".equals(type)) {
} else if ("androidx.compose.ui.platform.TestTagElement".equals(type)
|| "io.sentry.compose.SentryModifier.SentryTagModifierNodeElement".equals(type)) {
Comment thread
romtsn marked this conversation as resolved.
Outdated
// Newer Jetpack Compose uses TestTagElement as node elements
// See
// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/TestTag.kt;l=34;drc=dcaa116fbfda77e64a319e1668056ce3b032469f
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.sentry.compose.viewhierarchy;

import androidx.compose.runtime.collection.MutableVector;
import androidx.compose.ui.Modifier;
import androidx.compose.ui.geometry.Rect;
import androidx.compose.ui.layout.ModifierInfo;
import androidx.compose.ui.node.LayoutNode;
Expand All @@ -14,6 +15,7 @@
import io.sentry.internal.viewhierarchy.ViewHierarchyExporter;
import io.sentry.protocol.ViewHierarchyNode;
import io.sentry.util.AutoClosableReentrantLock;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -84,9 +86,13 @@ private static void addChild(

private static void setTag(
final @NotNull LayoutNode node, final @NotNull ViewHierarchyNode vhNode) {
// needs to be in-sync with ComposeGestureTargetLocator
final List<ModifierInfo> modifiers = node.getModifierInfo();
for (ModifierInfo modifierInfo : modifiers) {
if (modifierInfo.getModifier() instanceof SemanticsModifier) {
final @NotNull Modifier modifier = modifierInfo.getModifier();
// Newer Jetpack Compose 1.5 uses Node modifier elements
final @Nullable String type = modifier.getClass().getCanonicalName();
if (modifier instanceof SemanticsModifier) {
final SemanticsModifier semanticsModifierCore =
(SemanticsModifier) modifierInfo.getModifier();
final SemanticsConfiguration semanticsConfiguration =
Expand All @@ -99,6 +105,21 @@ private static void setTag(
}
}
}
} else if ("androidx.compose.ui.platform.TestTagElement".equals(type)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to test it with robolectric/instrumented tests to avoid regressions in future?

|| "io.sentry.compose.SentryModifier.SentryTagModifierNodeElement".equals(type)) {
// Newer Jetpack Compose uses TestTagElement as node elements
// See
// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/TestTag.kt;l=34;drc=dcaa116fbfda77e64a319e1668056ce3b032469f
try {
final Field tagField = modifier.getClass().getDeclaredField("tag");
tagField.setAccessible(true);
final @Nullable Object value = tagField.get(modifier);
if (value instanceof String) {
vhNode.setTag((String) value);
}
} catch (Throwable e) {
// ignored
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions sentry-compose/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
-keepnames class androidx.compose.foundation.CombinedClickableElement
-keepnames class androidx.compose.foundation.ScrollingLayoutElement
-keepnames class androidx.compose.ui.platform.TestTagElement { *; }
-keepnames class io.sentry.compose.SentryModifier.SentryTagModifierNodeElement { *; }

# R8 will warn about missing classes if people don't have androidx.compose-navigation on their
# classpath, but this is fine, these classes are used in an internal class which is only used when
Expand Down
Loading