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

Commit 8ec1ed5

Browse files
committed
Switched FlutterPlatformViewSemanticsContainer.semanticsObject to weak.
1 parent 2c1af0f commit 8ec1ed5

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

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: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ @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 {
2331
gMockPlatformView = nil;
2432
[super dealloc];
@@ -34,9 +42,7 @@ @implementation MockFlutterPlatformView
3442

3543
- (instancetype)init {
3644
if (self = [super init]) {
37-
MockPlatformView* view = [[MockPlatformView new] autorelease];
38-
gMockPlatformView = view;
39-
self.view = view;
45+
_view = [[MockPlatformView alloc] init];
4046
}
4147
return self;
4248
}
@@ -56,8 +62,7 @@ @implementation MockFlutterPlatformFactory
5662
- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
5763
viewIdentifier:(int64_t)viewId
5864
arguments:(id _Nullable)args {
59-
MockFlutterPlatformView* platformView = [[MockFlutterPlatformView new] autorelease];
60-
return platformView;
65+
return [[[MockFlutterPlatformView alloc] init] autorelease];
6166
}
6267

6368
@end
@@ -214,8 +219,6 @@ - (void)testSemanticsDeallocated {
214219
arguments:@{@"id" : @2, @"viewType" : @"MockFlutterPlatformView"}],
215220
result);
216221

217-
XCTAssertNotNil(gMockPlatformView);
218-
219222
auto bridge = std::make_unique<flutter::AccessibilityBridge>(
220223
/*view=*/mockFlutterView,
221224
/*platform_view=*/platform_view.get(),
@@ -229,6 +232,7 @@ - (void)testSemanticsDeallocated {
229232
nodes[kRootNodeId] = semantics_node;
230233
flutter::CustomAccessibilityActionUpdates actions;
231234
bridge->UpdateSemantics(/*nodes=*/nodes, /*actions=*/actions);
235+
XCTAssertNotNil(gMockPlatformView);
232236
flutterPlatformViewsController->Reset();
233237
}
234238
XCTAssertNil(gMockPlatformView);

0 commit comments

Comments
 (0)