Improve handling of certain icons in RTL (#130979)

Fixes https://github.com/flutter/flutter/issues/130978 

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
Pierre-Louis
2023-07-21 19:07:39 +02:00
committed by GitHub
parent 9cfbf6b9fd
commit 0919fb86f1
3 changed files with 84 additions and 25 deletions

View File

@@ -61,4 +61,61 @@ void main() {
'Icon(Icons.onetwothree_rounded),',
);
});
test('certain icons should be mirrored in RTL', () {
// Exact match
expect(
Icon(const MapEntry<String, String>('help', '')).isMirroredInRTL,
true,
);
// Variant
expect(
Icon(const MapEntry<String, String>('help_rounded', '')).isMirroredInRTL,
true,
);
// Common suffixes
expect(
Icon(const MapEntry<String, String>('help_alt', '')).isMirroredInRTL,
true,
);
expect(
Icon(const MapEntry<String, String>('help_new', '')).isMirroredInRTL,
true,
);
expect(
Icon(const MapEntry<String, String>('help_off', '')).isMirroredInRTL,
true,
);
expect(
Icon(const MapEntry<String, String>('help_on', '')).isMirroredInRTL,
true,
);
// Common suffixes + variant
expect(
Icon(const MapEntry<String, String>('help_alt_rounded', '')).isMirroredInRTL,
true,
);
expect(
Icon(const MapEntry<String, String>('help_new_rounded', '')).isMirroredInRTL,
true,
);
expect(
Icon(const MapEntry<String, String>('help_off_rounded', '')).isMirroredInRTL,
true,
);
expect(
Icon(const MapEntry<String, String>('help_on_rounded', '')).isMirroredInRTL,
true,
);
// No match
expect(
Icon(const MapEntry<String, String>('help_center_rounded', '')).isMirroredInRTL,
false,
);
// No match
expect(
Icon(const MapEntry<String, String>('arrow', '')).isMirroredInRTL,
false,
);
});
}

View File

@@ -150,7 +150,7 @@ const Set<String> _iconsMirroredWhenRTL = <String>{
'navigate_next',
'next_week',
'note',
'open_in_new',
'open_in',
'playlist_add',
'queue_music',
'redo',
@@ -513,12 +513,14 @@ class Icon {
String get usage => 'Icon($className.$flutterId),';
String get mirroredInRTL => _iconsMirroredWhenRTL.contains(shortId)
? ', matchTextDirection: true'
: '';
bool get isMirroredInRTL {
// Remove common suffixes (e.g. "_new" or "_alt") from the shortId.
final String normalizedShortId = shortId.replaceAll(RegExp(r'_(new|alt|off|on)$'), '');
return _iconsMirroredWhenRTL.any((String shortIdMirroredWhenRTL) => normalizedShortId == shortIdMirroredWhenRTL);
}
String get declaration =>
"static const IconData $flutterId = IconData(0x$hexCodepoint, fontFamily: '$fontFamily'$mirroredInRTL);";
"static const IconData $flutterId = IconData(0x$hexCodepoint, fontFamily: '$fontFamily'${isMirroredInRTL ? ', matchTextDirection: true' : ''});";
String get fullDeclaration => '''