Skip to content

Commit f7a94f6

Browse files
committed
fix(demo): force accessibility refresh on foreground
1 parent 3f8bb50 commit f7a94f6

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

examples/demo/Assets/Scripts/Services/AccessibilityBridge.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,23 @@ private void OnDestroy()
238238
_instance = null;
239239
}
240240

241+
// After returnToApp() the test runner's first query can read a stale
242+
// accessibility snapshot: WDA on iOS (and to a lesser extent
243+
// UiAutomator2 on Android) caches the tree, and neither
244+
// BuildHierarchy's "structure changed" check nor the OS's own
245+
// notifications reliably invalidate that cache when the tree is
246+
// identical to before backgrounding. Rebuild and broadcast a
247+
// screen-changed notification unconditionally on every foreground so
248+
// the next XCUITest/UiAutomator2 query returns fresh data without the
249+
// Appium side having to spin on a fixed sleep.
250+
private void OnApplicationFocus(bool hasFocus)
251+
{
252+
if (!hasFocus || _hierarchy == null || _root == null)
253+
return;
254+
BuildHierarchy();
255+
AssistiveSupport.notificationDispatcher?.SendScreenChanged();
256+
}
257+
241258
private void UnregisterTreeCallbacks()
242259
{
243260
if (_root != null)

0 commit comments

Comments
 (0)