* implement callback for a11y readiness
* use FlutterSemanticsUpdateNotification from header, move to VC header
This commit is contained in:
Dan Field 2019-03-06 16:53:14 -08:00 committed by GitHub
parent 1d587c84cb
commit 0f3face00a
5 changed files with 40 additions and 5 deletions

View File

@ -133,6 +133,26 @@ FLUTTER_EXPORT
*/
- (void)destroyContext;
/**
* Ensures that Flutter will generate a semantics tree.
*
* This is enabled by default if certain accessibility services are turned on by
* the user, or when using a Simulator. This method allows a user to turn
* semantics on when they would not ordinarily be generated and the performance
* overhead is not a concern, e.g. for UI testing. Note that semantics should
* never be programatically turned off, as it would potentially disable
* accessibility services an end user has requested.
*
* This method must only be called after launching the engine via
* `-runWithEntrypoint:` or `-runWithEntryPoint:libraryURI`.
*
* You can subscribe to semantics updates via `NSNotificationCenter` by adding
* an observer for the name `FlutterSemanticsUpdateNotification`. The `object`
* parameter will be the `FlutterViewController` associated with the semantics
* update.
*/
- (void)ensureSemanticsEnabled;
/**
* Sets the `FlutterViewController` for this instance. The FlutterEngine must be
* running (e.g. a successful call to `-runWithEntrypoint:` or `-runWithEntrypoint:libraryURI`)

View File

@ -17,6 +17,14 @@
@class FlutterEngine;
/**
* The name used for semantic update nofications via `NSNotificationCenter`.
*
* The object passed as the sender is the `FlutterViewController` associated
* with the update.
*/
const NSNotificationName FlutterSemanticsUpdateNotification = @"FlutterSemanticsUpdate";
/**
* A `UIViewController` implementation for Flutter views.
*

View File

@ -146,6 +146,10 @@
return _shell->GetTaskRunners().GetPlatformTaskRunner();
}
- (void)ensureSemanticsEnabled {
self.iosPlatformView->SetSemanticsEnabled(true);
}
- (void)setViewController:(FlutterViewController*)viewController {
FML_DCHECK(self.iosPlatformView);
_viewController = [viewController getWeakPtr];

View File

@ -40,6 +40,9 @@ class PlatformViewIOS final : public PlatformView {
void SetTextInputPlugin(fml::scoped_nsprotocol<FlutterTextInputPlugin*> plugin);
// |shell::PlatformView|
void SetSemanticsEnabled(bool enabled) override;
private:
fml::WeakPtr<FlutterViewController> owner_controller_;
std::unique_ptr<IOSSurface> ios_surface_;
@ -57,9 +60,6 @@ class PlatformViewIOS final : public PlatformView {
// |shell::PlatformView|
sk_sp<GrContext> CreateResourceContext() const override;
// |shell::PlatformView|
void SetSemanticsEnabled(bool enabled) override;
// |shell::PlatformView|
void SetAccessibilityFeatures(int32_t flags) override;

View File

@ -90,8 +90,8 @@ sk_sp<GrContext> PlatformViewIOS::CreateResourceContext() const {
// |shell::PlatformView|
void PlatformViewIOS::SetSemanticsEnabled(bool enabled) {
if (!owner_controller_) {
FML_DLOG(WARNING) << "Could not set semantics to enabled, this "
"PlatformViewIOS has no ViewController.";
FML_LOG(WARNING) << "Could not set semantics to enabled, this "
"PlatformViewIOS has no ViewController.";
return;
}
if (enabled && !accessibility_bridge_) {
@ -111,8 +111,11 @@ void PlatformViewIOS::SetAccessibilityFeatures(int32_t flags) {
// |shell::PlatformView|
void PlatformViewIOS::UpdateSemantics(blink::SemanticsNodeUpdates update,
blink::CustomAccessibilityActionUpdates actions) {
FML_DCHECK(owner_controller_);
if (accessibility_bridge_) {
accessibility_bridge_->UpdateSemantics(std::move(update), std::move(actions));
[[NSNotificationCenter defaultCenter] postNotificationName:FlutterSemanticsUpdateNotification
object:owner_controller_.get()];
}
}