import React, { useState, useCallback, useRef, useEffect } from 'react'; import { StyleSheet, View, Keyboard, Platform } from 'react-native'; import { useTheme, TextInput, IconButton } from 'react-native-paper'; export interface ChatInputProps { /** Callback with the message text when send is pressed */ onSend: (text: string) => void; /** Callback when the location-attachment button is pressed */ onSendLocation?: () => void; /** Placeholder text (default: "Type a message…") */ placeholder?: string; /** Whether input is currently disabled */ disabled?: boolean; } /** * Message input bar pinned to the bottom of a chat screen. * Features a flat TextInput, attachment button (šŸ“Ž) and send button (āž¤). */ export function ChatInput({ onSend, onSendLocation, placeholder = 'Type a message…', disabled = false, }: ChatInputProps) { const theme = useTheme(); const [text, setText] = useState(''); const inputRef = useRef(null); const handleSend = useCallback(() => { const trimmed = text.trim(); if (!trimmed) return; onSend(trimmed); setText(''); inputRef.current?.focus(); }, [text, onSend]); const onSubmitEditing = useCallback(() => { handleSend(); }, [handleSend]); // On Android, handle the hardware keyboard's "send" key const keyboardType = Platform.OS === 'android' ? 'default' : 'default'; return ( {/* Location attachment button */} {/* Text input */} 0 ? ( ) : null } /> ); } const styles = StyleSheet.create({ container: { flexDirection: 'row', alignItems: 'flex-end', paddingHorizontal: 4, paddingVertical: 4, borderTopWidth: StyleSheet.hairlineWidth, }, attachButton: { margin: 0, }, input: { flex: 1, backgroundColor: 'transparent', maxHeight: 120, marginVertical: 0, paddingHorizontal: 0, }, inputContent: { minHeight: 40, paddingTop: 8, paddingBottom: 8, }, sendIcon: { margin: 0, paddingBottom: 4, }, });