mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix FlutterPlatformViewSemanticsContainer retain cycle with SemanticsObject (flutter/engine#24308)
This commit is contained in:
parent
8db6a10711
commit
a1f254977b
@ -576,10 +576,35 @@ flutter::SemanticsAction GetSemanticsActionForScrollDirection(
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSArray*)accessibilityElements {
|
||||
return @[ _semanticsObject, _platformView ];
|
||||
#pragma mark - UIAccessibilityContainer overrides
|
||||
|
||||
- (NSInteger)accessibilityElementCount {
|
||||
// This container should only contain 2 elements:
|
||||
// 1. The semantic object that represents this container.
|
||||
// 2. The platform view object.
|
||||
return 2;
|
||||
}
|
||||
|
||||
- (nullable id)accessibilityElementAtIndex:(NSInteger)index {
|
||||
FML_DCHECK(index < 2);
|
||||
if (index == 0) {
|
||||
return _semanticsObject;
|
||||
} else {
|
||||
return _platformView;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)indexOfAccessibilityElement:(id)element {
|
||||
FML_DCHECK(element == _semanticsObject || element == _platformView);
|
||||
if (element == _semanticsObject) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UIAccessibilityElement overrides
|
||||
|
||||
- (CGRect)accessibilityFrame {
|
||||
return _semanticsObject.accessibilityFrame;
|
||||
}
|
||||
|
||||
@ -217,4 +217,16 @@ class MockAccessibilityBridge : public AccessibilityBridgeIos {
|
||||
XCTAssertTrue(bridge->observations[0].action == flutter::SemanticsAction::kShowOnScreen);
|
||||
}
|
||||
|
||||
- (void)testSemanticsObjectAndPlatformViewSemanticsContainerDontHaveRetainCycle {
|
||||
fml::WeakPtrFactory<flutter::MockAccessibilityBridge> factory(
|
||||
new flutter::MockAccessibilityBridge());
|
||||
fml::WeakPtr<flutter::MockAccessibilityBridge> bridge = factory.GetWeakPtr();
|
||||
SemanticsObject* object = [[SemanticsObject alloc] initWithBridge:bridge uid:1];
|
||||
object.platformViewSemanticsContainer =
|
||||
[[FlutterPlatformViewSemanticsContainer alloc] initWithSemanticsObject:object];
|
||||
__weak SemanticsObject* weakObject = object;
|
||||
object = nil;
|
||||
XCTAssertNil(weakObject);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user