|
2 | 2 |
|
3 | 3 | import androidx.annotation.OptIn;
|
4 | 4 | import androidx.compose.ui.InternalComposeUiApi;
|
| 5 | +import androidx.compose.ui.Modifier; |
5 | 6 | import androidx.compose.ui.geometry.Rect;
|
6 | 7 | import androidx.compose.ui.layout.ModifierInfo;
|
7 | 8 | import androidx.compose.ui.node.LayoutNode;
|
8 | 9 | import androidx.compose.ui.node.Owner;
|
9 |
| -import androidx.compose.ui.semantics.SemanticsConfiguration; |
10 |
| -import androidx.compose.ui.semantics.SemanticsModifier; |
11 |
| -import androidx.compose.ui.semantics.SemanticsPropertyKey; |
| 10 | +import androidx.compose.ui.platform.InspectableValue; |
| 11 | +import androidx.compose.ui.platform.ValueElement; |
12 | 12 |
|
13 | 13 | import com.amplitude.android.internal.ViewTarget;
|
14 | 14 | import com.amplitude.common.Logger;
|
|
17 | 17 | import org.jetbrains.annotations.Nullable;
|
18 | 18 |
|
19 | 19 | import java.util.ArrayDeque;
|
| 20 | +import java.util.Iterator; |
| 21 | +import java.util.LinkedHashMap; |
20 | 22 | import java.util.List;
|
21 | 23 | import java.util.Map;
|
22 | 24 | import java.util.Queue;
|
@@ -72,27 +74,44 @@ public ViewTarget locate(
|
72 | 74 | boolean isClickable = false;
|
73 | 75 | final List<ModifierInfo> modifiers = node.getModifierInfo();
|
74 | 76 | for (ModifierInfo modifierInfo : modifiers) {
|
75 |
| - if (modifierInfo.getModifier() instanceof SemanticsModifier) { |
76 |
| - final SemanticsModifier semanticsModifierCore = |
77 |
| - (SemanticsModifier) modifierInfo.getModifier(); |
78 |
| - final SemanticsConfiguration semanticsConfiguration = |
79 |
| - semanticsModifierCore.getSemanticsConfiguration(); |
80 |
| - for (Map.Entry<? extends SemanticsPropertyKey<?>, ?> entry : semanticsConfiguration) { |
81 |
| - final @Nullable String key = entry.getKey().getName(); |
82 |
| - if ("OnClick".equals(key)) { |
83 |
| - isClickable = true; |
84 |
| - } else if ("TestTag".equals(key)) { |
85 |
| - if (entry.getValue() instanceof String) { |
86 |
| - lastKnownTag = (String) entry.getValue(); |
| 77 | + final Modifier modifier = modifierInfo.getModifier(); |
| 78 | + if (modifier instanceof InspectableValue) { |
| 79 | + final InspectableValue inspectableValue = (InspectableValue) modifier; |
| 80 | + if ("testTag".equals(inspectableValue.getNameFallback())) { |
| 81 | + Iterator<ValueElement> iterator = inspectableValue.getInspectableElements().iterator(); |
| 82 | + while (iterator.hasNext()) { |
| 83 | + final ValueElement element = iterator.next(); |
| 84 | + if ("tag".equals(element.getName())) { |
| 85 | + lastKnownTag = (String) element.getValue(); |
| 86 | + break; |
| 87 | + } |
| 88 | + } |
| 89 | + } else if ("semantics".equals(inspectableValue.getNameFallback())) { |
| 90 | + Iterator<ValueElement> iterator = inspectableValue.getInspectableElements().iterator(); |
| 91 | + while (iterator.hasNext()) { |
| 92 | + final ValueElement element = iterator.next(); |
| 93 | + if ("properties".equals(element.getName())) { |
| 94 | + final Object elementValue = element.getValue(); |
| 95 | + if (elementValue instanceof LinkedHashMap) { |
| 96 | + final LinkedHashMap<Object, Object> properties = (LinkedHashMap<Object, Object>) elementValue; |
| 97 | + for (Map.Entry<Object, Object> entry : properties.entrySet()) { |
| 98 | + if ("TestTag".equals(entry.getKey())) { |
| 99 | + lastKnownTag = (String) entry.getValue(); |
| 100 | + break; |
| 101 | + } |
| 102 | + } |
| 103 | + } |
87 | 104 | }
|
88 | 105 | }
|
89 | 106 | }
|
90 |
| - } else { |
91 |
| - // Newer Jetpack Compose 1.5 uses Node modifiers for clicks/scrolls |
92 |
| - final @Nullable String type = modifierInfo.getModifier().getClass().getCanonicalName(); |
93 |
| - if ("androidx.compose.foundation.ClickableElement".equals(type) |
94 |
| - || "androidx.compose.foundation.CombinedClickableElement".equals(type)) { |
| 107 | + if ("clickable".equals(inspectableValue.getNameFallback())) { |
95 | 108 | isClickable = true;
|
| 109 | + } else { |
| 110 | + final @Nullable String type = modifier.getClass().getCanonicalName(); |
| 111 | + if ("androidx.compose.foundation.ClickableElement".equals(type) |
| 112 | + || "androidx.compose.foundation.CombinedClickableElement".equals(type)) { |
| 113 | + isClickable = true; |
| 114 | + } |
96 | 115 | }
|
97 | 116 | }
|
98 | 117 | }
|
|
0 commit comments