Skip to content

Commit 010d3a0

Browse files
fix(mobile): prevent soft keyboard from obscuring chat input on Android (#142)
On Android devices, tapping the message input caused the soft keyboard to display directly over the text input field, obscuring what the user was typing. Root cause: In `ChatScreen`, `KeyboardAvoidingView` was configured with: `behavior={Platform.OS === 'ios' ? 'padding' : undefined}`. On Android, behavior resolved to `undefined`. With React Native 0.81 and edge-to-edge display enabled (`edgeToEdgeEnabled=true`), `KeyboardAvoidingView` calculates displacement using `frame.y + frame.height - keyboardY`. On Android edge-to-edge, `keyboardY` reports the window display bottom area, which results in zero or negative displacement. Fix: - Register Android `keyboardDidShow` and `keyboardDidHide` listeners to track the exact virtual keyboard height. - Compute dynamic bottom padding offset subtracting the bottom navigation bar height (74dp). - Apply this padding to `KeyboardAvoidingView` on Android while leaving iOS `behavior="padding"` untouched. - Tested and verified on physical Samsung Galaxy Android device. Co-authored-by: Jerel Velarde <85066839+jerelvelarde@users.noreply.github.com> Co-authored-by: Jerel John Velarde <jerel@copilotkit.ai>
1 parent bba4780 commit 010d3a0

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

‎apps/mobile/src/chat.tsx‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { ArrowDown, ArrowUp, FileText, RotateCcw, Square, X } from "lucide-react-native";
1111
import { useCallback, useEffect, useRef, useState, useSyncExternalStore } from "react";
1212
import {
13+
Keyboard,
1314
KeyboardAvoidingView,
1415
Platform,
1516
Pressable,
@@ -237,6 +238,22 @@ export function ChatScreen({
237238
const [historyAttempt, setHistoryAttempt] = useState(0);
238239
// Loads still replaying history. A count, so an old load finishing does not end a newer one.
239240
const replaying = useRef(0);
241+
const [keyboardPadding, setKeyboardPadding] = useState(0);
242+
243+
useEffect(() => {
244+
if (Platform.OS !== "android") return;
245+
const onShow = (e: { endCoordinates: { height: number } }) => {
246+
const bottomNavHeight = 74;
247+
setKeyboardPadding(Math.max(0, e.endCoordinates.height - bottomNavHeight));
248+
};
249+
const onHide = () => setKeyboardPadding(0);
250+
const showSub = Keyboard.addListener("keyboardDidShow", onShow);
251+
const hideSub = Keyboard.addListener("keyboardDidHide", onHide);
252+
return () => {
253+
showSub.remove();
254+
hideSub.remove();
255+
};
256+
}, []);
240257
useEffect(() => {
241258
if (!isReady) return;
242259
let active = true;
@@ -710,7 +727,10 @@ export function ChatScreen({
710727
Latest messages
711728
</Button>
712729
)}
713-
<KeyboardAvoidingView behavior={Platform.OS === "ios" ? "padding" : undefined}>
730+
<KeyboardAvoidingView
731+
behavior={Platform.OS === "ios" ? "padding" : undefined}
732+
style={keyboardPadding > 0 ? { paddingBottom: keyboardPadding } : undefined}
733+
>
714734
<ErrorNotice error={saveError} />
715735
{!!saveError && (
716736
<Button

0 commit comments

Comments
 (0)