From e7dfb92c7a4032a5ae232a0cdf866a737fce7eb8 Mon Sep 17 00:00:00 2001 From: Andrei Salavei Date: Wed, 6 Nov 2024 21:54:46 +0100 Subject: [PATCH] Fix accessibility for dialogs (#1678) Add delay to wait until all elements in semantic tree are finalised Fixes https://youtrack.jetbrains.com/issue/CMP-6938/Accessibility-does-not-work-for-dialogs-with-platformLayers-enabled ## Release Notes ### Fixes - iOS - Fix Accessibility Items availability inside dialogs --- .../compose/ui/platform/Accessibility.uikit.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/platform/Accessibility.uikit.kt b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/platform/Accessibility.uikit.kt index 744c6635085ce..285f8260d9f98 100644 --- a/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/platform/Accessibility.uikit.kt +++ b/compose/ui/ui/src/uikitMain/kotlin/androidx/compose/ui/platform/Accessibility.uikit.kt @@ -1187,9 +1187,15 @@ internal class AccessibilityMediator( fun onLayoutChange(nodeId: Int) { debugLogger?.log("onLayoutChange (nodeId=$nodeId)") - invalidatedBoundsNodeIds.add(nodeId) + // TODO: Properly implement layout invalidation, taking into account that semantics + // can also change after the `onLayoutChange` event. + if (accessibilityElementsMap[nodeId] == null) { + // Forcing tree recalculation when a node with unknown nodeId occurred. + invalidationKind = SemanticsTreeInvalidationKind.COMPLETE + } else { + invalidatedBoundsNodeIds.add(nodeId) + } - // unprocessedInvalidationKind will be set to BOUNDS in sync(), it's a strict subset of COMPLETE invalidationChannel.trySend(Unit) }