@@ -190,6 +190,14 @@ public class AccessibilityBridge extends AccessibilityNodeProvider {
190
190
@ Nullable
191
191
private SemanticsNode inputFocusedSemanticsNode ;
192
192
193
+ // Keeps track of the last semantics node that had the input focus.
194
+ //
195
+ // This is used to determine if the input focus has changed since the last time the
196
+ // {@code inputFocusSemanticsNode} has been set, so that we can send a {@code TYPE_VIEW_FOCUSED}
197
+ // event when it changes.
198
+ @ Nullable
199
+ private SemanticsNode lastInputFocusedSemanticsNode ;
200
+
193
201
// The widget within Flutter that currently sits beneath a cursor, e.g,
194
202
// beneath a stylus or mouse cursor.
195
203
@ Nullable
@@ -1377,6 +1385,20 @@ void updateSemantics(@NonNull ByteBuffer buffer, @NonNull String[] strings) {
1377
1385
event .getText ().add (object .label );
1378
1386
sendAccessibilityEvent (event );
1379
1387
}
1388
+
1389
+ // If the object is the input-focused node, then tell the reader about it, but only if
1390
+ // it has changed since the last update.
1391
+ if (inputFocusedSemanticsNode != null && inputFocusedSemanticsNode .id == object .id &&
1392
+ (lastInputFocusedSemanticsNode == null || lastInputFocusedSemanticsNode .id != inputFocusedSemanticsNode .id )) {
1393
+ lastInputFocusedSemanticsNode = inputFocusedSemanticsNode ;
1394
+ sendAccessibilityEvent (obtainAccessibilityEvent (object .id , AccessibilityEvent .TYPE_VIEW_FOCUSED ));
1395
+ } else if (inputFocusedSemanticsNode == null ) {
1396
+ // There's no TYPE_VIEW_CLEAR_FOCUSED event, so if the current input focus becomes
1397
+ // null, then we just set the last one to null too, so that it sends the event again
1398
+ // when something regains focus.
1399
+ lastInputFocusedSemanticsNode = null ;
1400
+ }
1401
+
1380
1402
if (inputFocusedSemanticsNode != null && inputFocusedSemanticsNode .id == object .id
1381
1403
&& object .hadFlag (Flag .IS_TEXT_FIELD ) && object .hasFlag (Flag .IS_TEXT_FIELD )
1382
1404
// If we have a TextField that has InputFocus, we should avoid announcing it if something
0 commit comments