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

Commit c5b17af

Browse files
committed
update
1 parent 269576c commit c5b17af

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,20 @@ - (void)showAutocorrectionPromptRectForStart:(NSUInteger)start
761761
arguments:@[ @(client), @(start), @(end) ]];
762762
}
763763

764-
#pragma mark - Screenshot Delegate
764+
#pragma mark - FlutterViewEngineDelegate
765765

766766
- (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type
767767
asBase64Encoded:(BOOL)base64Encode {
768768
FML_DCHECK(_shell) << "Cannot takeScreenshot without a shell";
769769
return _shell->Screenshot(type, base64Encode);
770770
}
771771

772+
- (void)futterViewAccessibilityDidCall {
773+
if (self.viewController.view.accessibilityElements == nil) {
774+
[self ensureSemanticsEnabled];
775+
}
776+
}
777+
772778
- (NSObject<FlutterBinaryMessenger>*)binaryMessenger {
773779
return _binaryMessenger;
774780
}

shell/platform/darwin/ios/framework/Source/FlutterView.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
asBase64Encoded:(BOOL)base64Encode;
2222

2323
- (std::shared_ptr<flutter::FlutterPlatformViewsController>&)platformViewsController;
24-
- (void)ensureSemanticsEnabled;
24+
25+
/**
26+
* A callback that is called when iOS queries accessibility information of the Flutter view.
27+
*
28+
* This is useful to predict the current iOS accessibility status. For example, there is
29+
* no API to listen whether voice control is turned on or off. The Flutter engine uses
30+
* this callback to enable semantics in order to catch the case that voice control is
31+
* on.
32+
*/
33+
- (void)futterViewAccessibilityDidCall;
2534
@end
2635

2736
@interface FlutterView : UIView

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ - (BOOL)isAccessibilityElement {
139139
// TODO(chunhtai): Remove this workaround once iOS provides an
140140
// API to query whether voice control is enabled.
141141
// https://github.com/flutter/flutter/issues/76808.
142-
if (self.accessibilityElements == nil) {
143-
[_delegate ensureSemanticsEnabled];
144-
}
142+
[_delegate futterViewAccessibilityDidCall];
143+
// if (self.accessibilityElements == nil) {
144+
// [_delegate futterViewAccessibilityDidCall];
145+
// }
145146
return NO;
146147
}
147148

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

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,19 @@
44

55
#import <XCTest/XCTest.h>
66

7+
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
78
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h"
89

9-
@interface FakeDelegate : NSObject<FlutterViewEngineDelegate>
10+
@interface FakeDelegate : FlutterEngine
1011
@property(nonatomic) BOOL ensureSemanticsEnabledCalled;
1112
@end
1213

13-
@implementation FakeDelegate {
14-
std::shared_ptr<flutter::FlutterPlatformViewsController> _platformViewsController;
15-
}
16-
17-
- (instancetype)init{
18-
_ensureSemanticsEnabledCalled = NO;
19-
_platformViewsController = std::shared_ptr<flutter::FlutterPlatformViewsController>(nullptr);
20-
return self;
21-
}
14+
@implementation FakeDelegate
2215

23-
- (flutter::Rasterizer::Screenshot)takeScreenshot:(flutter::Rasterizer::ScreenshotType)type
24-
asBase64Encoded:(BOOL)base64Encode {
25-
return {};
26-
}
27-
28-
- (std::shared_ptr<flutter::FlutterPlatformViewsController>&)platformViewsController {
29-
return _platformViewsController;
30-
}
3116
- (void)ensureSemanticsEnabled {
3217
_ensureSemanticsEnabledCalled = YES;
3318
}
19+
3420
@end
3521

3622
@interface FlutterViewTest : XCTestCase
@@ -39,9 +25,8 @@ @interface FlutterViewTest : XCTestCase
3925
@implementation FlutterViewTest
4026

4127
- (void)testFlutterViewEnableSemanticsWhenIsAccessibilityElementIsCalled {
42-
FakeDelegate* delegate = [[FakeDelegate alloc] init];
43-
FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate
44-
opaque:NO];
28+
FakeDelegate* delegate = [[FakeDelegate alloc] initWithName:@"foobar"];
29+
FlutterView* view = [[FlutterView alloc] initWithDelegate:delegate opaque:NO];
4530
delegate.ensureSemanticsEnabledCalled = NO;
4631
XCTAssertFalse(view.isAccessibilityElement);
4732
XCTAssertTrue(delegate.ensureSemanticsEnabledCalled);

0 commit comments

Comments
 (0)