From 70bd77fa74c947abf5481fbe293a39e401788d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=BB=91=E5=92=8C=E5=B9=B3?= Date: Mon, 24 Feb 2025 14:18:55 +0800 Subject: [PATCH] Avoid sortedWithinKnot temporarily MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid sortedWithinKnot on OHOS to keep the children order of the semantics node is compatible with accessibility service on OHOS. Signed-off-by: 小黑和平 --- .../flutter/lib/src/semantics/semantics.dart | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/semantics/semantics.dart b/packages/flutter/lib/src/semantics/semantics.dart index da9a891f803..552d21af6bc 100644 --- a/packages/flutter/lib/src/semantics/semantics.dart +++ b/packages/flutter/lib/src/semantics/semantics.dart @@ -3125,9 +3125,27 @@ class _SemanticsSortGroup implements Comparable<_SemanticsSortGroup> { horizontalGroups = horizontalGroups.reversed.toList(); } - return horizontalGroups - .expand((_SemanticsSortGroup group) => group.sortedWithinKnot()) - .toList(); + switch (defaultTargetPlatform) { + // At present, OHOS does not support selecting the target component for hover + // events based on the childrenInHitTestOrder. The default component selection + // of the OHOS accessibility service is in the reverse order of + // childenInTraversalOrder. + // So, in order to avoid unexpected component selection in some situation, + // sortedWithinKnot shoult be avoid. + // For example: + // stack: children[A, B, C] + // sortedWithinKnot may order childenInTraversalOrder as [A, C, B] unexpectedly. + // FIXME: Remove it when OHOS support childrenInHitTestOrder + case TargetPlatform.ohos: + return + horizontalGroups + .expand((_SemanticsSortGroup group) => group.nodes) + .toList(); + default: + return horizontalGroups + .expand((_SemanticsSortGroup group) => group.sortedWithinKnot()) + .toList(); + } } /// Sorts [nodes] where nodes intersect both vertically and horizontally. -- Gitee