Skip to content

Commit aef35f9

Browse files
authored
Merge pull request #2692 from DataDog/yl/actions-tracking/add-selectable-item
Enhancement of Compose Actions tracking reflection
2 parents 3f5f691 + cc6c9f1 commit aef35f9

File tree

1 file changed

+9
-5
lines changed
  • integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/internal/utils

1 file changed

+9
-5
lines changed

integrations/dd-sdk-android-compose/src/main/kotlin/com/datadog/android/compose/internal/utils/LayoutNodeUtils.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ internal class LayoutNodeUtils {
5252
}
5353
} else {
5454
when (modifier::class.qualifiedName) {
55+
CLASS_NAME_SELECTABLE_ELEMENT,
5556
CLASS_NAME_CLICKABLE_ELEMENT,
5657
CLASS_NAME_COMBINED_CLICKABLE_ELEMENT -> {
5758
role = role ?: getRole(modifier)
@@ -87,11 +88,12 @@ internal class LayoutNodeUtils {
8788
}
8889

8990
@Suppress("UnsafeThirdPartyFunctionCall")
90-
// Function is wrapped with `runSafe` in the call site.
91-
private fun getRole(obj: Any): Role {
92-
val roleField = obj::class.java.getDeclaredField("role")
93-
roleField.isAccessible = true
94-
return roleField.get(obj) as Role
91+
private fun getRole(obj: Any): Role? {
92+
return runSafe {
93+
val roleField = obj::class.java.getDeclaredField("role")
94+
roleField.isAccessible = true
95+
roleField.get(obj) as? Role
96+
}
9597
}
9698

9799
fun getLayoutNodeBoundsInWindow(node: LayoutNode): Rect? {
@@ -135,5 +137,7 @@ internal class LayoutNodeUtils {
135137
"androidx.compose.foundation.ScrollingLayoutElement"
136138
private const val CLASS_NAME_SCROLLABLE_ELEMENT =
137139
"androidx.compose.foundation.gestures.ScrollableElement"
140+
private const val CLASS_NAME_SELECTABLE_ELEMENT =
141+
"androidx.compose.foundation.selection.SelectableElement"
138142
}
139143
}

0 commit comments

Comments
 (0)