Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tabSemanticsLabel to CupertinoLocalizations #55336

Merged
merged 15 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions packages/flutter/lib/src/cupertino/bottom_tab_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:ui' show ImageFilter;
import 'package:flutter/widgets.dart';

import 'colors.dart';
import 'localizations.dart';
import 'theme.dart';

// Standard iOS 10 tab bar height.
Expand Down Expand Up @@ -178,10 +179,13 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
style: CupertinoTheme.of(context).textTheme.tabLabelTextStyle.copyWith(color: inactive),
child: Padding(
padding: EdgeInsets.only(bottom: bottomPadding),
child: Row(
// Align bottom since we want the labels to be aligned.
crossAxisAlignment: CrossAxisAlignment.end,
children: _buildTabItems(context),
child: Semantics(
explicitChildNodes: true,
child:Row(
Piinks marked this conversation as resolved.
Show resolved Hide resolved
// Align bottom since we want the labels to be aligned.
crossAxisAlignment: CrossAxisAlignment.end,
children: _buildTabItems(context),
),
),
),
),
Expand All @@ -204,6 +208,7 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {

List<Widget> _buildTabItems(BuildContext context) {
final List<Widget> result = <Widget>[];
final CupertinoLocalizations localizations = CupertinoLocalizations.of(context);

for (int index = 0; index < items.length; index += 1) {
final bool active = index == currentIndex;
Expand All @@ -213,8 +218,10 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
Expanded(
child: Semantics(
selected: active,
// TODO(xster): This needs localization support. https://github.com/flutter/flutter/issues/13452
hint: 'tab, ${index + 1} of ${items.length}',
hint: localizations.tabLabel(
tabIndex: index + 1,
tabCount: items.length,
),
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap == null ? null : () { onTap(index); },
Expand Down
15 changes: 15 additions & 0 deletions packages/flutter/lib/src/cupertino/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ abstract class CupertinoLocalizations {
// The global version uses the translated string from the arb file.
String get alertDialogLabel;

/// The accessibility label used on a tab in a [CupertinoTabBar].
///
/// This message describes the index of the selected tab and how many tabs
/// there are, e.g. 'tab, 1 of 2' in United States English.
///
/// `tabIndex` and `tabCount` must be greater than or equal to one.
String tabLabel({int tabIndex, int tabCount});
Piinks marked this conversation as resolved.
Show resolved Hide resolved

/// Hour that is shown in [CupertinoTimerPicker] corresponding to
/// the given hour value.
///
Expand Down Expand Up @@ -348,6 +356,13 @@ class DefaultCupertinoLocalizations implements CupertinoLocalizations {
@override
String get alertDialogLabel => 'Alert';

@override
String tabLabel({int tabIndex, int tabCount}) {
assert(tabIndex >= 1);
assert(tabCount >= 1);
return 'tab, $tabIndex of $tabCount';
}

@override
String timerPickerHour(int hour) => hour.toString();

Expand Down
13 changes: 10 additions & 3 deletions packages/flutter/test/cupertino/bottom_tab_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ import '../widgets/semantics_tester.dart';

Future<void> pumpWidgetWithBoilerplate(WidgetTester tester, Widget widget) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: widget,
Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
DefaultWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
child: Directionality(
textDirection: TextDirection.ltr,
child: widget,
),
),
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add one test for the semantics content of the tabs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a test for that which was checking the value of the hard-coded string, now it is checking the localized result. :)

testWidgets('tabs announce semantics', (WidgetTester tester) async {

Expand Down
25 changes: 16 additions & 9 deletions packages/flutter/test/cupertino/tab_scaffold_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,22 @@ void main() {
});

testWidgets('Tab contents bottom padding are not consumed by viewInsets when resizeToAvoidBottomInset overriden', (WidgetTester tester) async {
final Widget child = Directionality(
textDirection: TextDirection.ltr,
child: CupertinoTabScaffold(
resizeToAvoidBottomInset: false,
tabBar: _buildTabBar(),
tabBuilder: (BuildContext context, int index) {
return const Placeholder();
},
),
final Widget child = Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
DefaultWidgetsLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
],
child: Directionality(
textDirection: TextDirection.ltr,
child: CupertinoTabScaffold(
resizeToAvoidBottomInset: false,
tabBar: _buildTabBar(),
tabBuilder: (BuildContext context, int index) {
return const Placeholder();
},
),
)
Piinks marked this conversation as resolved.
Show resolved Hide resolved
);

await tester.pumpWidget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ abstract class GlobalCupertinoLocalizations implements CupertinoLocalizations {
}
}

/// The raw version of [tabLabel], with `$tabIndex` and `$tabCount` verbatim
/// in the string.
@protected
String get tabLabelRaw;

@override
String tabLabel({ int tabIndex, int tabCount }) {
assert(tabIndex >= 1);
assert(tabCount >= 1);
final String template = tabLabelRaw;
return template
.replaceFirst(r'$tabIndex', _decimalFormat.format(tabIndex))
.replaceFirst(r'$tabCount', _decimalFormat.format(tabCount));
}

@override
String timerPickerHour(int hour) {
return _singleDigitHourFormat.format(DateTime.utc(0, 0, 0, hour));
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_af.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Knip",
"copyButtonLabel": "Kopieer",
"pasteButtonLabel": "Plak",
"selectAllButtonLabel": "Kies alles"
"selectAllButtonLabel": "Kies alles",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_am.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "ቁረጥ",
"copyButtonLabel": "ቅዳ",
"pasteButtonLabel": "ለጥፍ",
"selectAllButtonLabel": "ሁሉንም ምረጥ"
"selectAllButtonLabel": "ሁሉንም ምረጥ",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_ar.arb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"cutButtonLabel": "قص",
"copyButtonLabel": "نسخ",
"pasteButtonLabel": "لصق",
"selectAllButtonLabel": "اختيار الكل"
"selectAllButtonLabel": "اختيار الكل",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_as.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "কাট কৰক",
"copyButtonLabel": "প্ৰতিলিপি কৰক",
"pasteButtonLabel": "পে'ষ্ট কৰক",
"selectAllButtonLabel": "সকলো বাছনি কৰক"
"selectAllButtonLabel": "সকলো বাছনি কৰক",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_az.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Kəsin",
"copyButtonLabel": "Kopyalayın",
"pasteButtonLabel": "Yerləşdirin",
"selectAllButtonLabel": "Hamısını seçin"
"selectAllButtonLabel": "Hamısını seçin",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_be.arb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"cutButtonLabel": "Выразаць",
"copyButtonLabel": "Капіраваць",
"pasteButtonLabel": "Уставіць",
"selectAllButtonLabel": "Выбраць усе"
"selectAllButtonLabel": "Выбраць усе",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_bg.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Изрязване",
"copyButtonLabel": "Копиране",
"pasteButtonLabel": "Поставяне",
"selectAllButtonLabel": "Избиране на всички"
"selectAllButtonLabel": "Избиране на всички",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_bn.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "কাট করুন",
"copyButtonLabel": "কপি করুন",
"pasteButtonLabel": "পেস্ট করুন",
"selectAllButtonLabel": "সব বেছে নিন"
"selectAllButtonLabel": "সব বেছে নিন",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_bs.arb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"cutButtonLabel": "Izreži",
"copyButtonLabel": "Kopiraj",
"pasteButtonLabel": "Zalijepi",
"selectAllButtonLabel": "Odaberi sve"
"selectAllButtonLabel": "Odaberi sve",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_ca.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Retalla",
"copyButtonLabel": "Copia",
"pasteButtonLabel": "Enganxa",
"selectAllButtonLabel": "Selecciona-ho tot"
"selectAllButtonLabel": "Selecciona-ho tot",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_cs.arb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"cutButtonLabel": "Vyjmout",
"copyButtonLabel": "Kopírovat",
"pasteButtonLabel": "Vložit",
"selectAllButtonLabel": "Vybrat vše"
"selectAllButtonLabel": "Vybrat vše",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_da.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Klip",
"copyButtonLabel": "Kopiér",
"pasteButtonLabel": "Sæt ind",
"selectAllButtonLabel": "Vælg alle"
"selectAllButtonLabel": "Vælg alle",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Ausschneiden",
"copyButtonLabel": "Kopieren",
"pasteButtonLabel": "Einsetzen",
"selectAllButtonLabel": "Alles auswählen"
"selectAllButtonLabel": "Alles auswählen",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_el.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Αποκοπή",
"copyButtonLabel": "Αντιγραφή",
"pasteButtonLabel": "Επικόλληση",
"selectAllButtonLabel": "Επιλογή όλων"
"selectAllButtonLabel": "Επιλογή όλων",
"tabLabel": "TBD"
}
6 changes: 6 additions & 0 deletions packages/flutter_localizations/lib/src/l10n/cupertino_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
"description": "The accessibility audio announcement made when an iOS style alert dialog is opened."
},

"tabLabel": "tab, $tabIndex of $tabCount",
"@tabLabel": {
"description": "The accessibility label used on a tab. This message describes the index of the selected tab and how many tabs there are, e.g. 'Tab 1 of 2'. All values are greater than or equal to one.",
"parameters": "tabIndex, tabCount"
},

"timerPickerHourLabelOne": "hour",
"timerPickerHourLabelOther": "hours",
"@timerPickerHourLabel": {
Expand Down
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Cortar",
"copyButtonLabel": "Copiar",
"pasteButtonLabel": "Pegar",
"selectAllButtonLabel": "Seleccionar todos"
"selectAllButtonLabel": "Seleccionar todos",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_et.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Lõika",
"copyButtonLabel": "Kopeeri",
"pasteButtonLabel": "Kleebi",
"selectAllButtonLabel": "Vali kõik"
"selectAllButtonLabel": "Vali kõik",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_eu.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Ebaki",
"copyButtonLabel": "Kopiatu",
"pasteButtonLabel": "Itsatsi",
"selectAllButtonLabel": "Hautatu guztiak"
"selectAllButtonLabel": "Hautatu guztiak",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_fa.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "برش",
"copyButtonLabel": "کپی",
"pasteButtonLabel": "جای‌گذاری",
"selectAllButtonLabel": "انتخاب همه"
"selectAllButtonLabel": "انتخاب همه",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_fi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Leikkaa",
"copyButtonLabel": "Kopioi",
"pasteButtonLabel": "Liitä",
"selectAllButtonLabel": "Valitse kaikki"
"selectAllButtonLabel": "Valitse kaikki",
"tabLabel": "TBD"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "I-cut",
"copyButtonLabel": "Kopyahin",
"pasteButtonLabel": "I-paste",
"selectAllButtonLabel": "Piliin Lahat"
"selectAllButtonLabel": "Piliin Lahat",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Couper",
"copyButtonLabel": "Copier",
"pasteButtonLabel": "Coller",
"selectAllButtonLabel": "Tout sélect."
"selectAllButtonLabel": "Tout sélect.",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_gl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Cortar",
"copyButtonLabel": "Copiar",
"pasteButtonLabel": "Pegar",
"selectAllButtonLabel": "Seleccionar todo"
"selectAllButtonLabel": "Seleccionar todo",
"tabLabel": "TBD"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Ausschneiden",
"copyButtonLabel": "Kopieren",
"pasteButtonLabel": "Einsetzen",
"selectAllButtonLabel": "Alles auswählen"
"selectAllButtonLabel": "Alles auswählen",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_gu.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "કાપો",
"copyButtonLabel": "કૉપિ કરો",
"pasteButtonLabel": "પેસ્ટ કરો",
"selectAllButtonLabel": "બધા પસંદ કરો"
"selectAllButtonLabel": "બધા પસંદ કરો",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_he.arb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
"cutButtonLabel": "גזירה",
"copyButtonLabel": "העתקה",
"pasteButtonLabel": "הדבקה",
"selectAllButtonLabel": "בחירת הכול"
"selectAllButtonLabel": "בחירת הכול",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_hi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "काटें",
"copyButtonLabel": "कॉपी करें",
"pasteButtonLabel": "चिपकाएं",
"selectAllButtonLabel": "सभी चुनें"
"selectAllButtonLabel": "सभी चुनें",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_hr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"cutButtonLabel": "Izreži",
"copyButtonLabel": "Kopiraj",
"pasteButtonLabel": "Zalijepi",
"selectAllButtonLabel": "Odaberi sve"
"selectAllButtonLabel": "Odaberi sve",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_hu.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Kivágás",
"copyButtonLabel": "Másolás",
"pasteButtonLabel": "Beillesztés",
"selectAllButtonLabel": "Összes kijelölése"
"selectAllButtonLabel": "Összes kijelölése",
"tabLabel": "TBD"
}
3 changes: 2 additions & 1 deletion packages/flutter_localizations/lib/src/l10n/cupertino_hy.arb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"cutButtonLabel": "Կտրել",
"copyButtonLabel": "Պատճենել",
"pasteButtonLabel": "Տեղադրել",
"selectAllButtonLabel": "Նշել բոլորը"
"selectAllButtonLabel": "Նշել բոլորը",
"tabLabel": "TBD"
}
Loading