diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java index 00476172b4..bb5e132d46 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/FlutterNativeView.java @@ -205,7 +205,8 @@ public class FlutterNativeView implements BinaryMessenger { // Called by native to update the semantics/accessibility tree. private void updateSemantics(ByteBuffer buffer, String[] strings) { - if (mFlutterView == null) return; + if (mFlutterView == null) + return; mFlutterView.updateSemantics(buffer, strings); } @@ -218,13 +219,17 @@ public class FlutterNativeView implements BinaryMessenger { // Called by native to notify first Flutter frame rendered. private void onFirstFrame() { - if (mFlutterView == null) return; + if (mFlutterView == null) + return; mFlutterView.onFirstFrame(); } - // Called by native to notify when the engine is restarted (cold reload). + // Called by native to notify when the engine is restarted (hot restart). @SuppressWarnings("unused") private void onPreEngineRestart() { + if (mFlutterView != null) { + mFlutterView.resetAccessibilityTree(); + } if (mPluginRegistry == null) return; mPluginRegistry.onPreEngineRestart(); diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h index bcfb5b5c68..465abc5035 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h @@ -129,11 +129,12 @@ class AccessibilityBridge final { fml::WeakPtr GetWeakPtr(); + void clearState(); + private: SemanticsObject* GetOrCreateObject(int32_t id, blink::SemanticsNodeUpdates& updates); void VisitObjectsRecursivelyAndRemove(SemanticsObject* object, NSMutableArray* doomed_uids); - void ReleaseObjects(std::unordered_map& objects); void HandleEvent(NSDictionary* annotatedEvent); UIView* view_; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 029cfcfd77..d744e5fc06 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -687,4 +687,10 @@ fml::WeakPtr AccessibilityBridge::GetWeakPtr() { return weak_factory_.GetWeakPtr(); } +void AccessibilityBridge::clearState() { + [objects_ removeAllObjects]; + previous_route_id_ = 0; + previous_routes_.clear(); +} + } // namespace shell diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm index 0f3a1b8ca2..f3371a9834 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm @@ -120,6 +120,9 @@ std::unique_ptr PlatformViewIOS::CreateVSyncWaiter() { } void PlatformViewIOS::OnPreEngineRestart() const { + if (accessibility_bridge_) { + accessibility_bridge_->clearState(); + } if (!owner_controller_) { return; }