Skip to content

Conversation

@FrancoisBlavoet
Copy link

@FrancoisBlavoet FrancoisBlavoet commented Sep 8, 2025

Ugly fix for #2093

The current approach to check for modifier == Modifier.alpha(0f) only works if you use this exact modifier.
In particular, Modifier.graphicsLayer { alpha = 0f } won't match this check.

Unfortunately, Compose does not really expose anything that we could use to identify a transparent node.
There is however an internal function allowing us to detect this.
Ideally we would get the compose team to make it public (or otherwise expose this information another way), but in the mean time I have written this ugly reflective way to access this information

This also adds a check for HideFromAccessibility since this is a new replacement for InvisibleToUser, we need to check for that one too.

@FrancoisBlavoet FrancoisBlavoet changed the title Make it so Paparazzi A11y renderer correctly discards all nodes with … Make it so Paparazzi A11y renderer correctly discards all nodes with alpha=0f Sep 8, 2025
private fun SemanticsNode.hasZeroAlpha(): Boolean {
// try to reflectively query internal SemanticsNode.isTransparent() by iterating on kotlin field mangled names:
val candidateGetterNames = arrayOf(
"isTransparent",
Copy link
Author

@FrancoisBlavoet FrancoisBlavoet Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very ugly, unless there is an alternative way to get this info, we should get Compose to expose this property

@FrancoisBlavoet FrancoisBlavoet changed the title Make it so Paparazzi A11y renderer correctly discards all nodes with alpha=0f Paparazzi A11y renderer: discard all nodes with alpha=0f Sep 9, 2025
"getIsTransparent",
"getIsTransparent\$ui_release"
)
for (name in candidateGetterNames) {
Copy link
Contributor

@TWiStErRob TWiStErRob Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this is near inner loop; executed on all nodes. I should be possible to cache this reflection filter query (companion object by lazy? because it's not dependent on any specific node) and only doing the invoke in hasZeroAlpha.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, we now cache the resolved function

@FrancoisBlavoet FrancoisBlavoet changed the title Paparazzi A11y renderer: discard all nodes with alpha=0f A11y renderer: handle nodes with alpha=0f or HideFromAccessibility Sep 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants