11package io.sentry.compose
22
33import androidx.compose.ui.Modifier
4+ import androidx.compose.ui.node.ModifierNodeElement
5+ import androidx.compose.ui.node.SemanticsModifierNode
6+ import androidx.compose.ui.platform.InspectorInfo
7+ import androidx.compose.ui.semantics.SemanticsConfiguration
8+ import androidx.compose.ui.semantics.SemanticsModifier
49import androidx.compose.ui.semantics.SemanticsPropertyKey
5- import androidx.compose.ui.semantics.semantics
10+ import androidx.compose.ui.semantics.SemanticsPropertyReceiver
611
712public object SentryModifier {
813
@@ -19,11 +24,35 @@ public object SentryModifier {
1924 )
2025
2126 @JvmStatic
22- public fun Modifier.sentryTag (tag : String ): Modifier {
23- return semantics(
24- properties = {
25- this [SentryTag ] = tag
27+ public fun Modifier.sentryTag (tag : String ): Modifier =
28+ this then SentryTagModifierNodeElement (tag)
29+
30+ private data class SentryTagModifierNodeElement (val tag : String ) :
31+ ModifierNodeElement <SentryTagModifierNode >(), SemanticsModifier {
32+
33+ override val semanticsConfiguration: SemanticsConfiguration =
34+ SemanticsConfiguration ().also {
35+ it[SentryTag ] = tag
2636 }
27- )
37+
38+ override fun create (): SentryTagModifierNode = SentryTagModifierNode (tag)
39+
40+ override fun update (node : SentryTagModifierNode ) {
41+ node.tag = tag
42+ }
43+
44+ override fun InspectorInfo.inspectableProperties () {
45+ name = " sentryTag"
46+ properties[" tag" ] = tag
47+ }
48+ }
49+
50+ private class SentryTagModifierNode (var tag : String ) :
51+ Modifier .Node (),
52+ SemanticsModifierNode {
53+
54+ override fun SemanticsPropertyReceiver.applySemantics () {
55+ this [SentryTag ] = tag
56+ }
2857 }
2958}
0 commit comments