Skip to content

Commit 5147ad5

Browse files
committed
Add matchTextDirection to directional icons
Fixes #1907 We update the icon generation script to automatically set matchTextDirection: true for icons that imply directionality (arrow_right, chevron_right, send). This ensures these icons flip correctly in RTL locales. We also update the documentation within the generation script to instruct future contributors on how to handle new directional icons.
1 parent 9296fb3 commit 5147ad5

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

assets/icons/directional_icons.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//List of icons that should flip horizontally in RTL layout.
2+
3+
4+
module.exports = [
5+
"arrow_right",
6+
"chevron_right",
7+
"send",
8+
"arrow_left_right",
9+
"message_feed",
10+
"topics"
11+
]

lib/widgets/icons.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ abstract final class ZulipIcons {
1818
// or otherwise edit the SVG files there.
1919
// The files' names (before ".svg") should be valid Dart identifiers.
2020
//
21+
// * If the icon is directional (meaning it should point
22+
// the other way in RTL layouts), add its name in
23+
// `assets/icons/directional_icons.js`. For guidance, see:
24+
// https://m3.material.io/foundations/layout/understanding-layout/bidirectionality-rtl#ad90d075-6db4-457b-a15b-51fb6653c825
25+
//
2126
// * Then run the command `tools/icons/build-icon-font`.
2227
// That will update this file and the generated icon font,
2328
// `assets/icons/ZulipIcons.ttf`.
@@ -28,10 +33,10 @@ abstract final class ZulipIcons {
2833
static const IconData arrow_down = IconData(0xf101, fontFamily: "Zulip Icons");
2934

3035
/// The Zulip custom icon "arrow_left_right".
31-
static const IconData arrow_left_right = IconData(0xf102, fontFamily: "Zulip Icons");
36+
static const IconData arrow_left_right = IconData(0xf102, fontFamily: "Zulip Icons", matchTextDirection: true);
3237

3338
/// The Zulip custom icon "arrow_right".
34-
static const IconData arrow_right = IconData(0xf103, fontFamily: "Zulip Icons");
39+
static const IconData arrow_right = IconData(0xf103, fontFamily: "Zulip Icons", matchTextDirection: true);
3540

3641
/// The Zulip custom icon "at_sign".
3742
static const IconData at_sign = IconData(0xf104, fontFamily: "Zulip Icons");
@@ -64,7 +69,7 @@ abstract final class ZulipIcons {
6469
static const IconData chevron_down = IconData(0xf10d, fontFamily: "Zulip Icons");
6570

6671
/// The Zulip custom icon "chevron_right".
67-
static const IconData chevron_right = IconData(0xf10e, fontFamily: "Zulip Icons");
72+
static const IconData chevron_right = IconData(0xf10e, fontFamily: "Zulip Icons", matchTextDirection: true);
6873

6974
/// The Zulip custom icon "circle_x".
7075
static const IconData circle_x = IconData(0xf10f, fontFamily: "Zulip Icons");
@@ -133,7 +138,7 @@ abstract final class ZulipIcons {
133138
static const IconData message_checked = IconData(0xf124, fontFamily: "Zulip Icons");
134139

135140
/// The Zulip custom icon "message_feed".
136-
static const IconData message_feed = IconData(0xf125, fontFamily: "Zulip Icons");
141+
static const IconData message_feed = IconData(0xf125, fontFamily: "Zulip Icons", matchTextDirection: true);
137142

138143
/// The Zulip custom icon "more_horizontal".
139144
static const IconData more_horizontal = IconData(0xf126, fontFamily: "Zulip Icons");
@@ -160,7 +165,7 @@ abstract final class ZulipIcons {
160165
static const IconData see_who_reacted = IconData(0xf12d, fontFamily: "Zulip Icons");
161166

162167
/// The Zulip custom icon "send".
163-
static const IconData send = IconData(0xf12e, fontFamily: "Zulip Icons");
168+
static const IconData send = IconData(0xf12e, fontFamily: "Zulip Icons", matchTextDirection: true);
164169

165170
/// The Zulip custom icon "settings".
166171
static const IconData settings = IconData(0xf12f, fontFamily: "Zulip Icons");
@@ -187,7 +192,7 @@ abstract final class ZulipIcons {
187192
static const IconData topic = IconData(0xf136, fontFamily: "Zulip Icons");
188193

189194
/// The Zulip custom icon "topics".
190-
static const IconData topics = IconData(0xf137, fontFamily: "Zulip Icons");
195+
static const IconData topics = IconData(0xf137, fontFamily: "Zulip Icons", matchTextDirection: true);
191196

192197
/// The Zulip custom icon "trash".
193198
static const IconData trash = IconData(0xf138, fontFamily: "Zulip Icons");

tools/icons/build-icon-font.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,23 @@ async function main() {
6262
fs.copyFileSync(path.join(tmpDir, `${fontName}.ttf`), path.join(destDir, `${fontFileBaseName}.ttf`));
6363

6464
const template = fs.readFileSync(dataTemplateFile, 'utf8');
65+
66+
// Icons that should flip horizontally in RTL layout.
67+
const directionalIconsFile = path.join(srcDir, 'directional_icons.js');
68+
const directionalIcons = require(directionalIconsFile);
69+
6570
const generated = Object.entries(codepoints).map(([name, codepoint]) => {
6671
const codepointHex = "0x" + codepoint.toString(16);
72+
73+
const namedParams = [`fontFamily: "${fontName}"`];
74+
if (directionalIcons.includes(name)) {
75+
namedParams.push('matchTextDirection: true');
76+
}
77+
6778
return `\
6879
6980
/// The Zulip custom icon "${name}".
70-
static const IconData ${name} = IconData(${codepointHex}, fontFamily: "${fontName}");
81+
static const IconData ${name} = IconData(${codepointHex}, ${namedParams.join(', ')});
7182
`;
7283
}).join("");
7384
const output = template.replace(

0 commit comments

Comments
 (0)