diff --git a/apps/android/src/screens/chat/expanded-composer.tsx b/apps/android/src/screens/chat/expanded-composer.tsx new file mode 100644 index 0000000..0be1152 --- /dev/null +++ b/apps/android/src/screens/chat/expanded-composer.tsx @@ -0,0 +1,192 @@ +import { ArrowUp, CircleStop } from 'lucide-react-native' +import { useEffect, useMemo, useRef } from 'react' +import { ActivityIndicator, Animated, Easing, Pressable, Text, TextInput, View } from 'react-native' +import { strings } from '../../locales/i18n' +import type { RemoteSession } from '../../types' +import { CollapseCornerIcon } from '../../ui/composer-expand-icons' +import { splitDraftSegments } from '../../ui/mention-popover' +import { formatQuoteDraftSnippet } from '../../ui/quote-helpers' +import { QuoteMarkIcon } from '../../ui/quote-preview' +import { useTheme } from '../../ui/theme-context' +import { useThemedStyles } from '../../ui/use-themed-styles' +import { easingCurve, resolveMotion } from '../../ui/motion' +import { useReduceMotion } from '../../ui/use-reduce-motion' +import { createStyles } from './styles' +import type { useChatMentions } from './use-chat-mentions' + +type BackendChatTextKeys = Record< + 'generating' | 'messageLabel' | 'placeholder' | 'policyHint', + { [Key in keyof typeof strings.chat]: typeof strings.chat[Key] extends string ? Key : never }[keyof typeof strings.chat] +> + +const BACKEND_CHAT_TEXT_KEYS: Partial> & { harness: BackendChatTextKeys } = { + harness: { generating: 'generating', messageLabel: 'messageLabel', placeholder: 'placeholder', policyHint: 'policyHint' }, + codex: { generating: 'codexGenerating', messageLabel: 'codexMessageLabel', placeholder: 'codexPlaceholder', policyHint: 'codexPolicyHint' }, + cursor: { generating: 'cursorGenerating', messageLabel: 'cursorMessageLabel', placeholder: 'cursorPlaceholder', policyHint: 'cursorPolicyHint' }, + claude: { generating: 'claudeGenerating', messageLabel: 'claudeMessageLabel', placeholder: 'claudePlaceholder', policyHint: 'claudePolicyHint' }, + hermes: { generating: 'hermesGenerating', messageLabel: 'hermesMessageLabel', placeholder: 'hermesPlaceholder', policyHint: 'hermesPolicyHint' }, + opencode: { generating: 'opencodeGenerating', messageLabel: 'opencodeMessageLabel', placeholder: 'opencodePlaceholder', policyHint: 'opencodePolicyHint' }, + pi: { generating: 'piGenerating', messageLabel: 'piMessageLabel', placeholder: 'piPlaceholder', policyHint: 'piPolicyHint' }, + antigravity: { generating: 'antigravityGenerating', messageLabel: 'antigravityMessageLabel', placeholder: 'antigravityPlaceholder', policyHint: 'antigravityPolicyHint' }, +} + +type Props = { + visible: boolean + onClose: () => void + backend: RemoteSession['backend'] + draft: string + quotes?: string[] + onRemoveQuote?: (index: number) => void + input: ReturnType + replyActive: boolean + stopping: boolean + sendDisabled: boolean + onSubmit: () => void + onStop: () => void +} + +export function ExpandedComposer({ + visible, + onClose, + backend, + draft, + quotes, + onRemoveQuote, + input, + replyActive, + stopping, + sendDisabled, + onSubmit, + onStop, +}: Props) { + const { colors } = useTheme() + const styles = useThemedStyles(createStyles) + const { selection, onChangeText, onSelectionChange } = input + const draftSegments = useMemo(() => splitDraftSegments(draft), [draft]) + const backendTextKeys = BACKEND_CHAT_TEXT_KEYS[backend ?? 'harness'] ?? BACKEND_CHAT_TEXT_KEYS.harness + const reduceMotion = useReduceMotion() + // The composer expands in place; it is the same surface growing, not a new + // screen arriving from an edge. + const entrance = useRef(new Animated.Value(1)).current + useEffect(() => { + if (!visible) return + entrance.setValue(0) + const animation = Animated.timing(entrance, { + toValue: 1, + duration: resolveMotion('fullscreen', reduceMotion).duration, + easing: Easing.bezier(...easingCurve('expand')), + useNativeDriver: true, + }) + animation.start() + return () => animation.stop() + }, [visible, entrance, reduceMotion]) + + if (!visible) { + return null + } + + return ( + + + + + [styles.expandedCollapseButton, pressed && styles.plusPressed]} + > + + + + + {quotes && quotes.length > 0 && ( + + {quotes.map((quoteText, index) => ( + onRemoveQuote?.(index)} + style={styles.composerInlineQuoteBadge} + > + + + “{formatQuoteDraftSnippet(quoteText, 18)}” + + + ))} + + )} + + + + + {draftSegments.map((segment, index) => ( + + {segment.text} + + ))} + + + + + + {replyActive && draft.trim().length === 0 ? ( + [styles.stopButton, pressed && !stopping && styles.stopPressed, stopping && styles.sendDisabled]} + > + {stopping ? ( + + ) : ( + + )} + + ) : ( + { + onSubmit() + onClose() + }} + style={({ pressed }) => [styles.sendButton, pressed && styles.sendPressed, sendDisabled && styles.sendDisabled]} + > + + + )} + + + + ) +}