Skip to content

列車種別ボックスをreact-native-svgで実装し直し - #5729

Merged
TinyKitten merged 1 commit into
devfrom
feature/svg-train-type-boxes
Mar 30, 2026
Merged

TinyKitten merged 1 commit into
devfrom
feature/svg-train-type-boxes

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 30, 2026 •

Copy link
Copy Markdown
Member

Summary

  • TrainTypeBoxE231/JO/JLの描画をreact-native-svgベースに置き換え、iOS/Android間の描画差異を解消
  • E231: 8方向オフセットによる擬似ストロークをSVG stroke/fill 2レイヤー方式に変更
  • JO/JL: RN transform: skewX(Androidで無視される)をSVG <G transform="skewX(...)"> に変更
  • 日本語文字の均等配置をflex space-evenlyからSVGパーセンテージ座標に変更
  • 長い列車種別名(Saphir Odoriko等)の自動フォントサイズ調整をonLayoutベースで再実装

Test plan

  • E231テーマ: 日本語/英語/中国語/韓国語の各言語で列車種別表示を確認
  • E231テーマ: enOverride(中央特快、通勤快速等)の2行表示を確認
  • JOテーマ: 日本語文字の均等配置とskew表示を確認
  • JOテーマ: 長い英語列車種別名(Saphir Odoriko等)が収まることを確認
  • JLテーマ: 同上
  • Android実機/エミュレータでskewが正しく適用されることを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • 新機能

    • LEDテーマと通常テーマに対応した列車タイプ表示の改善
  • スタイル

    • 列車タイプボックスのテキストレンダリング精度向上。複数の列車種別表示コンポーネントの表示ロジックを統一し、テーマ切り替え時の一貫性を強化

@github-actions github-actions Bot added the react label Mar 30, 2026
@coderabbitai

coderabbitai Bot commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

3つの訓練型ボックスコンポーネント(TrainTypeBoxE231、TrainTypeBoxJL、TrainTypeBoxJO)がReact NativeのTypographyベースのレンダリングからSVGベースのレンダリング実装に移行されました。テーマ依存のフォント選択とダイナミックなサイズ調整機能が追加されています。

Changes

Cohort / File(s) Summary
SVG Text Pipeline Migration
src/components/TrainTypeBoxE231.tsx, src/components/TrainTypeBoxJL.tsx, src/components/TrainTypeBoxJO.tsx
Typography コンポーネントベースのテキストレンダリングを react-native-svg の Svg、G、SvgText を使用したSVGベースの実装に置き換え。theme依存フォント選択(isLEDThemeAtom)、動的フォントサイズ調整、レイアウト測定、カスタムベースライン配置を導入。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰✨ Typography から SVG へ、
三つのコンポーネント美しく変身、
LED テーマが光り輝き、
テキストは正確に配置され、
描画パイプライン、ウサギも喜ぶ!🎨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed PRタイトルは、3つのコンポーネント(TrainTypeBoxE231/JO/JL)のreact-native-svg への置き換えという主要な変更を正確に反映しており、簡潔で明確です。
Description check ✅ Passed PR説明は概要、変更の詳細、テスト計画を含みテンプレートの主要セクションを満たしていますが、「変更の種類」チェックボックスが未記入で、「CI/CD」セクションのテスト項目が不完全です。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/svg-train-type-boxes

Comment @coderabbitai help to get the list of available commands and usage tips.

@TinyKitten TinyKitten self-assigned this Mar 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/components/TrainTypeBoxE231.tsx (1)

288-321: キーの重複可能性に注意

key={s_${text}} および key={f_${text}} は、同じテキストが複数行に含まれる場合にキーの重複を引き起こす可能性があります。現在の使用パターン(enOverrideのheading/bodyや単一行テキスト)では問題ないと思われますが、将来の拡張を考慮するとインデックスを含めた方が安全です。

♻️ 修正案
-          <SvgText
-            key={`s_${text}`}
+          <SvgText
+            key={`s_${i}_${text}`}
-          <SvgText
-            key={`f_${text}`}
+          <SvgText
+            key={`f_${i}_${text}`}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/TrainTypeBoxE231.tsx` around lines 288 - 321, The keys for the
two SvgText maps use only text (key={`s_${text}`} and key={`f_${text}`}) which
can collide when identical text appears on multiple lines; update the key
generation in the lines.map calls (the SvgText elements inside TrainTypeBoxE231)
to include the index (i) or another unique identifier (e.g.,
key={`s_${i}_${text}`} and key={`f_${i}_${text}`}) so each SvgText rendered by
the first and second map is guaranteed unique.
src/components/TrainTypeBoxJL.tsx (1)

21-27: TrainTypeBoxJOとの共通コードの抽出を検討

BOX_HEIGHT、FONT_SIZE、SKEW_ANGLE、SKEW_SHIFT、SKEW_TRANSFORMの定数、およびfontFamily/fontWeightロジック、adjustedFontSize計算がTrainTypeBoxJOとほぼ同一です。将来のメンテナンス性向上のため、共通ユーティリティまたはカスタムフックへの抽出を検討してもよいかもしれません。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/TrainTypeBoxJL.tsx` around lines 21 - 27,
TrainTypeBoxJL内のBOX_HEIGHT、FONT_SIZE、SKEW_ANGLE、SKEW_SHIFT、SKEW_TRANSFORMとfontFamily
/
fontWeightロジック、adjustedFontSizeの計算はTrainTypeBoxJOと重複しているので、共通のユーティリティ関数またはカスタムフック(例:
useTrainTypeBoxStyles)を作成してこれらの定数と計算ロジックを移動してください;
新しい関数はデバイス判定(isTablet)を受け取りBOX_HEIGHT, FONT_SIZE, SKEW_*
値、SKEW_TRANSFORM文字列、fontFamily/fontWeight、そしてadjustedFontSizeを返すようにして、TrainTypeBoxJLとTrainTypeBoxJOからそれを呼び出すように差し替えて重複を削除してください.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/TrainTypeBoxJL.tsx`:
- Around line 155-183: The Japanese-character branch in TrainTypeBoxJL (the
chars.map block rendering SvgText) is missing the fontFamily prop and uses
fontWeight inconsistently: add fontFamily={fontFamily} to the SvgText in the
chars branch so the LED theme font is applied (mirror TrainTypeBoxJO), and
replace the hardcoded fontWeight="bold" in the fallback branch with
fontWeight={fontWeight} so both branches use the same fontWeight variable; keep
other props (x, y, fontSize/adjustedFontSize, fill, textAnchor,
alignmentBaseline) unchanged.

In `@src/components/TrainTypeBoxJO.tsx`:
- Around line 159-186: The Japanese-characters branch inside the chars.map
rendering (SvgText instances at lines showing the chars map) omits fontFamily
and the non-Japanese branch hardcodes fontWeight="bold"; update the chars branch
to include fontFamily={fontFamily} so JFDotJiskan24h can apply, and make the
non-Japanese SvgText use the computed fontWeight variable (fontWeight) instead
of the hardcoded "bold" so both branches use consistent weight logic; keep
existing fontSize/adjustedFontSize usage and other props (x, y, fill,
textAnchor, alignmentBaseline, children).

---

Nitpick comments:
In `@src/components/TrainTypeBoxE231.tsx`:
- Around line 288-321: The keys for the two SvgText maps use only text
(key={`s_${text}`} and key={`f_${text}`}) which can collide when identical text
appears on multiple lines; update the key generation in the lines.map calls (the
SvgText elements inside TrainTypeBoxE231) to include the index (i) or another
unique identifier (e.g., key={`s_${i}_${text}`} and key={`f_${i}_${text}`}) so
each SvgText rendered by the first and second map is guaranteed unique.

In `@src/components/TrainTypeBoxJL.tsx`:
- Around line 21-27:
TrainTypeBoxJL内のBOX_HEIGHT、FONT_SIZE、SKEW_ANGLE、SKEW_SHIFT、SKEW_TRANSFORMとfontFamily
/
fontWeightロジック、adjustedFontSizeの計算はTrainTypeBoxJOと重複しているので、共通のユーティリティ関数またはカスタムフック(例:
useTrainTypeBoxStyles)を作成してこれらの定数と計算ロジックを移動してください;
新しい関数はデバイス判定(isTablet)を受け取りBOX_HEIGHT, FONT_SIZE, SKEW_*
値、SKEW_TRANSFORM文字列、fontFamily/fontWeight、そしてadjustedFontSizeを返すようにして、TrainTypeBoxJLとTrainTypeBoxJOからそれを呼び出すように差し替えて重複を削除してください.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05aabb51-a64c-4778-a313-389e8c4626ba

📥 Commits

Reviewing files that changed from the base of the PR and between e22eaa4 and 3f85a73.

📒 Files selected for processing (3)
  • src/components/TrainTypeBoxE231.tsx
  • src/components/TrainTypeBoxJL.tsx
  • src/components/TrainTypeBoxJO.tsx

Comment thread src/components/TrainTypeBoxJL.tsx Resolved
Comment thread src/components/TrainTypeBoxJO.tsx Resolved
@TinyKitten
TinyKitten merged commit cb9418f into dev Mar 30, 2026
6 checks passed
@TinyKitten
TinyKitten deleted the feature/svg-train-type-boxes branch March 30, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant