-
-
Notifications
You must be signed in to change notification settings - Fork 467
Expand file tree
/
Copy pathSentryModifier.kt
More file actions
64 lines (50 loc) · 2.15 KB
/
SentryModifier.kt
File metadata and controls
64 lines (50 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package io.sentry.compose
import androidx.compose.ui.Modifier
import androidx.compose.ui.node.ModifierNodeElement
import androidx.compose.ui.node.SemanticsModifierNode
import androidx.compose.ui.platform.InspectorInfo
import androidx.compose.ui.semantics.SemanticsConfiguration
import androidx.compose.ui.semantics.SemanticsModifier
import androidx.compose.ui.semantics.SemanticsPropertyKey
import androidx.compose.ui.semantics.SemanticsPropertyReceiver
public object SentryModifier {
public const val TAG: String = "SentryTag"
// Based on TestTag
// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/semantics/SemanticsProperties.kt;l=166;drc=76bc6975d1b520c545b6f8786ff5c9f0bc22bd1f
private val SentryTag = SemanticsPropertyKey<String>(
name = TAG,
mergePolicy = { parentValue, _ ->
// Never merge SentryTags, to avoid leaking internal test tags to parents.
parentValue
}
)
@JvmStatic
public fun Modifier.sentryTag(tag: String): Modifier =
this then SentryTagModifierNodeElement(tag)
private data class SentryTagModifierNodeElement(val tag: String) :
ModifierNodeElement<SentryTagModifierNode>(), SemanticsModifier {
override val semanticsConfiguration: SemanticsConfiguration =
SemanticsConfiguration().also {
it[SentryTag] = tag
}
override fun create(): SentryTagModifierNode = SentryTagModifierNode(tag)
override fun update(node: SentryTagModifierNode) {
node.tag = tag
}
override fun InspectorInfo.inspectableProperties() {
name = "sentryTag"
properties["tag"] = tag
}
}
private class SentryTagModifierNode(var tag: String) :
Modifier.Node(),
SemanticsModifierNode {
override val shouldClearDescendantSemantics: Boolean
get() = false
override val shouldMergeDescendantSemantics: Boolean
get() = false
override fun SemanticsPropertyReceiver.applySemantics() {
this[SentryTag] = tag
}
}
}