diff --git a/shell/platform/android/io/flutter/view/FlutterNativeView.java b/shell/platform/android/io/flutter/view/FlutterNativeView.java index 00476172b42ae..bb5e132d46ac6 100644 --- a/shell/platform/android/io/flutter/view/FlutterNativeView.java +++ b/shell/platform/android/io/flutter/view/FlutterNativeView.java @@ -205,7 +205,8 @@ private void handlePlatformMessageResponse(int replyId, byte[] reply) { // 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 @@ private void updateCustomAccessibilityActions(ByteBuffer buffer, String[] string // 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/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h index bcfb5b5c6821b..465abc5035191 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h +++ b/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/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm index 029cfcfd77595..d744e5fc06605 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm @@ -687,4 +687,10 @@ - (BOOL)accessibilityScroll:(UIAccessibilityScrollDirection)direction { return weak_factory_.GetWeakPtr(); } +void AccessibilityBridge::clearState() { + [objects_ removeAllObjects]; + previous_route_id_ = 0; + previous_routes_.clear(); +} + } // namespace shell diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index 0f3a1b8ca2467..f3371a9834a53 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -120,6 +120,9 @@ } void PlatformViewIOS::OnPreEngineRestart() const { + if (accessibility_bridge_) { + accessibility_bridge_->clearState(); + } if (!owner_controller_) { return; }