Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
bdbe3a15
Unverified
Commit
bdbe3a15
authored
Nov 16, 2017
by
amirh
Committed by
GitHub
Nov 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an accessibility service with an announce method. (#12594)
parent
beb4004f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
1 deletion
+100
-1
semantics.dart
packages/flutter/lib/semantics.dart
+1
-0
semantics_event.dart
packages/flutter/lib/src/semantics/semantics_event.dart
+38
-1
semantics_service.dart
packages/flutter/lib/src/semantics/semantics_service.dart
+34
-0
semantics_service_test.dart
packages/flutter/test/semantics/semantics_service_test.dart
+27
-0
No files found.
packages/flutter/lib/semantics.dart
View file @
bdbe3a15
...
...
@@ -14,3 +14,4 @@
library
semantics
;
export
'src/semantics/semantics.dart'
;
export
'src/semantics/semantics_service.dart'
;
packages/flutter/lib/src/semantics/semantics_event.dart
View file @
bdbe3a15
...
...
@@ -14,7 +14,7 @@ abstract class SemanticsEvent {
/// Initializes internal fields.
///
/// [type] is a string that identifies this class of [SemanticsEvent]s.
SemanticsEvent
(
this
.
type
);
const
SemanticsEvent
(
this
.
type
);
/// The type of this event.
///
...
...
@@ -121,3 +121,40 @@ class ScrollCompletedSemanticsEvent extends SemanticsEvent {
return
map
;
}
}
/// An event for a semantic announcement.
///
/// This should be used for announcement that are not seamlessly announced by
/// the system as a result of a UI state change.
///
/// For example a camera application can use this method to make accessibility
/// announcements regarding objects in the viewfinder.
///
/// When possible, prefer using mechanisms like [Semantics] to implicitly
/// trigger announcements over using this event.
class
AnnounceSemanticsEvent
extends
SemanticsEvent
{
/// Constructs an event that triggers an announcement by the platform.
const
AnnounceSemanticsEvent
(
this
.
message
,
this
.
textDirection
)
:
assert
(
message
!=
null
),
assert
(
textDirection
!=
null
),
super
(
'announce'
);
/// The message to announce.
///
/// This property must not be null.
final
String
message
;
/// Text direction for [message].
///
/// This property must not be null.
final
TextDirection
textDirection
;
@override
Map
<
String
,
dynamic
>
getDataMap
()
{
return
<
String
,
dynamic
>{
'message'
:
message
,
'textDirection'
:
textDirection
.
index
,
};
}
}
packages/flutter/lib/src/semantics/semantics_service.dart
0 → 100644
View file @
bdbe3a15
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'dart:ui'
show
TextDirection
;
import
'package:flutter/services.dart'
show
SystemChannels
;
import
'semantics_event.dart'
show
AnnounceSemanticsEvent
;
/// Allows access to the platform's accessibility services.
///
/// Events sent by this service are handled by the platform-specific
/// accessibility bridge in Flutter's engine.
///
/// When possible, prefer using mechanisms like [Semantics] to implicitly
/// trigger announcements over using this event.
class
SemanticsService
{
SemanticsService
.
_
();
/// Sends a semantic announcement.
///
/// This should be used for announcement that are not seamlessly announced by
/// the system as a result of a UI state change.
///
/// For example a camera application can use this method to make accessibility
/// announcements regarding objects in the viewfinder.
static
Future
<
Null
>
announce
(
String
message
,
TextDirection
textDirection
)
async
{
final
AnnounceSemanticsEvent
event
=
new
AnnounceSemanticsEvent
(
message
,
textDirection
);
await
SystemChannels
.
accessibility
.
send
(
event
.
toMap
());
}
}
packages/flutter/test/semantics/semantics_service_test.dart
0 → 100644
View file @
bdbe3a15
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:ui'
show
TextDirection
;
import
'package:flutter/semantics.dart'
;
import
'package:flutter/services.dart'
show
SystemChannels
;
import
'package:test/test.dart'
;
void
main
(
)
{
test
(
'Semantic announcement'
,
()
async
{
final
List
<
Map
<
String
,
dynamic
>>
log
=
<
Map
<
String
,
dynamic
>>[];
SystemChannels
.
accessibility
.
setMockMessageHandler
((
Map
<
String
,
dynamic
>
message
)
async
{
log
.
add
(
message
);
});
await
SemanticsService
.
announce
(
'announcement 1'
,
TextDirection
.
ltr
);
await
SemanticsService
.
announce
(
'announcement 2'
,
TextDirection
.
rtl
);
expect
(
log
,
equals
(<
Map
<
String
,
dynamic
>>[
<
String
,
dynamic
>
{
'type'
:
'announce'
,
'data'
:
<
String
,
dynamic
>
{
'message'
:
'announcement 1'
,
'textDirection'
:
1
}},
<
String
,
dynamic
>
{
'type'
:
'announce'
,
'data'
:
<
String
,
dynamic
>
{
'message'
:
'announcement 2'
,
'textDirection'
:
0
}},
]));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment