Add accessibility action to get TextLayoutResult
1. SwitchAccess/VoiceAccess is still relying on framework for
granularity movements, so it is safer to implement the traversal action in
accessibility delegate so that every semantics node has this action.
2. Compared to text/textfield implement the traversal action, providing
TextLayoutResult to accessibility can avoid duplicate code (traversal
implemention in both accessibility delegate and text/textfield.). And we
avoid exposing the traversal action to compose developers.
3. For text location API, we need to get a list of Rects for the specified
text locations. We can use the added property in this CL or add a new
action to passback a list of rects. I prefer adding fewer APIs.
Relnote: Add accessibility action to get TextLayoutResult
Test: tested with later code of granularity traversal.
Change-Id: I9d6e6313528500524f04638ccb5742fcfbb41392
diff --git a/ui/ui-core/api/0.1.0-dev16.txt b/ui/ui-core/api/0.1.0-dev16.txt
index 6e7a200..2798289 100644
--- a/ui/ui-core/api/0.1.0-dev16.txt
+++ b/ui/ui-core/api/0.1.0-dev16.txt
@@ -2331,6 +2331,7 @@
public final class SemanticsActions {
method public androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> getCustomActions();
+ method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> getGetTextLayoutResult();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getOnClick();
method @Deprecated public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getScrollBackward();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> getScrollBy();
@@ -2339,6 +2340,7 @@
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function3<java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Boolean>>> getSetSelection();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<androidx.ui.text.AnnotatedString,java.lang.Boolean>>> getSetText();
property public final androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> CustomActions;
+ property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> GetTextLayoutResult;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> OnClick;
property @Deprecated public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> ScrollBackward;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> ScrollBy;
@@ -2382,6 +2384,7 @@
method public static boolean getFocused(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static String getTestTag(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static androidx.ui.text.AnnotatedString getText(androidx.ui.semantics.SemanticsPropertyReceiver);
+ method public static void getTextLayoutResult(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function1<? super java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean> action);
method public static androidx.ui.text.TextRange getTextSelectionRange(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void hidden(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void onClick(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function0<java.lang.Boolean> action);
diff --git a/ui/ui-core/api/current.txt b/ui/ui-core/api/current.txt
index 6e7a200..2798289 100644
--- a/ui/ui-core/api/current.txt
+++ b/ui/ui-core/api/current.txt
@@ -2331,6 +2331,7 @@
public final class SemanticsActions {
method public androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> getCustomActions();
+ method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> getGetTextLayoutResult();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getOnClick();
method @Deprecated public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getScrollBackward();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> getScrollBy();
@@ -2339,6 +2340,7 @@
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function3<java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Boolean>>> getSetSelection();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<androidx.ui.text.AnnotatedString,java.lang.Boolean>>> getSetText();
property public final androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> CustomActions;
+ property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> GetTextLayoutResult;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> OnClick;
property @Deprecated public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> ScrollBackward;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> ScrollBy;
@@ -2382,6 +2384,7 @@
method public static boolean getFocused(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static String getTestTag(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static androidx.ui.text.AnnotatedString getText(androidx.ui.semantics.SemanticsPropertyReceiver);
+ method public static void getTextLayoutResult(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function1<? super java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean> action);
method public static androidx.ui.text.TextRange getTextSelectionRange(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void hidden(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void onClick(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function0<java.lang.Boolean> action);
diff --git a/ui/ui-core/api/public_plus_experimental_0.1.0-dev16.txt b/ui/ui-core/api/public_plus_experimental_0.1.0-dev16.txt
index 6e7a200..2798289 100644
--- a/ui/ui-core/api/public_plus_experimental_0.1.0-dev16.txt
+++ b/ui/ui-core/api/public_plus_experimental_0.1.0-dev16.txt
@@ -2331,6 +2331,7 @@
public final class SemanticsActions {
method public androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> getCustomActions();
+ method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> getGetTextLayoutResult();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getOnClick();
method @Deprecated public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getScrollBackward();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> getScrollBy();
@@ -2339,6 +2340,7 @@
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function3<java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Boolean>>> getSetSelection();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<androidx.ui.text.AnnotatedString,java.lang.Boolean>>> getSetText();
property public final androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> CustomActions;
+ property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> GetTextLayoutResult;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> OnClick;
property @Deprecated public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> ScrollBackward;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> ScrollBy;
@@ -2382,6 +2384,7 @@
method public static boolean getFocused(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static String getTestTag(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static androidx.ui.text.AnnotatedString getText(androidx.ui.semantics.SemanticsPropertyReceiver);
+ method public static void getTextLayoutResult(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function1<? super java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean> action);
method public static androidx.ui.text.TextRange getTextSelectionRange(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void hidden(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void onClick(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function0<java.lang.Boolean> action);
diff --git a/ui/ui-core/api/public_plus_experimental_current.txt b/ui/ui-core/api/public_plus_experimental_current.txt
index 6e7a200..2798289 100644
--- a/ui/ui-core/api/public_plus_experimental_current.txt
+++ b/ui/ui-core/api/public_plus_experimental_current.txt
@@ -2331,6 +2331,7 @@
public final class SemanticsActions {
method public androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> getCustomActions();
+ method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> getGetTextLayoutResult();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getOnClick();
method @Deprecated public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getScrollBackward();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> getScrollBy();
@@ -2339,6 +2340,7 @@
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function3<java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Boolean>>> getSetSelection();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<androidx.ui.text.AnnotatedString,java.lang.Boolean>>> getSetText();
property public final androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> CustomActions;
+ property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> GetTextLayoutResult;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> OnClick;
property @Deprecated public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> ScrollBackward;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> ScrollBy;
@@ -2382,6 +2384,7 @@
method public static boolean getFocused(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static String getTestTag(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static androidx.ui.text.AnnotatedString getText(androidx.ui.semantics.SemanticsPropertyReceiver);
+ method public static void getTextLayoutResult(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function1<? super java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean> action);
method public static androidx.ui.text.TextRange getTextSelectionRange(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void hidden(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void onClick(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function0<java.lang.Boolean> action);
diff --git a/ui/ui-core/api/restricted_0.1.0-dev16.txt b/ui/ui-core/api/restricted_0.1.0-dev16.txt
index f977cd7..2147144 100644
--- a/ui/ui-core/api/restricted_0.1.0-dev16.txt
+++ b/ui/ui-core/api/restricted_0.1.0-dev16.txt
@@ -2392,6 +2392,7 @@
public final class SemanticsActions {
method public androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> getCustomActions();
+ method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> getGetTextLayoutResult();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getOnClick();
method @Deprecated public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getScrollBackward();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> getScrollBy();
@@ -2400,6 +2401,7 @@
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function3<java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Boolean>>> getSetSelection();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<androidx.ui.text.AnnotatedString,java.lang.Boolean>>> getSetText();
property public final androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> CustomActions;
+ property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> GetTextLayoutResult;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> OnClick;
property @Deprecated public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> ScrollBackward;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> ScrollBy;
@@ -2443,6 +2445,7 @@
method public static boolean getFocused(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static String getTestTag(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static androidx.ui.text.AnnotatedString getText(androidx.ui.semantics.SemanticsPropertyReceiver);
+ method public static void getTextLayoutResult(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function1<? super java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean> action);
method public static androidx.ui.text.TextRange getTextSelectionRange(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void hidden(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void onClick(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function0<java.lang.Boolean> action);
diff --git a/ui/ui-core/api/restricted_current.txt b/ui/ui-core/api/restricted_current.txt
index f977cd7..2147144 100644
--- a/ui/ui-core/api/restricted_current.txt
+++ b/ui/ui-core/api/restricted_current.txt
@@ -2392,6 +2392,7 @@
public final class SemanticsActions {
method public androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> getCustomActions();
+ method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> getGetTextLayoutResult();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getOnClick();
method @Deprecated public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> getScrollBackward();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> getScrollBy();
@@ -2400,6 +2401,7 @@
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function3<java.lang.Integer,java.lang.Integer,java.lang.Boolean,java.lang.Boolean>>> getSetSelection();
method public androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<androidx.ui.text.AnnotatedString,java.lang.Boolean>>> getSetText();
property public final androidx.ui.semantics.SemanticsPropertyKey<java.util.List<androidx.ui.semantics.CustomAccessibilityAction>> CustomActions;
+ property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function1<java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean>>> GetTextLayoutResult;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> OnClick;
property @Deprecated public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function0<java.lang.Boolean>>> ScrollBackward;
property public final androidx.ui.semantics.SemanticsPropertyKey<androidx.ui.semantics.AccessibilityAction<kotlin.jvm.functions.Function2<java.lang.Float,java.lang.Float,java.lang.Boolean>>> ScrollBy;
@@ -2443,6 +2445,7 @@
method public static boolean getFocused(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static String getTestTag(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static androidx.ui.text.AnnotatedString getText(androidx.ui.semantics.SemanticsPropertyReceiver);
+ method public static void getTextLayoutResult(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function1<? super java.util.List<androidx.ui.text.TextLayoutResult>,java.lang.Boolean> action);
method public static androidx.ui.text.TextRange getTextSelectionRange(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void hidden(androidx.ui.semantics.SemanticsPropertyReceiver);
method public static void onClick(androidx.ui.semantics.SemanticsPropertyReceiver, String? label = null, kotlin.jvm.functions.Function0<java.lang.Boolean> action);
diff --git a/ui/ui-core/src/commonMain/kotlin/androidx/ui/semantics/SemanticsProperties.kt b/ui/ui-core/src/commonMain/kotlin/androidx/ui/semantics/SemanticsProperties.kt
index 0b852e6..98c1c85 100644
--- a/ui/ui-core/src/commonMain/kotlin/androidx/ui/semantics/SemanticsProperties.kt
+++ b/ui/ui-core/src/commonMain/kotlin/androidx/ui/semantics/SemanticsProperties.kt
@@ -17,6 +17,7 @@
package androidx.ui.semantics
import androidx.ui.text.AnnotatedString
+import androidx.ui.text.TextLayoutResult
import androidx.ui.text.TextRange
import kotlin.reflect.KProperty
@@ -110,6 +111,15 @@
*/
object SemanticsActions {
/**
+ * Action to get a Text/TextField node's [TextLayoutResult]. The result is the first element
+ * of layout(the argument of the AccessibilityAction).
+ *
+ * @see SemanticsPropertyReceiver.getTextLayoutResult
+ */
+ val GetTextLayoutResult = SemanticsPropertyKey<AccessibilityAction<
+ (MutableList<TextLayoutResult>) -> Boolean>>("GetTextLayoutResult")
+
+ /**
* Action to be performed when the node is clicked.
*
* @see SemanticsPropertyReceiver.onClick
@@ -329,6 +339,19 @@
var SemanticsPropertyReceiver.customActions by SemanticsActions.CustomActions
/**
+ * This function adds the [SemanticsActions.GetTextLayoutResult] to the [SemanticsPropertyReceiver].
+ *
+ * @param label Optional label for this action.
+ * @param action Action to be performed when the [SemanticsActions.GetTextLayoutResult] is called.
+ */
+fun SemanticsPropertyReceiver.getTextLayoutResult(
+ label: String? = null,
+ action: (MutableList<TextLayoutResult>) -> Boolean
+) {
+ this[SemanticsActions.GetTextLayoutResult] = AccessibilityAction(label, action)
+}
+
+/**
* This function adds the [SemanticsActions.OnClick] to the [SemanticsPropertyReceiver].
*
* @param label Optional label for this action.
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/ErrorMessagesTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/ErrorMessagesTest.kt
index 4036a2a..1564f0f 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/ErrorMessagesTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/ErrorMessagesTest.kt
@@ -54,6 +54,8 @@
"Node #X at (X, X, X, X)px, Tag: 'MyButton'\n" +
"Disabled = 'kotlin.Unit'\n" +
"Text = 'Toggle'\n" +
+ "GetTextLayoutResult = 'AccessibilityAction(label=null, action=Function1<" +
+ "java.util.List<androidx.ui.text.TextLayoutResult>, java.lang.Boolean>)'\n" +
"MergeDescendants = 'true'\n" +
"Has 1 sibling\n" +
"Selector used: (TestTag = 'MyButton')"
@@ -229,6 +231,8 @@
"The node is no longer in the tree, last known semantics:\n" +
"Node #X at (X, X, X, X)px\n" +
"Text = 'Hello'\n" +
+ "GetTextLayoutResult = 'AccessibilityAction(label=null, action=Function1<" +
+ "java.util.List<androidx.ui.text.TextLayoutResult>, java.lang.Boolean>)'\n" +
"Has 1 sibling\n" +
"Original selector: Text = 'Hello' (ignoreCase: false)"
) {
@@ -254,6 +258,8 @@
"The node is no longer in the tree, last known semantics:\n" +
"Node #X at (X, X, X, X)px\n" +
"Text = 'Hello'\n" +
+ "GetTextLayoutResult = 'AccessibilityAction(label=null, action=Function1<" +
+ "java.util.List<androidx.ui.text.TextLayoutResult>, java.lang.Boolean>)'\n" +
"Has 1 sibling\n" +
"Original selector: Text = 'Hello' (ignoreCase: false)"
) {
@@ -279,6 +285,8 @@
"The node is no longer in the tree, last known semantics:\n" +
"Node #X at (X, X, X, X)px\n" +
"Text = 'Hello'\n" +
+ "GetTextLayoutResult = 'AccessibilityAction(label=null, action=Function1<" +
+ "java.util.List<androidx.ui.text.TextLayoutResult>, java.lang.Boolean>)'\n" +
"Has 1 sibling\n" +
"Original selector: Text = 'Hello' (ignoreCase: false)"
) {
diff --git a/ui/ui-test/src/androidTest/java/androidx/ui/test/PrintToStringTest.kt b/ui/ui-test/src/androidTest/java/androidx/ui/test/PrintToStringTest.kt
index afd122c..6da687b 100644
--- a/ui/ui-test/src/androidTest/java/androidx/ui/test/PrintToStringTest.kt
+++ b/ui/ui-test/src/androidTest/java/androidx/ui/test/PrintToStringTest.kt
@@ -69,6 +69,8 @@
assertThat(obfuscateNodesInfo(result)).isEqualTo("" +
"Node #X at (X, X, X, X)px\n" +
"Text = 'Hello'\n" +
+ "GetTextLayoutResult = 'AccessibilityAction(label=null, action=Function1<java" +
+ ".util.List<androidx.ui.text.TextLayoutResult>, java.lang.Boolean>)'\n" +
"Has 1 sibling")
}
@@ -85,9 +87,13 @@
assertThat(obfuscateNodesInfo(result)).isEqualTo("" +
"1) Node #X at (X, X, X, X)px\n" +
"Text = 'Hello'\n" +
+ "GetTextLayoutResult = 'AccessibilityAction(label=null, action=Function1<java" +
+ ".util.List<androidx.ui.text.TextLayoutResult>, java.lang.Boolean>)'\n" +
"Has 1 sibling\n" +
"2) Node #X at (X, X, X, X)px\n" +
"Text = 'World'\n" +
+ "GetTextLayoutResult = 'AccessibilityAction(label=null, action=Function1<java" +
+ ".util.List<androidx.ui.text.TextLayoutResult>, java.lang.Boolean>)'\n" +
"Has 1 sibling")
}
@@ -117,9 +123,15 @@
" | \n" +
" | Text = 'Button'\n" +
+ " | GetTextLayoutResult = 'AccessibilityAction(label=null, " +
+ "action=Function1<java.util.List<androidx.ui.text.TextLayoutResult>, java.lang" +
+ ".Boolean>)'\n" +
" | MergeDescendants = 'true'\n" +
" |-Node #X at (X, X, X, X)px\n" +
- " Text = 'Hello'")
+ " Text = 'Hello'\n" +
+ " GetTextLayoutResult = 'AccessibilityAction(label=null, " +
+ "action=Function1<java.util.List<androidx.ui.text.TextLayoutResult>, java.lang" +
+ ".Boolean>)'")
}
@Test
diff --git a/ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreText.kt b/ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreText.kt
index 31c9e93..97f1d54 100644
--- a/ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreText.kt
+++ b/ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreText.kt
@@ -35,10 +35,12 @@
import androidx.ui.core.onPositioned
import androidx.ui.core.selection.Selectable
import androidx.ui.core.selection.SelectionRegistrarAmbient
+import androidx.ui.core.semantics.semantics
import androidx.ui.geometry.Offset
import androidx.ui.graphics.Color
import androidx.ui.graphics.drawscope.drawCanvas
import androidx.ui.graphics.Paint
+import androidx.ui.semantics.getTextLayoutResult
import androidx.ui.text.font.Font
import androidx.ui.text.selection.MultiWidgetSelectionDelegate
import androidx.ui.text.style.TextAlign
@@ -151,6 +153,15 @@
}
state.previousGlobalPosition = newGlobalPosition
}
+ }.semantics {
+ getTextLayoutResult {
+ if (state.layoutResult != null) {
+ it.add(state.layoutResult!!)
+ true
+ } else {
+ false
+ }
+ }
},
minIntrinsicWidthMeasureBlock = { _, _ ->
state.textDelegate.layoutIntrinsics(layoutDirection)
diff --git a/ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreTextField.kt b/ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreTextField.kt
index 62ce6bd..f677d38 100644
--- a/ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreTextField.kt
+++ b/ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreTextField.kt
@@ -61,6 +61,7 @@
import androidx.ui.text.selection.TextFieldSelectionManager
import kotlin.math.max
import androidx.ui.semantics.focused
+import androidx.ui.semantics.getTextLayoutResult
import androidx.ui.semantics.setSelection
import androidx.ui.semantics.setText
import androidx.ui.semantics.text
@@ -342,7 +343,7 @@
}
val semanticsModifier = semanticsModifier(value, imeAction, focusModifier,
- onValueChangeWrapper)
+ state, onValueChangeWrapper)
onDispose { manager.hideSelectionToolbar() }
@@ -507,6 +508,7 @@
value: TextFieldValue,
imeAction: ImeAction,
focusModifier: FocusModifier,
+ state: TextFieldState,
onValueChange: (TextFieldValue) -> Unit
): Modifier {
return Modifier.semantics {
@@ -515,6 +517,14 @@
this.text = AnnotatedString(value.text)
this.textSelectionRange = value.selection
this.focused = focusModifier.focusState == FocusState.Focused
+ getTextLayoutResult {
+ if (state.layoutResult != null) {
+ it.add(state.layoutResult!!)
+ true
+ } else {
+ false
+ }
+ }
setText {
onValueChange(TextFieldValue(it.text, TextRange(it.text.length)))
true