Skip to content

Commit 0e04cb4

Browse files
m-absAlexander Vakrilov
authored andcommitted
fix(android): NavigationButton was read as "Button" by screenreaders. (NativeScript#5949)
The navigation button for the vision-impaired users were always read as: "Button" by the TalkBack service on Android.
1 parent b0afd3a commit 0e04cb4

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

tests/app/ui/action-bar/action-bar-tests.android.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ export function test_navigationButton_visibility() {
3232
TKUnit.assertNull(toolbar.getNavigationIcon(), "Visibility does not work");
3333
}
3434

35+
export function test_navigationButton_contentDecription() {
36+
const actionItem = new ActionItem();
37+
actionItem.icon = "~/small-image.png";
38+
const actionItemText = "NavButton with small-image";
39+
actionItem.text = actionItemText;
40+
const page = actionTestsCommon.createPageAndNavigate();
41+
page.actionBar.navigationButton = actionItem;
42+
43+
const toolbar = <android.support.v7.widget.Toolbar>page.actionBar.nativeViewProtected;
44+
45+
TKUnit.assertEqual(toolbar.getNavigationContentDescription(), actionItemText, "Navigation Button should have an content decription");
46+
}
47+
3548
export function test_set_actionView_to_attached_actionItem_propagates_context() {
3649
const actionItem = new ActionItem();
3750
const actionButton = new Button();
@@ -72,4 +85,4 @@ export function test_add_actionItem_with_actionView_propagates_context() {
7285
TKUnit.assertNull(actionButton._context, "Action button context should be null before added");
7386
actionItem.actionView = actionButton;
7487
TKUnit.assertNotNull(actionButton._context, "Action button context should not be null after add");
75-
}
88+
}

tns-core-modules/ui/action-bar/action-bar.android.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ export class ActionBar extends ActionBarBase {
223223
this.nativeViewProtected.setNavigationIcon(drawableOrId);
224224
}
225225

226+
// Set navigation content descripion, used by screen readers for the vision-impaired users
227+
this.nativeViewProtected.setNavigationContentDescription(navButton.text || null);
228+
226229
let navBtn = new WeakRef(navButton);
227230
this.nativeViewProtected.setNavigationOnClickListener(new android.view.View.OnClickListener({
228231
onClick: function (v) {
@@ -285,7 +288,7 @@ export class ActionBar extends ActionBarBase {
285288
let menuItem = menu.add(android.view.Menu.NONE, item._getItemId(), android.view.Menu.NONE, item.text + "");
286289

287290
if (item.actionView && item.actionView.android) {
288-
// With custom action view, the menuitem cannot be displayed in a popup menu.
291+
// With custom action view, the menuitem cannot be displayed in a popup menu.
289292
item.android.position = "actionBar";
290293
menuItem.setActionView(item.actionView.android);
291294
ActionBar._setOnClickListener(item);
@@ -376,7 +379,7 @@ export class ActionBar extends ActionBarBase {
376379
}
377380

378381
// Fallback to hardcoded falue if we don't find TextView instance...
379-
// using new TextView().getTextColors().getDefaultColor() returns different value: -1979711488
382+
// using new TextView().getTextColors().getDefaultColor() returns different value: -1979711488
380383
defaultTitleTextColor = tv ? tv.getTextColors().getDefaultColor() : -570425344;
381384
}
382385

@@ -468,4 +471,4 @@ function getIconVisibility(iconVisibility: string): boolean {
468471

469472
function getSystemResourceId(systemIcon: string): number {
470473
return android.content.res.Resources.getSystem().getIdentifier(systemIcon, "drawable", "android");
471-
}
474+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy