Skip to content

エッジトゥエッジのAndroidでAIチャットの入力欄がキーボードに隠れる問題を修正 - #6603

Merged
TinyKitten merged 2 commits into
devfrom
claude/keyboard-avoiding-view-pixel-9a-dtv2tl
Aug 8, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/keyboard-avoiding-view-pixel-9a-dtv2tl

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

概要

Pixel 9a (Android 17) で AI に行き先を相談する画面のキーボード表示時、入力バーがキーボードに覆われて見えなくなる不具合を修正します。

原因は KeyboardAvoidingView の設定ではなく、エッジトゥエッジ環境 (edgeToEdgeEnabled=true) の Android では KeyboardAvoidingView そのものが機能しないことでした。

  • エッジトゥエッジでは android:windowSoftInputMode="adjustResize" を指定してもウィンドウが縮まない。
  • そのため ReactRootView.checkForKeyboardEvents() が送る endCoordinates.screenY は常に画面下端のままになる。
  • KeyboardAvoidingView._relativeKeyboardHeight() は frame.y + frame.height - screenY を押し上げ量とするため、結果が常に 0 になり behavior に何を渡しても効かない(Android は undefined を渡していたため二重に効いていなかった)。
  • 一方で endCoordinates.height は imeInsets.bottom - barInsets.bottom として正しく届くので、これを起点に下余白を組み立てる方式へ変更しました。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • src/hooks/useKeyboardBottomInset.ts を追加。キーボードイベントから画面下端に確保すべき余白・追従アニメーション時間・表示状態を返す。
    • Android は keyboardDidShow / keyboardDidHide を購読し、endCoordinates.height(ナビゲーションバー分を除いた IME 高さ)に useSafeAreaInsets().bottom を足してウィンドウ下端からの重なり量へ戻す。did 系イベントは IME の遷移後に届きうるため、追従アニメーションは行わず即座に確定させる(duration: 0)。
    • iOS は keyboardWillShow / keyboardWillHide を購読。endCoordinates.height はホームインジケータ領域を含むため加算せず、イベントの duration をそのまま使う(0 で届いた場合は 250ms にフォールバック)。
    • キーボード非表示時は useSafeAreaInsets().bottom を返すため、従来の下端余白の挙動は据え置き。
  • src/screens/DestinationAgent/index.tsx から KeyboardAvoidingView を削除し、入力バーのコンテナを Animated.View にして withTiming で paddingBottom を追従させる。
  • あわせて、キーボード表示でリストの表示領域が縮んだ際に末尾のメッセージがキーボードの裏へ隠れないよう追従スクロールを追加。
  • src/hooks/useKeyboardBottomInset.test.ts を追加。iOS / Android 双方の余白計算、購読するイベント名、duration の解決、リスナ解除を検証(9 ケース)。
  • docs/spec/ai-agent/ui.md の入力バー仕様を実装に合わせて更新し、KeyboardAvoidingView を使わない理由を記録。

回帰リスクと緩和

  • 影響範囲は AI 相談画面 (DestinationAgent) のみ。他画面のキーボード挙動には触れていません。
  • iOS は従来 behavior="padding" で入力バーを持ち上げていましたが、入力バーは画面最下部にあるため押し上げ量は「キーボード高さ」と一致し、新実装と等価です。キーボード非表示時の余白も従来どおり insets.bottom + 8 を維持しています。
  • Android の duration: 0 は、RN のイベントが IME 遷移の開始時に届く場合でも終了後に届く場合でも「入力欄が隠れている時間が最短」になる選択です。実機で入力バーの先行移動が気になる場合は短い値への調整余地があります。
  • 同じ理由で src/components/CustomModal.tsx の avoidKeyboard(SavePresetNameModal / NewReportModal)も Android では効いていないと考えられますが、本 PR のスコープ外としています。必要であれば同じフックを流用して別途対応します。

テスト

ローカルで以下を実行し、いずれも成功することを確認しています(npm test: 213 suites / 2237 tests all pass)。

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

スクリーンショット(任意)

実機・エミュレータを操作できない環境で作業したため、スクリーンショット / 録画は未添付です。マージ前に報告端末である Pixel 9a (Android 17) での目視確認をお願いします。

@TinyKitten TinyKitten self-assigned this Aug 8, 2026
@github-actions github-actions Bot added the react label Aug 8, 2026
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

useKeyboardBottomInset を追加し、iOS と Android のキーボードイベントから下端余白を計算します。DestinationAgentScreen は入力バーをアニメーション移動し、キーボード表示時にメッセージ末尾へスクロールします。

Changes

キーボード追従フロー

Layer / File(s) Summary
キーボード下端インセットの実装と検証
src/hooks/useKeyboardBottomInset.ts, src/hooks/useKeyboardBottomInset.test.ts
useKeyboardBottomInset が iOS の will 系イベントと Android の did 系イベントを購読します。安全領域、キーボード高さ、アニメーション時間、表示状態を返します。テストはイベント処理と購読解除を検証します。
DestinationAgent への入力バー統合
src/screens/DestinationAgent/index.tsx, docs/spec/ai-agent/ui.md
KeyboardAvoidingView を削除し、Animated.View と withTiming で入力バーを移動します。キーボード表示時はメッセージ末尾へスクロールします。UI 仕様を更新します。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Keyboard
  participant useKeyboardBottomInset
  participant DestinationAgentScreen
  participant MessageList
  Keyboard->>useKeyboardBottomInset: キーボード表示イベント
  useKeyboardBottomInset->>DestinationAgentScreen: 下端インセットとアニメーション時間
  DestinationAgentScreen->>MessageList: メッセージ末尾へスクロール
  DestinationAgentScreen->>DestinationAgentScreen: 入力バーをアニメーション移動
Loading

Possibly related PRs

Poem

うさぎが跳ねて、入力欄はふわり
キーボード来ても、隠れずすっきり
末尾へメッセージ、ぴょんと追従
安全領域も、そっと確保
新しいフックで、月まで届く

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed タイトルは、エッジトゥエッジのAndroidでAIチャットの入力欄がキーボードに隠れる問題の修正を明確に示しています。
Description check ✅ Passed 概要、変更内容、テスト結果、回帰リスク、関連Issue、スクリーンショットの説明があり、テンプレートの必須項目を満たしています。
✨ 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 claude/keyboard-avoiding-view-pixel-9a-dtv2tl

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

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/hooks/useKeyboardBottomInset.test.ts`:
- Around line 74-87: Extend the iOS keyboardWillShow coverage in the test around
loadHook and emit to pass a keyboard event with duration 0, then assert
result.current.duration uses the 250ms IOS_FALLBACK_ANIMATION_DURATION fallback.
Keep the existing nonzero-duration assertion unchanged.

In `@src/hooks/useKeyboardBottomInset.ts`:
- Around line 39-42: Update resolveDuration in
src/hooks/useKeyboardBottomInset.ts:39-42 to return 0 for Android
keyboardDidShow/keyboardDidHide events while preserving the existing iOS
duration fallback. Add or update the Android duration assertion in
src/hooks/useKeyboardBottomInset.test.ts:121-128 to verify 0. No direct change
is required in src/screens/DestinationAgent/index.tsx:234-240.
🪄 Autofix

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: 395d9ae8-e662-4ff2-8e75-85a065d63dd3

📥 Commits

Reviewing files that changed from the base of the PR and between 11ec7e2 and 21bef19.

📒 Files selected for processing (4)
  • docs/spec/ai-agent/ui.md
  • src/hooks/useKeyboardBottomInset.test.ts
  • src/hooks/useKeyboardBottomInset.ts
  • src/screens/DestinationAgent/index.tsx

Comment thread src/hooks/useKeyboardBottomInset.ts Resolved
@TinyKitten
TinyKitten merged commit f080928 into dev Aug 8, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/keyboard-avoiding-view-pixel-9a-dtv2tl branch August 8, 2026 12:57
This was referenced Aug 8, 2026
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.

2 participants