diff --git a/apps/android/src/screens/chat/expanded-composer.tsx b/apps/android/src/screens/chat/expanded-composer.tsx index 0be1152..35b990c 100644 --- a/apps/android/src/screens/chat/expanded-composer.tsx +++ b/apps/android/src/screens/chat/expanded-composer.tsx @@ -1,18 +1,19 @@ 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 { useEffect, useMemo, useRef, useState } from 'react' +import { ActivityIndicator, Animated, Easing, Pressable, StyleSheet, Text, TextInput, View } from 'react-native' import { strings } from '../../locales/i18n' import type { RemoteSession } from '../../types' import { CollapseCornerIcon } from '../../ui/composer-expand-icons' +import { triggerLightHaptic } from '../../ui/haptics' 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 { easingCurve } from '../../ui/motion' import { useReduceMotion } from '../../ui/use-reduce-motion' +import { type ComposerInputBridge } from './composer' import { createStyles } from './styles' -import type { useChatMentions } from './use-chat-mentions' type BackendChatTextKeys = Record< 'generating' | 'messageLabel' | 'placeholder' | 'policyHint', @@ -30,16 +31,20 @@ const BACKEND_CHAT_TEXT_KEYS: Partial> & { h antigravity: { generating: 'antigravityGenerating', messageLabel: 'antigravityMessageLabel', placeholder: 'antigravityPlaceholder', policyHint: 'antigravityPolicyHint' }, } -type Props = { +export type ExpandedComposerProps = { visible: boolean onClose: () => void - backend: RemoteSession['backend'] + backend?: RemoteSession['backend'] draft: string quotes?: string[] onRemoveQuote?: (index: number) => void - input: ReturnType + input: Pick + accessibilityLabel?: string + placeholder?: string + highlightMentionTokens?: boolean replyActive: boolean stopping: boolean + sending?: boolean sendDisabled: boolean onSubmit: () => void onStop: () => void @@ -53,50 +58,81 @@ export function ExpandedComposer({ quotes, onRemoveQuote, input, + accessibilityLabel, + placeholder, + highlightMentionTokens = true, replyActive, stopping, + sending = false, sendDisabled, onSubmit, onStop, -}: Props) { +}: ExpandedComposerProps) { const { colors } = useTheme() const styles = useThemedStyles(createStyles) const { selection, onChangeText, onSelectionChange } = input - const draftSegments = useMemo(() => splitDraftSegments(draft), [draft]) + const showTokenHighlight = highlightMentionTokens !== false + const draftSegments = useMemo(() => (showTokenHighlight ? splitDraftSegments(draft) : []), [draft, showTokenHighlight]) const backendTextKeys = BACKEND_CHAT_TEXT_KEYS[backend ?? 'harness'] ?? BACKEND_CHAT_TEXT_KEYS.harness + const resolvedLabel = accessibilityLabel ?? strings.chat[backendTextKeys.messageLabel] + const resolvedPlaceholder = placeholder ?? strings.chat[backendTextKeys.placeholder] 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 + const [mounted, setMounted] = useState(visible) + const entrance = useRef(new Animated.Value(visible ? 1 : 0)).current + useEffect(() => { - if (!visible) return - entrance.setValue(0) + if (visible) { + setMounted(true) + entrance.stopAnimation() + entrance.setValue(0) + const animation = Animated.timing(entrance, { + toValue: 1, + duration: reduceMotion ? 110 : 240, + easing: Easing.bezier(...easingCurve('expand')), + useNativeDriver: true, + }) + animation.start() + return () => animation.stop() + } + if (!mounted) return + entrance.stopAnimation() const animation = Animated.timing(entrance, { - toValue: 1, - duration: resolveMotion('fullscreen', reduceMotion).duration, - easing: Easing.bezier(...easingCurve('expand')), + toValue: 0, + duration: reduceMotion ? 90 : 170, + easing: Easing.bezier(...easingCurve('retreat')), useNativeDriver: true, }) - animation.start() + animation.start(({ finished }) => { + if (finished) setMounted(false) + }) return () => animation.stop() - }, [visible, entrance, reduceMotion]) + }, [visible, mounted, entrance, reduceMotion]) - if (!visible) { + if (!mounted) { return null } return ( - + + + @@ -132,25 +168,28 @@ export function ExpandedComposer({ - - {draftSegments.map((segment, index) => ( - - {segment.text} - - ))} - + {showTokenHighlight ? ( + + {draftSegments.map((segment, index) => ( + + {segment.text} + + ))} + + ) : undefined} @@ -161,7 +200,10 @@ export function ExpandedComposer({ accessibilityLabel={strings.chat.stop} accessibilityState={{ disabled: stopping, busy: stopping }} disabled={stopping} - onPress={onStop} + onPress={() => { + triggerLightHaptic() + onStop() + }} style={({ pressed }) => [styles.stopButton, pressed && !stopping && styles.stopPressed, stopping && styles.sendDisabled]} > {stopping ? ( @@ -174,15 +216,19 @@ export function ExpandedComposer({ { onSubmit() onClose() }} - style={({ pressed }) => [styles.sendButton, pressed && styles.sendPressed, sendDisabled && styles.sendDisabled]} + style={({ pressed }) => [styles.sendButton, pressed && styles.sendPressed, !sending && sendDisabled && styles.sendDisabled]} > - + {sending ? ( + + ) : ( + + )} )}