From 2143bc5ca7b29281e138b679b3b608e45ee3431d Mon Sep 17 00:00:00 2001 From: "Kihara, Takuya" Date: Wed, 1 May 2024 17:48:18 +0900 Subject: [PATCH 1/5] fix: App crash when use WebView with iOS VoiceOver --- .../darwin/ios/framework/Source/FlutterPlatformViews.mm | 8 -------- .../ios/framework/Source/FlutterPlatformViews_Internal.h | 2 +- .../darwin/ios/framework/Source/SemanticsObject.mm | 3 +-- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 56ab003c8d0b7..20b122cfcacd7 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -981,10 +981,6 @@ @implementation FlutterTouchInterceptingView { fml::scoped_nsobject _delayingRecognizer; FlutterPlatformViewGestureRecognizersBlockingPolicy _blockingPolicy; UIView* _embeddedView; - // The used as the accessiblityContainer. - // The `accessiblityContainer` is used in UIKit to determine the parent of this accessibility - // node. - NSObject* _flutterAccessibilityContainer; } - (instancetype)initWithEmbeddedView:(UIView*)embeddedView platformViewsController: @@ -1063,10 +1059,6 @@ - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event { - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { } -- (void)setFlutterAccessibilityContainer:(NSObject*)flutterAccessibilityContainer { - _flutterAccessibilityContainer = flutterAccessibilityContainer; -} - - (id)accessibilityContainer { return _flutterAccessibilityContainer; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index b3337a1d69283..c2357c3dac20d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -440,7 +440,7 @@ class FlutterPlatformViewsController { - (UIView*)embeddedView; // Sets flutterAccessibilityContainer as this view's accessibilityContainer. -- (void)setFlutterAccessibilityContainer:(NSObject*)flutterAccessibilityContainer; +@property(nonatomic, retain) id flutterAccessibilityContainer; @end @interface UIView (FirstResponder) diff --git a/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm b/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm index 7eb0c2384fe5b..93ba5cffa99e1 100644 --- a/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm +++ b/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm @@ -876,14 +876,13 @@ - (instancetype)initWithBridge:(fml::WeakPtr)br uid:(int32_t)uid platformView:(nonnull FlutterTouchInterceptingView*)platformView { if (self = [super initWithBridge:bridge uid:uid]) { - _platformView = [platformView retain]; + _platformView = platformView; [platformView setFlutterAccessibilityContainer:self]; } return self; } - (void)dealloc { - [_platformView release]; _platformView = nil; [super dealloc]; } From 26373648d5f1ebdd592a5fb78bba5e4474047f4a Mon Sep 17 00:00:00 2001 From: "Kihara, Takuya" Date: Wed, 1 May 2024 17:54:09 +0900 Subject: [PATCH 2/5] fix format --- shell/platform/darwin/ios/framework/Source/SemanticsObject.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm b/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm index 93ba5cffa99e1..8aaa4b4d79f0c 100644 --- a/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm +++ b/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm @@ -876,7 +876,7 @@ - (instancetype)initWithBridge:(fml::WeakPtr)br uid:(int32_t)uid platformView:(nonnull FlutterTouchInterceptingView*)platformView { if (self = [super initWithBridge:bridge uid:uid]) { - _platformView = platformView; + _platformView = platformView; [platformView setFlutterAccessibilityContainer:self]; } return self; From 14c4c176125bd53e683919772922549c45806976 Mon Sep 17 00:00:00 2001 From: "Kihara, Takuya" Date: Thu, 2 May 2024 15:39:46 +0900 Subject: [PATCH 3/5] fix lint issue --- .../darwin/ios/framework/Source/FlutterPlatformViews.mm | 5 +++++ .../platform/darwin/ios/framework/Source/SemanticsObject.mm | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 20b122cfcacd7..41295f26a720d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -1063,6 +1063,11 @@ - (id)accessibilityContainer { return _flutterAccessibilityContainer; } +- (void)dealloc { + [_flutterAccessibilityContainer release]; + [super dealloc]; +} + @end @implementation DelayingGestureRecognizer { diff --git a/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm b/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm index 8aaa4b4d79f0c..cb30bc36a652d 100644 --- a/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm +++ b/shell/platform/darwin/ios/framework/Source/SemanticsObject.mm @@ -867,7 +867,7 @@ - (UIAccessibilityTraits)accessibilityTraits { @end @interface FlutterPlatformViewSemanticsContainer () -@property(nonatomic, retain) UIView* platformView; +@property(nonatomic, assign) UIView* platformView; @end @implementation FlutterPlatformViewSemanticsContainer From f1754af5ba0939dd64b76180648f61223755d13a Mon Sep 17 00:00:00 2001 From: "Kihara, Takuya" Date: Tue, 7 May 2024 15:50:14 +0900 Subject: [PATCH 4/5] Fix test code to match object lifecycle --- .../framework/Source/SemanticsObjectTest.mm | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm b/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm index 45285d7cc418b..0acc2fc48e770 100644 --- a/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm +++ b/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm @@ -994,19 +994,30 @@ - (void)testFlutterPlatformViewSemanticsContainer { new flutter::testing::MockAccessibilityBridge()); fml::WeakPtr bridge = factory.GetWeakPtr(); __weak FlutterTouchInterceptingView* weakPlatformView; + __weak FlutterPlatformViewSemanticsContainer* weakContainer; @autoreleasepool { FlutterTouchInterceptingView* platformView = [[FlutterTouchInterceptingView alloc] init]; weakPlatformView = platformView; - FlutterPlatformViewSemanticsContainer* container = - [[FlutterPlatformViewSemanticsContainer alloc] initWithBridge:bridge - uid:1 - platformView:platformView]; - XCTAssertEqualObjects(platformView.accessibilityContainer, container); + + @autoreleasepool { + FlutterPlatformViewSemanticsContainer* container = + [[FlutterPlatformViewSemanticsContainer alloc] initWithBridge:bridge + uid:1 + platformView:platformView]; + weakContainer = container; + XCTAssertEqualObjects(platformView.accessibilityContainer, container); + XCTAssertNotNil(weakPlatformView); + XCTAssertNotNil(weakContainer); + } + // Check the variables are still lived. + // `container` is `retain` in `platformView`, so it will not be nil here. XCTAssertNotNil(weakPlatformView); + XCTAssertNotNil(weakContainer); } // Check if there's no more strong references to `platformView` after container and platformView // are released. XCTAssertNil(weakPlatformView); + XCTAssertNil(weakContainer); } - (void)testTextInputSemanticsObject { From fc5447fcc1e55405045c5ef91b80bc903c3ce5f6 Mon Sep 17 00:00:00 2001 From: "Kihara, Takuya" Date: Tue, 7 May 2024 16:01:04 +0900 Subject: [PATCH 5/5] Fix indent --- .../darwin/ios/framework/Source/SemanticsObjectTest.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm b/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm index 0acc2fc48e770..7452c5c097c9e 100644 --- a/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm +++ b/shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm @@ -1001,9 +1001,9 @@ - (void)testFlutterPlatformViewSemanticsContainer { @autoreleasepool { FlutterPlatformViewSemanticsContainer* container = - [[FlutterPlatformViewSemanticsContainer alloc] initWithBridge:bridge - uid:1 - platformView:platformView]; + [[FlutterPlatformViewSemanticsContainer alloc] initWithBridge:bridge + uid:1 + platformView:platformView]; weakContainer = container; XCTAssertEqualObjects(platformView.accessibilityContainer, container); XCTAssertNotNil(weakPlatformView);