Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 97bf023

Browse files
committed
Switched FlutterPlatformViewSemanticsContainer.semanticsObject to weak.
1 parent 80db950 commit 97bf023

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@
160160
}
161161
}
162162

163-
NSObject<FlutterPlatformView>* embedded_view = [factory createWithFrame:CGRectZero
164-
viewIdentifier:viewId
165-
arguments:params];
163+
NSObject<FlutterPlatformView>* embedded_view = [[factory createWithFrame:CGRectZero
164+
viewIdentifier:viewId
165+
arguments:params] autorelease];
166166
// Set a unique view identifier, so the platform view can be identified in unit tests.
167167
[embedded_view view].accessibilityIdentifier =
168168
[NSString stringWithFormat:@"platform_view[%ld]", viewId];

shell/platform/darwin/ios/framework/Source/SemanticsObject.mm

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,12 @@ - (UIAccessibilityTraits)accessibilityTraits {
508508

509509
@end
510510

511+
@interface FlutterPlatformViewSemanticsContainer ()
512+
@property(nonatomic, assign) SemanticsObject* semanticsObject;
513+
@property(nonatomic, strong) UIView* platformView;
514+
@end
515+
511516
@implementation FlutterPlatformViewSemanticsContainer {
512-
SemanticsObject* _semanticsObject;
513517
UIView* _platformView;
514518
}
515519

@@ -531,13 +535,22 @@ - (instancetype)initWithSemanticsObject:(SemanticsObject*)object {
531535
flutter::FlutterPlatformViewsController* controller =
532536
object.bridge->GetPlatformViewsController();
533537
if (controller) {
534-
_platformView = [controller->GetPlatformViewByID(object.node.platformViewId) view];
538+
_platformView = [[controller->GetPlatformViewByID(object.node.platformViewId) view] retain];
535539
}
536-
self.accessibilityElements = @[ _semanticsObject, _platformView ];
537540
}
538541
return self;
539542
}
540543

544+
- (void)dealloc {
545+
[_platformView release];
546+
_platformView = nil;
547+
[super dealloc];
548+
}
549+
550+
- (NSArray*)accessibilityElements {
551+
return @[ _semanticsObject, _platformView ];
552+
}
553+
541554
- (CGRect)accessibilityFrame {
542555
return _semanticsObject.accessibilityFrame;
543556
}

shell/platform/darwin/ios/framework/Source/accessibility_bridge.mm

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@
133133
NSMutableArray<NSNumber*>* doomed_uids = [NSMutableArray arrayWithArray:[objects_.get() allKeys]];
134134
if (root)
135135
VisitObjectsRecursivelyAndRemove(root, doomed_uids);
136-
137-
for (NSNumber* doomed_uid in doomed_uids) {
138-
((SemanticsObject*)objects_.get()[doomed_uid]).platformViewSemanticsContainer = nil;
139-
}
140136
[objects_ removeObjectsForKeys:doomed_uids];
141137

142138
layoutChanged = layoutChanged || [doomed_uids count] > 0;
@@ -247,9 +243,6 @@ static bool DidFlagChange(const flutter::SemanticsNode& oldNode,
247243
}
248244

249245
void AccessibilityBridge::clearState() {
250-
for (SemanticsObject* object in objects_.get().allValues) {
251-
object.platformViewSemanticsContainer = nil;
252-
}
253246
[objects_ removeAllObjects];
254247
previous_route_id_ = 0;
255248
previous_routes_.clear();

shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@
1313

1414
FLUTTER_ASSERT_NOT_ARC
1515
@class MockPlatformView;
16-
MockPlatformView* mockPlatformView = nil;
16+
static MockPlatformView* gMockPlatformView = nil;
1717

1818
@interface MockPlatformView : UIView
1919
@end
2020
@implementation MockPlatformView
2121

22+
- (instancetype)init {
23+
self = [super init];
24+
if (self) {
25+
gMockPlatformView = self;
26+
}
27+
return self;
28+
}
29+
2230
- (void)dealloc {
23-
mockPlatformView = nil;
31+
gMockPlatformView = nil;
2432
[super dealloc];
2533
}
2634

@@ -34,15 +42,14 @@ @implementation MockFlutterPlatformView
3442

3543
- (instancetype)init {
3644
if (self = [super init]) {
37-
MockPlatformView* view = [[MockPlatformView new] autorelease];
38-
mockPlatformView = view;
39-
self.view = view;
45+
_view = [[MockPlatformView alloc] init];
4046
}
4147
return self;
4248
}
4349

4450
- (void)dealloc {
45-
self.view = nil;
51+
[_view release];
52+
_view = nil;
4653
[super dealloc];
4754
}
4855

@@ -55,8 +62,7 @@ @implementation MockFlutterPlatformFactory
5562
- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
5663
viewIdentifier:(int64_t)viewId
5764
arguments:(id _Nullable)args {
58-
MockFlutterPlatformView* platformView = [[MockFlutterPlatformView new] autorelease];
59-
return platformView;
65+
return [[MockFlutterPlatformView alloc] init];
6066
}
6167

6268
@end
@@ -197,8 +203,8 @@ - (void)testSemanticsDeallocated {
197203
id mockFlutterView = OCMClassMock([FlutterView class]);
198204
std::string label = "some label";
199205

200-
flutter::FlutterPlatformViewsController* flutterPlatformViewsController =
201-
(flutter::FlutterPlatformViewsController*)(new flutter::FlutterPlatformViewsController());
206+
auto flutterPlatformViewsController =
207+
std::make_unique<flutter::FlutterPlatformViewsController>();
202208
flutterPlatformViewsController->SetFlutterView(mockFlutterView);
203209

204210
MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease];
@@ -213,10 +219,10 @@ - (void)testSemanticsDeallocated {
213219
arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}],
214220
result);
215221

216-
__block auto bridge = std::make_unique<flutter::AccessibilityBridge>(
222+
auto bridge = std::make_unique<flutter::AccessibilityBridge>(
217223
/*view=*/mockFlutterView,
218224
/*platform_view=*/platform_view.get(),
219-
/*platform_views_controller=*/flutterPlatformViewsController);
225+
/*platform_views_controller=*/flutterPlatformViewsController.get());
220226

221227
flutter::SemanticsNodeUpdates nodes;
222228
flutter::SemanticsNode semantics_node;
@@ -227,9 +233,8 @@ - (void)testSemanticsDeallocated {
227233
flutter::CustomAccessibilityActionUpdates actions;
228234
bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions);
229235
flutterPlatformViewsController->Reset();
230-
delete flutterPlatformViewsController;
231236
}
232-
XCTAssertNil(mockPlatformView);
237+
XCTAssertNil(gMockPlatformView);
233238
}
234239

235240
@end

0 commit comments

Comments
 (0)