Import apps/android/src/screens/chat/composer.tsx
This commit is contained in:
parent
250da02343
commit
591dc52ce7
|
|
@ -1,19 +1,17 @@
|
||||||
import { ArrowUp, ChevronDown, CircleStop, Plus, Zap } from 'lucide-react-native'
|
import { ArrowUp, CircleStop, Plus, X, Zap } from 'lucide-react-native'
|
||||||
import { useMemo } from 'react'
|
import { useMemo, useState, type RefObject } from 'react'
|
||||||
import { ActivityIndicator, Pressable, Text, TextInput, View } from 'react-native'
|
import { ActivityIndicator, Pressable, Text, TextInput, View } from 'react-native'
|
||||||
import Svg, { Path } from 'react-native-svg'
|
|
||||||
import { strings } from '../../locales/i18n'
|
import { strings } from '../../locales/i18n'
|
||||||
import type { RemoteSession } from '../../types'
|
import type { RemoteSession } from '../../types'
|
||||||
import { FISH_LOGO_PATH, FISH_LOGO_VIEWBOX } from '../../ui/fish-logo'
|
import { MentionPopover, splitDraftSegments, type MentionGroup } from '../../ui/mention-popover'
|
||||||
import { MentionPopover, splitDraftSegments } from '../../ui/mention-popover'
|
|
||||||
import { formatQuoteDraftSnippet } from '../../ui/quote-helpers'
|
import { formatQuoteDraftSnippet } from '../../ui/quote-helpers'
|
||||||
import { QuoteMarkIcon } from '../../ui/quote-preview'
|
import { QuoteMarkIcon } from '../../ui/quote-preview'
|
||||||
import { useTheme } from '../../ui/theme-context'
|
import { useTheme } from '../../ui/theme-context'
|
||||||
import { useThemedStyles } from '../../ui/use-themed-styles'
|
import { useThemedStyles } from '../../ui/use-themed-styles'
|
||||||
import { ReplyStatusDots } from './messages'
|
|
||||||
import { ExpandCornerIcon } from '../../ui/composer-expand-icons'
|
import { ExpandCornerIcon } from '../../ui/composer-expand-icons'
|
||||||
|
import { triggerLightHaptic } from '../../ui/haptics'
|
||||||
|
import { nextStackedOverflowLength, shouldShowExpandCorner, shouldUseStackedComposer } from './composer-gate'
|
||||||
import { createStyles } from './styles'
|
import { createStyles } from './styles'
|
||||||
import type { useChatMentions } from './use-chat-mentions'
|
|
||||||
|
|
||||||
type BackendChatTextKeys = Record<
|
type BackendChatTextKeys = Record<
|
||||||
'generating' | 'messageLabel' | 'placeholder' | 'policyHint',
|
'generating' | 'messageLabel' | 'placeholder' | 'policyHint',
|
||||||
|
|
@ -21,7 +19,7 @@ type BackendChatTextKeys = Record<
|
||||||
>
|
>
|
||||||
|
|
||||||
// Resolve these keys during rendering so language changes use the current catalog.
|
// Resolve these keys during rendering so language changes use the current catalog.
|
||||||
const BACKEND_CHAT_TEXT_KEYS: Partial<Record<string, BackendChatTextKeys>> & { harness: BackendChatTextKeys } = {
|
export const BACKEND_CHAT_TEXT_KEYS: Partial<Record<string, BackendChatTextKeys>> & { harness: BackendChatTextKeys } = {
|
||||||
harness: { generating: 'generating', messageLabel: 'messageLabel', placeholder: 'placeholder', policyHint: 'policyHint' },
|
harness: { generating: 'generating', messageLabel: 'messageLabel', placeholder: 'placeholder', policyHint: 'policyHint' },
|
||||||
codex: { generating: 'codexGenerating', messageLabel: 'codexMessageLabel', placeholder: 'codexPlaceholder', policyHint: 'codexPolicyHint' },
|
codex: { generating: 'codexGenerating', messageLabel: 'codexMessageLabel', placeholder: 'codexPlaceholder', policyHint: 'codexPolicyHint' },
|
||||||
cursor: { generating: 'cursorGenerating', messageLabel: 'cursorMessageLabel', placeholder: 'cursorPlaceholder', policyHint: 'cursorPolicyHint' },
|
cursor: { generating: 'cursorGenerating', messageLabel: 'cursorMessageLabel', placeholder: 'cursorPlaceholder', policyHint: 'cursorPolicyHint' },
|
||||||
|
|
@ -35,15 +33,31 @@ const BACKEND_CHAT_TEXT_KEYS: Partial<Record<string, BackendChatTextKeys>> & { h
|
||||||
/** Soft hint threshold; the composer accepts longer input instead of silently truncating. */
|
/** Soft hint threshold; the composer accepts longer input instead of silently truncating. */
|
||||||
const LONG_DRAFT_HINT = 12_000
|
const LONG_DRAFT_HINT = 12_000
|
||||||
|
|
||||||
|
/** Shared input adapter so both Agent chat and DS-Bot reuse the same composer shell. */
|
||||||
|
export type ComposerInputBridge = {
|
||||||
|
composerInputRef?: RefObject<TextInput | null>
|
||||||
|
mentionType: string | null
|
||||||
|
mentionGroups: MentionGroup[]
|
||||||
|
selection?: { start: number; end: number }
|
||||||
|
closeMention: () => void
|
||||||
|
onChangeText: (value: string) => void
|
||||||
|
onSelectionChange: (event: { nativeEvent: { selection: { start: number; end: number } } }) => void
|
||||||
|
}
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
backend: RemoteSession['backend']
|
backend?: RemoteSession['backend']
|
||||||
draft: string
|
draft: string
|
||||||
quotes?: string[]
|
quotes?: string[]
|
||||||
onRemoveQuote?: (index: number) => void
|
onRemoveQuote?: (index: number) => void
|
||||||
input: ReturnType<typeof useChatMentions>
|
input: ComposerInputBridge
|
||||||
|
accessibilityLabel?: string
|
||||||
|
placeholder?: string
|
||||||
|
highlightMentionTokens?: boolean
|
||||||
replyActive: boolean
|
replyActive: boolean
|
||||||
stopping: boolean
|
stopping: boolean
|
||||||
compactRunning: boolean
|
sending?: boolean
|
||||||
|
/** A tracked Host command (for example `/compact`) is running. */
|
||||||
|
commandRunning?: boolean
|
||||||
hasComposerContent: boolean
|
hasComposerContent: boolean
|
||||||
connected: boolean
|
connected: boolean
|
||||||
/** Text editing is local, so a dropped carrier must not lock this field. */
|
/** Text editing is local, so a dropped carrier must not lock this field. */
|
||||||
|
|
@ -52,197 +66,233 @@ type Props = {
|
||||||
sendDisabled: boolean
|
sendDisabled: boolean
|
||||||
compactComposer: boolean
|
compactComposer: boolean
|
||||||
composerInputMaxHeight: number
|
composerInputMaxHeight: number
|
||||||
model: { available: boolean; label: string | undefined; selecting: boolean; onOpen: () => void }
|
|
||||||
promptsPickerOpen: boolean
|
|
||||||
onExpand: () => void
|
|
||||||
onOpenExpand?: () => void
|
onOpenExpand?: () => void
|
||||||
onOpenActions: () => void
|
onOpenActions: () => void
|
||||||
onOpenPrompts: () => void
|
onOpenPrompts?: () => void
|
||||||
onSubmit: () => void
|
onSubmit: () => void
|
||||||
onStop: () => void
|
onStop: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ChatComposer({ backend, draft, quotes, onRemoveQuote, input, replyActive, stopping, compactRunning,
|
export function ChatComposer({ backend, draft, quotes, onRemoveQuote, input, accessibilityLabel, placeholder,
|
||||||
|
highlightMentionTokens = true, replyActive, stopping, sending = false, commandRunning,
|
||||||
hasComposerContent, connected, editable, composerDisabled, sendDisabled, compactComposer,
|
hasComposerContent, connected, editable, composerDisabled, sendDisabled, compactComposer,
|
||||||
composerInputMaxHeight, model, promptsPickerOpen, onExpand, onOpenExpand, onOpenActions, onOpenPrompts, onSubmit, onStop }: Props) {
|
composerInputMaxHeight, onOpenExpand, onOpenActions, onOpenPrompts, onSubmit, onStop }: Props) {
|
||||||
const { colors } = useTheme()
|
const { colors } = useTheme()
|
||||||
const styles = useThemedStyles(createStyles)
|
const styles = useThemedStyles(createStyles)
|
||||||
const { composerInputRef, mentionType, mentionGroups, selection, closeMention, onChangeText, onSelectionChange } = input
|
const { composerInputRef, mentionType, mentionGroups, selection, closeMention, onChangeText, onSelectionChange } = input
|
||||||
const draftSegments = useMemo(() => splitDraftSegments(draft), [draft])
|
const draftSegments = useMemo(() => (highlightMentionTokens ? splitDraftSegments(draft) : []), [draft, highlightMentionTokens])
|
||||||
|
const hasTokens = useMemo(
|
||||||
|
() => highlightMentionTokens && draftSegments.some(segment => segment.token),
|
||||||
|
[draftSegments, highlightMentionTokens],
|
||||||
|
)
|
||||||
|
const inputChildren = useMemo(
|
||||||
|
() => (hasTokens
|
||||||
|
? (
|
||||||
|
<Text style={{ fontSize: 16, lineHeight: 22 }}>
|
||||||
|
{draftSegments.map((segment, index) => (
|
||||||
|
<Text key={index} style={{ color: segment.token ? colors.primary : colors.ink }}>{segment.text}</Text>
|
||||||
|
))}
|
||||||
|
</Text>
|
||||||
|
)
|
||||||
|
: undefined),
|
||||||
|
[colors.ink, colors.primary, draftSegments, hasTokens],
|
||||||
|
)
|
||||||
const backendTextKeys = BACKEND_CHAT_TEXT_KEYS[backend ?? 'harness'] ?? BACKEND_CHAT_TEXT_KEYS.harness
|
const backendTextKeys = BACKEND_CHAT_TEXT_KEYS[backend ?? 'harness'] ?? BACKEND_CHAT_TEXT_KEYS.harness
|
||||||
const replyStatusLabel = stopping ? strings.chat.stopping : strings.chat[backendTextKeys.generating]
|
const resolvedLabel = accessibilityLabel ?? strings.chat[backendTextKeys.messageLabel]
|
||||||
|
const resolvedPlaceholder = placeholder ?? strings.chat[backendTextKeys.placeholder]
|
||||||
|
const [contentHeight, setContentHeight] = useState(0)
|
||||||
|
const [stackedOverflowLength, setStackedOverflowLength] = useState<number | null>(null)
|
||||||
|
const hasQuotes = quotes !== undefined && quotes.length > 0
|
||||||
|
const effectiveContentHeight = draft.length === 0 ? 0 : contentHeight
|
||||||
|
const effectiveOverflowLength = draft.length === 0 ? null : stackedOverflowLength
|
||||||
|
const isStacked = shouldUseStackedComposer({
|
||||||
|
draft,
|
||||||
|
hasQuotes,
|
||||||
|
overflowLength: effectiveOverflowLength,
|
||||||
|
})
|
||||||
|
const showExpand = isStacked && onOpenExpand !== undefined && shouldShowExpandCorner({
|
||||||
|
draft,
|
||||||
|
contentHeight: effectiveContentHeight,
|
||||||
|
})
|
||||||
|
const rightInlineReserve = 40
|
||||||
|
+ (onOpenPrompts !== undefined ? 40 : 0)
|
||||||
|
+ ((replyActive || commandRunning) && hasComposerContent ? 34 : 0)
|
||||||
return <>
|
return <>
|
||||||
{replyActive && (
|
|
||||||
<View
|
|
||||||
accessible
|
|
||||||
accessibilityLabel={replyStatusLabel}
|
|
||||||
accessibilityLiveRegion="polite"
|
|
||||||
style={styles.replyStatus}
|
|
||||||
>
|
|
||||||
<Svg width={18} height={18} viewBox={`0 0 ${FISH_LOGO_VIEWBOX.width} ${FISH_LOGO_VIEWBOX.height}`} accessible={false}><Path d={FISH_LOGO_PATH} fill={colors.accent} /></Svg>
|
|
||||||
<Text style={styles.replyStatusText}>{replyStatusLabel}</Text>
|
|
||||||
{!stopping && <ReplyStatusDots />}
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
<View style={{ position: 'relative', zIndex: 20, elevation: 20 }}>
|
<View style={{ position: 'relative', zIndex: 20, elevation: 20 }}>
|
||||||
{mentionType !== null && (
|
{mentionType !== null && (
|
||||||
<MentionPopover groups={mentionGroups} onDismiss={closeMention} emptyText={strings.mention.noMatches} />
|
<MentionPopover groups={mentionGroups} onDismiss={closeMention} emptyText={strings.mention.noMatches} />
|
||||||
)}
|
)}
|
||||||
{compactRunning ? <View style={[styles.composerCard, styles.runningComposer]}>
|
<View style={[styles.composerCard, hasQuotes && styles.composerCardWithQuotes]}>
|
||||||
<Pressable accessibilityRole="button" accessibilityLabel={strings.chat.moreActions} onPress={onOpenActions}
|
{hasQuotes && (
|
||||||
style={({ pressed }) => [styles.plusButton, pressed && styles.plusPressed]}>
|
<View style={styles.composerQuotesWrap}>
|
||||||
<Plus size={22} color={colors.ink} />
|
{quotes.map((quoteText, index) => (
|
||||||
</Pressable>
|
<Pressable
|
||||||
<Pressable accessibilityRole="button" accessibilityLabel={strings.sessionActivity.composeRunning}
|
key={`inline-quote-${index}`}
|
||||||
onPress={onExpand} style={styles.runningComposerPrompt}>
|
accessibilityRole="button"
|
||||||
<Text style={styles.runningComposerText} numberOfLines={1}>{strings.sessionActivity.composeRunning}</Text>
|
accessibilityLabel={`${strings.chat.removeQuote ?? '删除引用'}: ${quoteText}`}
|
||||||
</Pressable>
|
onPress={() => onRemoveQuote?.(index)}
|
||||||
<Pressable accessibilityRole="button" accessibilityLabel={strings.chat.stop} disabled={stopping}
|
hitSlop={4}
|
||||||
accessibilityState={{ disabled: stopping, busy: stopping }} onPress={onStop}
|
style={styles.composerQuotePill}
|
||||||
style={({ pressed }) => [styles.stopButton, pressed && !stopping && styles.stopPressed]}>
|
>
|
||||||
{stopping ? <ActivityIndicator size="small" color={colors.onInverse} /> : <CircleStop size={20} color={colors.onInverse} />}
|
<QuoteMarkIcon size={12} color={colors.primary} />
|
||||||
</Pressable>
|
<Text numberOfLines={1} style={styles.composerQuotePillText}>
|
||||||
</View> : <View style={styles.composerCard}>
|
“{formatQuoteDraftSnippet(quoteText, 18)}”
|
||||||
{draft.length > 0 && !compactRunning && onOpenExpand !== undefined && (
|
</Text>
|
||||||
<Pressable
|
<X size={12} color={colors.primary} />
|
||||||
accessibilityRole="button"
|
</Pressable>
|
||||||
accessibilityLabel={strings.chat.expandComposer}
|
))}
|
||||||
onPress={onOpenExpand}
|
</View>
|
||||||
hitSlop={8}
|
|
||||||
style={({ pressed }) => [styles.composerExpandButton, pressed && styles.plusPressed]}
|
|
||||||
>
|
|
||||||
<ExpandCornerIcon size={17} color={colors.muted} />
|
|
||||||
</Pressable>
|
|
||||||
)}
|
)}
|
||||||
<View style={styles.composerInputWrap}>
|
{/* Keep Child 0 (TextInput) and Child 1 (action bar) in fixed React tree positions so inline <-> stacked promotion never unmounts the input or drops IME focus. */}
|
||||||
{quotes?.map((quoteText, index) => (
|
<View style={styles.composerBody}>
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
isStacked ? styles.composerInputSlotStacked : [styles.composerInputSlotInline, { marginLeft: 40, marginRight: rightInlineReserve }],
|
||||||
|
showExpand && styles.composerInputSlotExpandPad,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
ref={composerInputRef}
|
||||||
|
accessibilityLabel={resolvedLabel}
|
||||||
|
style={[
|
||||||
|
styles.composerInput,
|
||||||
|
isStacked && styles.composerInputStacked,
|
||||||
|
draft.length === 0 && styles.composerInputEmpty,
|
||||||
|
compactComposer && { maxHeight: composerInputMaxHeight },
|
||||||
|
]}
|
||||||
|
value={!hasTokens ? draft : undefined}
|
||||||
|
onChangeText={onChangeText}
|
||||||
|
onSelectionChange={onSelectionChange}
|
||||||
|
onContentSizeChange={(event) => {
|
||||||
|
const nextHeight = event.nativeEvent.contentSize.height
|
||||||
|
setContentHeight(nextHeight)
|
||||||
|
setStackedOverflowLength(prev => nextStackedOverflowLength({
|
||||||
|
draft,
|
||||||
|
contentHeight: nextHeight,
|
||||||
|
currentOverflowLength: prev,
|
||||||
|
}))
|
||||||
|
}}
|
||||||
|
onKeyPress={({ nativeEvent }) => {
|
||||||
|
if (nativeEvent.key === 'Backspace' && draft.length === 0 && quotes && quotes.length > 0) {
|
||||||
|
onRemoveQuote?.(quotes.length - 1)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
selection={selection}
|
||||||
|
placeholder={resolvedPlaceholder}
|
||||||
|
placeholderTextColor={colors.muted}
|
||||||
|
multiline
|
||||||
|
editable={editable}
|
||||||
|
selectionColor={colors.accent}
|
||||||
|
cursorColor={colors.accent}
|
||||||
|
children={inputChildren}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<View pointerEvents="box-none" style={isStacked ? styles.composerActionsRow : styles.composerActionsOverlay}>
|
||||||
<Pressable
|
<Pressable
|
||||||
key={`inline-quote-${index}`}
|
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={`${strings.chat.removeQuote ?? '删除引用'}: ${quoteText}`}
|
accessibilityLabel={strings.chat.moreActions}
|
||||||
onPress={() => onRemoveQuote?.(index)}
|
accessibilityState={{ disabled: composerDisabled }}
|
||||||
style={styles.composerInlineQuoteBadge}
|
disabled={composerDisabled}
|
||||||
|
onPress={() => {
|
||||||
|
triggerLightHaptic()
|
||||||
|
onOpenActions()
|
||||||
|
}}
|
||||||
|
hitSlop={6}
|
||||||
|
style={({ pressed }) => [styles.plusButton, pressed && styles.plusPressed, composerDisabled && styles.plusDisabled]}
|
||||||
>
|
>
|
||||||
<QuoteMarkIcon size={14} color={colors.primary} />
|
<Plus size={20} color={!composerDisabled ? colors.ink : colors.disabled} />
|
||||||
<Text numberOfLines={1} style={[styles.composerInlineQuoteText, { color: colors.primary, maxWidth: 180 }]}>
|
|
||||||
“{formatQuoteDraftSnippet(quoteText, 14)}”
|
|
||||||
</Text>
|
|
||||||
</Pressable>
|
</Pressable>
|
||||||
))}
|
<View style={styles.composerTrailing}>
|
||||||
{/* Native attributed text keeps references blue without an opaque Android value layer. */}
|
{onOpenPrompts !== undefined && (
|
||||||
<TextInput
|
|
||||||
ref={composerInputRef}
|
|
||||||
accessibilityLabel={strings.chat[backendTextKeys.messageLabel]}
|
|
||||||
style={[styles.composerInput, compactComposer && { maxHeight: composerInputMaxHeight }, draft.length > 0 && !compactRunning && onOpenExpand !== undefined && { paddingRight: 32 }]}
|
|
||||||
onChangeText={onChangeText}
|
|
||||||
onSelectionChange={onSelectionChange}
|
|
||||||
onKeyPress={({ nativeEvent }) => {
|
|
||||||
if (nativeEvent.key === 'Backspace' && draft.length === 0 && quotes && quotes.length > 0) {
|
|
||||||
onRemoveQuote?.(quotes.length - 1)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
|
|
||||||
selection={selection}
|
|
||||||
placeholder={strings.chat[backendTextKeys.placeholder]}
|
|
||||||
placeholderTextColor={colors.muted}
|
|
||||||
multiline
|
|
||||||
editable={editable}
|
|
||||||
selectionColor={colors.accent}
|
|
||||||
cursorColor={colors.accent}
|
|
||||||
>
|
|
||||||
<Text>{draftSegments.map((segment, index) => <Text key={index} style={{ color: segment.token ? colors.primary : colors.ink }}>{segment.text}</Text>)}</Text>
|
|
||||||
</TextInput>
|
|
||||||
</View>
|
|
||||||
<View style={styles.composerControls}>
|
|
||||||
<Pressable
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel={strings.chat.moreActions}
|
|
||||||
accessibilityState={{ disabled: composerDisabled }}
|
|
||||||
disabled={composerDisabled}
|
|
||||||
onPress={onOpenActions}
|
|
||||||
hitSlop={8}
|
|
||||||
style={({ pressed }) => [styles.plusButton, pressed && styles.plusPressed, composerDisabled && styles.plusDisabled]}
|
|
||||||
>
|
|
||||||
<Plus size={20} color={connected ? colors.ink : colors.disabled} />
|
|
||||||
</Pressable>
|
|
||||||
<Pressable
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel={strings.chat.quickPrompts}
|
|
||||||
accessibilityState={{ disabled: composerDisabled, expanded: promptsPickerOpen }}
|
|
||||||
disabled={composerDisabled}
|
|
||||||
onPress={onOpenPrompts}
|
|
||||||
hitSlop={{ top: 8, bottom: 8 }}
|
|
||||||
style={({ pressed }) => [styles.plusButton, pressed && styles.plusPressed, composerDisabled && styles.plusDisabled]}
|
|
||||||
>
|
|
||||||
<Zap size={18} color={connected ? colors.ink : colors.disabled} strokeWidth={1.9} />
|
|
||||||
</Pressable>
|
|
||||||
<View style={styles.composerSpacer} />
|
|
||||||
{model.available && (
|
|
||||||
<Pressable accessibilityRole="button" accessibilityLabel={strings.chat.selectModel} onPress={model.onOpen} style={styles.modelChip}>
|
|
||||||
<Text style={styles.modelChipText} numberOfLines={1}>{model.label}</Text>
|
|
||||||
{model.selecting ? <ActivityIndicator size="small" color={colors.muted} /> : <ChevronDown size={14} color={colors.muted} />}
|
|
||||||
</Pressable>
|
|
||||||
)}
|
|
||||||
{replyActive && !hasComposerContent
|
|
||||||
? <Pressable
|
|
||||||
accessibilityRole="button"
|
|
||||||
accessibilityLabel={strings.chat.stop}
|
|
||||||
accessibilityState={{ disabled: stopping, busy: stopping }}
|
|
||||||
disabled={stopping}
|
|
||||||
onPress={onStop}
|
|
||||||
style={({ pressed }) => [styles.stopButton, pressed && !stopping && styles.stopPressed, stopping && styles.sendDisabled]}
|
|
||||||
>
|
|
||||||
{stopping
|
|
||||||
? <ActivityIndicator size="small" color={colors.onInverse} />
|
|
||||||
: <CircleStop size={20} color={colors.onInverse} />}
|
|
||||||
</Pressable>
|
|
||||||
: <>
|
|
||||||
{/* With text in the composer the primary action is the send
|
|
||||||
(queueing) button — tapping where Send lives must never stop
|
|
||||||
the running task (official InputBar behaviour). Stop stays
|
|
||||||
available as its own secondary button. */}
|
|
||||||
{replyActive && (
|
|
||||||
<Pressable
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={strings.chat.quickPrompts}
|
||||||
|
accessibilityState={{ disabled: composerDisabled }}
|
||||||
|
disabled={composerDisabled}
|
||||||
|
onPress={onOpenPrompts}
|
||||||
|
hitSlop={6}
|
||||||
|
style={({ pressed }) => [styles.composerShortcutButton, pressed && styles.plusPressed, composerDisabled && styles.plusDisabled]}
|
||||||
|
>
|
||||||
|
<Zap size={19} color={!composerDisabled ? colors.ink : colors.disabled} />
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
|
{(replyActive || commandRunning) && !hasComposerContent
|
||||||
|
? <Pressable
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={strings.chat.stop}
|
accessibilityLabel={strings.chat.stop}
|
||||||
accessibilityState={{ disabled: stopping, busy: stopping }}
|
accessibilityState={{ disabled: stopping, busy: stopping }}
|
||||||
disabled={stopping}
|
disabled={stopping}
|
||||||
onPress={onStop}
|
onPress={() => {
|
||||||
style={({ pressed }) => [styles.stopButtonSmall, pressed && !stopping && styles.stopPressed, stopping && styles.sendDisabled]}
|
triggerLightHaptic()
|
||||||
|
onStop()
|
||||||
|
}}
|
||||||
|
hitSlop={6}
|
||||||
|
style={({ pressed }) => [styles.stopButton, pressed && !stopping && styles.stopPressed, stopping && styles.sendDisabled]}
|
||||||
>
|
>
|
||||||
{stopping
|
{stopping
|
||||||
? <ActivityIndicator size="small" color={colors.white} />
|
? <ActivityIndicator size="small" color={colors.onInverse} />
|
||||||
: <CircleStop size={17} color={colors.onInverse} />}
|
: <CircleStop size={18} color={colors.onInverse} />}
|
||||||
</Pressable>
|
</Pressable>
|
||||||
)}
|
: <>
|
||||||
<Pressable
|
{/* With text in the composer the primary action is the send
|
||||||
accessibilityRole="button"
|
(queueing) button — tapping where Send lives must never stop
|
||||||
accessibilityLabel={strings.chat.send}
|
the running task (official InputBar behaviour). Stop stays
|
||||||
accessibilityState={{ disabled: sendDisabled }}
|
available as its own secondary button. */}
|
||||||
disabled={sendDisabled}
|
{(replyActive || commandRunning) && (
|
||||||
onPress={onSubmit}
|
<Pressable
|
||||||
style={({ pressed }) => [styles.sendButton, pressed && styles.sendPressed, sendDisabled && styles.sendDisabled]}
|
accessibilityRole="button"
|
||||||
>
|
accessibilityLabel={strings.chat.stop}
|
||||||
<ArrowUp size={20} color={sendDisabled ? colors.subtle : colors.white} strokeWidth={2.4} />
|
accessibilityState={{ disabled: stopping, busy: stopping }}
|
||||||
</Pressable>
|
disabled={stopping}
|
||||||
</>}
|
onPress={() => {
|
||||||
|
triggerLightHaptic()
|
||||||
|
onStop()
|
||||||
|
}}
|
||||||
|
hitSlop={6}
|
||||||
|
style={({ pressed }) => [styles.stopButtonSmall, pressed && !stopping && styles.stopPressed, stopping && styles.sendDisabled]}
|
||||||
|
>
|
||||||
|
{stopping
|
||||||
|
? <ActivityIndicator size="small" color={colors.onInverse} />
|
||||||
|
: <CircleStop size={16} color={colors.onInverse} />}
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={strings.chat.send}
|
||||||
|
accessibilityState={{ disabled: sendDisabled, busy: sending }}
|
||||||
|
disabled={sendDisabled}
|
||||||
|
onPress={onSubmit}
|
||||||
|
hitSlop={6}
|
||||||
|
style={({ pressed }) => [styles.sendButton, pressed && styles.sendPressed, !sending && sendDisabled && styles.sendDisabled]}
|
||||||
|
>
|
||||||
|
{sending
|
||||||
|
? <ActivityIndicator size="small" color={colors.onInverse ?? colors.white} />
|
||||||
|
: <ArrowUp size={18} color={sendDisabled ? colors.subtle : (colors.onInverse ?? colors.white)} strokeWidth={2.4} />}
|
||||||
|
</Pressable>
|
||||||
|
</>}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
{showExpand && (
|
||||||
|
<Pressable
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={strings.chat.expandComposer}
|
||||||
|
onPress={onOpenExpand}
|
||||||
|
hitSlop={6}
|
||||||
|
style={({ pressed }) => [styles.composerExpandCorner, pressed && styles.plusPressed]}
|
||||||
|
>
|
||||||
|
<ExpandCornerIcon size={15} color={colors.muted} />
|
||||||
|
</Pressable>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
</View>}
|
</View>
|
||||||
</View>
|
</View>
|
||||||
{draft.length > LONG_DRAFT_HINT && (
|
{draft.length > LONG_DRAFT_HINT && (
|
||||||
<Text style={styles.composerHint}>{strings.chat.draftLong(draft.length)}</Text>
|
<Text style={styles.composerHint}>{strings.chat.draftLong(draft.length)}</Text>
|
||||||
)}
|
)}
|
||||||
{/* The draft survives a carrier drop; say so instead of silently
|
{/* The draft survives a carrier drop; say so instead of silently
|
||||||
swallowing an offline send tap (the primary action stays disabled). */}
|
swallowing an offline send tap (the primary action stays disabled). */}
|
||||||
{!connected && draft.length > 0 && (
|
{!connected && (draft.length > 0 || hasComposerContent) && (
|
||||||
<Text accessibilityLiveRegion="polite" style={styles.composerHint}>{strings.chat.offlineSendBlocked}</Text>
|
<Text accessibilityLiveRegion="polite" style={[styles.composerHint, styles.composerHintWarning]}>{strings.chat.offlineSendBlocked}</Text>
|
||||||
)}
|
|
||||||
{/* Landscape phones leave almost no space above the IME once the
|
|
||||||
composer is visible; keep the privacy note for roomier windows. */}
|
|
||||||
{!compactComposer && (
|
|
||||||
<Text style={styles.composerHint}>
|
|
||||||
{strings.chat[backendTextKeys.policyHint]}
|
|
||||||
</Text>
|
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue