|
1 | 1 | package io.sentry.compose.gestures; |
2 | 2 |
|
| 3 | +import androidx.compose.ui.Modifier; |
3 | 4 | import androidx.compose.ui.geometry.Rect; |
4 | 5 | import androidx.compose.ui.layout.ModifierInfo; |
5 | 6 | import androidx.compose.ui.node.LayoutNode; |
|
13 | 14 | import io.sentry.compose.helper.BuildConfig; |
14 | 15 | import io.sentry.internal.gestures.GestureTargetLocator; |
15 | 16 | import io.sentry.internal.gestures.UiElement; |
| 17 | +import java.lang.reflect.Field; |
16 | 18 | import java.util.LinkedList; |
17 | 19 | import java.util.List; |
18 | 20 | import java.util.Map; |
@@ -90,13 +92,28 @@ public ComposeGestureTargetLocator(final @NotNull ILogger logger) { |
90 | 92 | } |
91 | 93 | } |
92 | 94 | } else { |
| 95 | + final @NotNull Modifier modifier = modifierInfo.getModifier(); |
93 | 96 | // Newer Jetpack Compose 1.5 uses Node modifiers for clicks/scrolls |
94 | | - final @Nullable String type = modifierInfo.getModifier().getClass().getCanonicalName(); |
| 97 | + final @Nullable String type = modifier.getClass().getCanonicalName(); |
95 | 98 | if ("androidx.compose.foundation.ClickableElement".equals(type) |
96 | 99 | || "androidx.compose.foundation.CombinedClickableElement".equals(type)) { |
97 | 100 | isClickable = true; |
98 | 101 | } else if ("androidx.compose.foundation.ScrollingLayoutElement".equals(type)) { |
99 | 102 | isScrollable = true; |
| 103 | + } else if ("androidx.compose.ui.platform.TestTagElement".equals(type)) { |
| 104 | + // Newer Jetpack Compose uses TestTagElement as node elements |
| 105 | + // See |
| 106 | + // 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 |
| 107 | + try { |
| 108 | + final Field tagField = modifier.getClass().getDeclaredField("tag"); |
| 109 | + tagField.setAccessible(true); |
| 110 | + final @Nullable Object value = tagField.get(modifier); |
| 111 | + if (value instanceof String) { |
| 112 | + lastKnownTag = (String) value; |
| 113 | + } |
| 114 | + } catch (Throwable e) { |
| 115 | + // ignored |
| 116 | + } |
100 | 117 | } |
101 | 118 | } |
102 | 119 | } |
|
0 commit comments