Refine mobile new task toolbar labels and focus
This commit is contained in:
1 parent
39006ef617
commit
7c7fa6e6c0
2 files changed
+276
-58
No files matched your search
@@ -238,17 +238,18 @@ export function ReviewCommentComposerSheet() {
|
||||
<View className="min-h-0 flex-1 gap-2">
|
||||
<Text className="text-[13px] font-t3-bold text-foreground">Comment</Text>
|
||||
<View className="min-h-[132px] flex-1 overflow-hidden rounded-[20px] border border-border bg-card">
|
||||
<View className="flex-1 px-4 pt-3.5">
|
||||
<TextInputWrapper onPaste={handleNativePaste} style={{ flex: 1 }}>
|
||||
<View className="min-h-0 flex-1 px-4 pt-3.5">
|
||||
<TextInputWrapper onPaste={handleNativePaste} style={{ flex: 1, minHeight: 0 }}>
|
||||
<TextInput
|
||||
autoFocus
|
||||
multiline
|
||||
scrollEnabled
|
||||
placeholder="Leave a comment..."
|
||||
textAlignVertical="top"
|
||||
value={commentText}
|
||||
onChangeText={setCommentText}
|
||||
className="h-full flex-1 border-0 bg-transparent px-0 py-0 font-sans text-[15px]"
|
||||
style={{ flex: 1 }}
|
||||
style={{ flex: 1, minHeight: 0 }}
|
||||
/>
|
||||
</TextInputWrapper>
|
||||
</View>
|
||||
|
||||
@@ -1,14 +1,33 @@
|
||||
import { useRouter } from "expo-router";
|
||||
import { SymbolView } from "expo-symbols";
|
||||
import { TextInputWrapper } from "expo-paste-input";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
import { View } from "react-native";
|
||||
import { KeyboardStickyView, useKeyboardState } from "react-native-keyboard-controller";
|
||||
import {
|
||||
type ComponentProps,
|
||||
type ReactNode,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import {
|
||||
InteractionManager,
|
||||
Pressable,
|
||||
ScrollView,
|
||||
View,
|
||||
useColorScheme,
|
||||
type LayoutChangeEvent,
|
||||
type NativeScrollEvent,
|
||||
type NativeSyntheticEvent,
|
||||
type TextInput as RNTextInput,
|
||||
} from "react-native";
|
||||
import { KeyboardAvoidingView, useKeyboardState } from "react-native-keyboard-controller";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { useThemeColor } from "../../lib/useThemeColor";
|
||||
|
||||
import { EnvironmentId, type ModelSelection } from "@t3tools/contracts";
|
||||
|
||||
import { AppTextInput as TextInput } from "../../components/AppText";
|
||||
import { AppText as Text, AppTextInput as TextInput } from "../../components/AppText";
|
||||
import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
|
||||
import { ControlPill, ControlPillMenu } from "../../components/ControlPill";
|
||||
import { ProviderIcon } from "../../components/ProviderIcon";
|
||||
@@ -22,6 +41,9 @@ import { NewTaskSheetHeader } from "./NewTaskSheetHeader";
|
||||
import { branchBadgeLabel, useNewTaskFlow } from "./new-task-flow-provider";
|
||||
import { useProjectActions } from "./use-project-actions";
|
||||
|
||||
const TOOLBAR_FADE_WIDTH = 18;
|
||||
const TOOLBAR_SCROLL_EPSILON = 4;
|
||||
|
||||
function withModelSelectionOption(
|
||||
selection: ModelSelection,
|
||||
id: string,
|
||||
@@ -34,6 +56,61 @@ function withModelSelectionOption(
|
||||
};
|
||||
}
|
||||
|
||||
function formatTitleCase(value: string): string {
|
||||
return value.length === 0 ? value : `${value.charAt(0).toUpperCase()}${value.slice(1)}`;
|
||||
}
|
||||
|
||||
function formatWorkspaceLabel(input: {
|
||||
readonly workspaceMode: string;
|
||||
readonly currentBranchName: string | null;
|
||||
readonly selectedBranchName: string | null;
|
||||
}): string {
|
||||
const branchName = input.selectedBranchName ?? input.currentBranchName;
|
||||
if (input.workspaceMode === "worktree") {
|
||||
return branchName ? `New worktree · ${branchName}` : "New worktree";
|
||||
}
|
||||
return branchName ? `Current · ${branchName}` : "Current checkout";
|
||||
}
|
||||
|
||||
function NewTaskToolbarTrigger(props: {
|
||||
readonly icon?: ComponentProps<typeof SymbolView>["name"];
|
||||
readonly iconNode?: ReactNode;
|
||||
readonly label?: string;
|
||||
readonly accessibilityLabel?: string;
|
||||
readonly onPress?: () => void;
|
||||
readonly showChevron?: boolean;
|
||||
}) {
|
||||
const iconColor = useThemeColor("--color-icon");
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
accessibilityLabel={props.accessibilityLabel ?? props.label}
|
||||
accessibilityRole="button"
|
||||
onPress={props.onPress}
|
||||
className="h-11 flex-row items-center justify-center gap-2 rounded-full bg-subtle px-3.5 active:opacity-70"
|
||||
style={{ maxWidth: 172 }}
|
||||
>
|
||||
{props.iconNode ? (
|
||||
<View className="h-4 w-4 items-center justify-center">{props.iconNode}</View>
|
||||
) : props.icon ? (
|
||||
<SymbolView name={props.icon} size={16} tintColor={iconColor} type="monochrome" />
|
||||
) : null}
|
||||
{props.label ? (
|
||||
<Text
|
||||
className="shrink text-[13px] font-t3-bold text-foreground"
|
||||
ellipsizeMode="tail"
|
||||
numberOfLines={1}
|
||||
>
|
||||
{props.label}
|
||||
</Text>
|
||||
) : null}
|
||||
{props.showChevron === false ? null : (
|
||||
<SymbolView name="chevron.down" size={11} tintColor={iconColor} type="monochrome" />
|
||||
)}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
export function NewTaskDraftScreen(props: {
|
||||
readonly initialProjectRef?: {
|
||||
readonly environmentId?: string;
|
||||
@@ -45,11 +122,20 @@ export function NewTaskDraftScreen(props: {
|
||||
const flow = useNewTaskFlow();
|
||||
const router = useRouter();
|
||||
const insets = useSafeAreaInsets();
|
||||
const colorScheme = useColorScheme();
|
||||
const isKeyboardVisible = useKeyboardState((state) => state.isVisible);
|
||||
const controlsBottomPadding = isKeyboardVisible ? 8 : Math.max(insets.bottom, 10);
|
||||
const { logicalProjects, selectedProject, setProject } = flow;
|
||||
const promptInputRef = useRef<RNTextInput>(null);
|
||||
const [toolbarMetrics, setToolbarMetrics] = useState({
|
||||
contentWidth: 0,
|
||||
offsetX: 0,
|
||||
viewportWidth: 0,
|
||||
});
|
||||
|
||||
const borderColor = useThemeColor("--color-border");
|
||||
const sheetFadeOpaque = colorScheme === "dark" ? "rgba(14,14,14,0.98)" : "rgba(242,242,247,0.98)";
|
||||
const sheetFadeTransparent = colorScheme === "dark" ? "rgba(14,14,14,0)" : "rgba(242,242,247,0)";
|
||||
|
||||
useEffect(() => {
|
||||
if (props.initialProjectRef?.environmentId && props.initialProjectRef?.projectId) {
|
||||
@@ -93,6 +179,24 @@ export function NewTaskDraftScreen(props: {
|
||||
void flow.loadBranches();
|
||||
}, [flow, selectedProject]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedProject) {
|
||||
return;
|
||||
}
|
||||
|
||||
let focusFrame: ReturnType<typeof requestAnimationFrame> | null = null;
|
||||
const interaction = InteractionManager.runAfterInteractions(() => {
|
||||
focusFrame = requestAnimationFrame(() => promptInputRef.current?.focus());
|
||||
});
|
||||
|
||||
return () => {
|
||||
interaction.cancel();
|
||||
if (focusFrame !== null) {
|
||||
cancelAnimationFrame(focusFrame);
|
||||
}
|
||||
};
|
||||
}, [selectedProject]);
|
||||
|
||||
const environmentMenuActions = useMemo(
|
||||
() =>
|
||||
flow.environments.map((environment) => ({
|
||||
@@ -231,10 +335,10 @@ export function NewTaskDraftScreen(props: {
|
||||
{
|
||||
id: "workspace:mode",
|
||||
title: "Mode",
|
||||
subtitle: flow.workspaceMode === "local" ? "Local" : "Worktree",
|
||||
subtitle: flow.workspaceMode === "local" ? "Current checkout" : "New worktree",
|
||||
subactions: (["local", "worktree"] as const).map((value) => ({
|
||||
id: `workspace:mode:${value}`,
|
||||
title: value === "local" ? "Local" : "Worktree",
|
||||
title: value === "local" ? "Current checkout" : "New worktree",
|
||||
state: flow.workspaceMode === value ? ("on" as const) : undefined,
|
||||
})),
|
||||
},
|
||||
@@ -253,6 +357,56 @@ export function NewTaskDraftScreen(props: {
|
||||
flow.workspaceMode,
|
||||
]);
|
||||
|
||||
const selectedEnvironmentLabel =
|
||||
flow.environments.find(
|
||||
(environment) => environment.environmentId === flow.selectedEnvironmentId,
|
||||
)?.environmentLabel ?? "Environment";
|
||||
const currentBranchName =
|
||||
flow.availableBranches.find((branch) => branch.current)?.name ??
|
||||
flow.availableBranches.find((branch) => branch.isDefault)?.name ??
|
||||
null;
|
||||
const configurationLabel = useMemo(() => {
|
||||
const parts = [
|
||||
formatTitleCase(flow.effort),
|
||||
flow.fastMode ? "Fast" : null,
|
||||
flow.contextWindow !== "1M" ? flow.contextWindow : null,
|
||||
].filter((part): part is string => Boolean(part));
|
||||
return parts.length > 0 ? parts.join(" · ") : "Configuration";
|
||||
}, [flow.contextWindow, flow.effort, flow.fastMode]);
|
||||
const workspaceLabel = useMemo(
|
||||
() =>
|
||||
formatWorkspaceLabel({
|
||||
currentBranchName,
|
||||
selectedBranchName: flow.selectedBranchName,
|
||||
workspaceMode: flow.workspaceMode,
|
||||
}),
|
||||
[currentBranchName, flow.selectedBranchName, flow.workspaceMode],
|
||||
);
|
||||
const toolbarScrollEdges = useMemo(() => {
|
||||
const maxOffset = Math.max(0, toolbarMetrics.contentWidth - toolbarMetrics.viewportWidth);
|
||||
return {
|
||||
showLeftFade: toolbarMetrics.offsetX > TOOLBAR_SCROLL_EPSILON,
|
||||
showRightFade: toolbarMetrics.offsetX < maxOffset - TOOLBAR_SCROLL_EPSILON,
|
||||
};
|
||||
}, [toolbarMetrics]);
|
||||
const handleToolbarLayout = useCallback((event: LayoutChangeEvent) => {
|
||||
const viewportWidth = event.nativeEvent.layout.width;
|
||||
setToolbarMetrics((current) =>
|
||||
current.viewportWidth === viewportWidth ? current : { ...current, viewportWidth },
|
||||
);
|
||||
}, []);
|
||||
const handleToolbarContentSizeChange = useCallback((contentWidth: number) => {
|
||||
setToolbarMetrics((current) =>
|
||||
current.contentWidth === contentWidth ? current : { ...current, contentWidth },
|
||||
);
|
||||
}, []);
|
||||
const handleToolbarScroll = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
const offsetX = event.nativeEvent.contentOffset.x;
|
||||
setToolbarMetrics((current) =>
|
||||
Math.abs(current.offsetX - offsetX) < 1 ? current : { ...current, offsetX },
|
||||
);
|
||||
}, []);
|
||||
|
||||
function handleModelMenuAction(event: string) {
|
||||
if (!event.startsWith("model:")) {
|
||||
return;
|
||||
@@ -408,24 +562,27 @@ export function NewTaskDraftScreen(props: {
|
||||
}
|
||||
/>
|
||||
|
||||
<View style={{ flex: 1, paddingHorizontal: 20, paddingTop: 8 }}>
|
||||
<TextInputWrapper
|
||||
onPaste={(payload) => void handleNativePaste(payload)}
|
||||
style={{ flex: 1 }}
|
||||
>
|
||||
<TextInput
|
||||
multiline
|
||||
value={flow.prompt}
|
||||
onChangeText={flow.setPrompt}
|
||||
placeholder={`Describe a coding task in ${selectedProject.title}`}
|
||||
textAlignVertical="top"
|
||||
className="h-full flex-1 border-0 bg-transparent text-[18px] leading-[28px]"
|
||||
style={{ flex: 1 }}
|
||||
/>
|
||||
</TextInputWrapper>
|
||||
</View>
|
||||
<KeyboardAvoidingView automaticOffset behavior="padding" style={{ flex: 1 }}>
|
||||
<View style={{ flex: 1, minHeight: 0, paddingHorizontal: 20, paddingTop: 8 }}>
|
||||
<TextInputWrapper
|
||||
onPaste={(payload) => void handleNativePaste(payload)}
|
||||
style={{ flex: 1, minHeight: 0 }}
|
||||
>
|
||||
<TextInput
|
||||
ref={promptInputRef}
|
||||
autoFocus
|
||||
multiline
|
||||
scrollEnabled
|
||||
value={flow.prompt}
|
||||
onChangeText={flow.setPrompt}
|
||||
placeholder={`Describe a coding task in ${selectedProject.title}`}
|
||||
textAlignVertical="top"
|
||||
className="h-full flex-1 border-0 bg-transparent text-[18px] leading-[28px]"
|
||||
style={{ flex: 1, minHeight: 0 }}
|
||||
/>
|
||||
</TextInputWrapper>
|
||||
</View>
|
||||
|
||||
<KeyboardStickyView>
|
||||
<View
|
||||
style={{
|
||||
borderTopWidth: 1,
|
||||
@@ -443,39 +600,99 @@ export function NewTaskDraftScreen(props: {
|
||||
/>
|
||||
</View>
|
||||
) : null}
|
||||
<View className="flex-row items-center justify-between gap-2 px-4 pt-2">
|
||||
<ControlPill icon="plus" onPress={() => void handlePickImages()} />
|
||||
<ControlPillMenu
|
||||
actions={modelMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ControlPill
|
||||
iconNode={
|
||||
<ProviderIcon provider={flow.selectedModelOption?.providerDriver} size={16} />
|
||||
}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={optionsMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ControlPill icon="slider.horizontal.3" />
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={environmentMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleEnvironmentMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ControlPill icon="desktopcomputer" />
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={workspaceMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleWorkspaceMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<ControlPill icon="point.topleft.down.curvedto.point.bottomright.up" />
|
||||
</ControlPillMenu>
|
||||
<View className="flex-row items-center gap-1.5 px-1.5 pt-2">
|
||||
<View className="min-w-0 flex-1" style={{ position: "relative" }}>
|
||||
<ScrollView
|
||||
horizontal
|
||||
keyboardShouldPersistTaps="always"
|
||||
onContentSizeChange={handleToolbarContentSizeChange}
|
||||
onLayout={handleToolbarLayout}
|
||||
onScroll={handleToolbarScroll}
|
||||
scrollEventThrottle={16}
|
||||
showsHorizontalScrollIndicator={false}
|
||||
contentContainerStyle={{
|
||||
alignItems: "center",
|
||||
gap: 8,
|
||||
paddingLeft: 0,
|
||||
paddingRight: 1,
|
||||
}}
|
||||
>
|
||||
<ControlPill icon="plus" onPress={() => void handlePickImages()} />
|
||||
<ControlPillMenu
|
||||
actions={modelMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleModelMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<NewTaskToolbarTrigger
|
||||
accessibilityLabel="Model"
|
||||
iconNode={
|
||||
<ProviderIcon provider={flow.selectedModelOption?.providerDriver} size={16} />
|
||||
}
|
||||
label={flow.selectedModelOption?.label ?? "Model"}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={optionsMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleOptionsMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<NewTaskToolbarTrigger
|
||||
accessibilityLabel="Configuration"
|
||||
icon="slider.horizontal.3"
|
||||
label={configurationLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={environmentMenuActions}
|
||||
onPressAction={({ nativeEvent }) =>
|
||||
handleEnvironmentMenuAction(nativeEvent.event)
|
||||
}
|
||||
>
|
||||
<NewTaskToolbarTrigger
|
||||
accessibilityLabel="Environment"
|
||||
icon="desktopcomputer"
|
||||
label={selectedEnvironmentLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
<ControlPillMenu
|
||||
actions={workspaceMenuActions}
|
||||
onPressAction={({ nativeEvent }) => handleWorkspaceMenuAction(nativeEvent.event)}
|
||||
>
|
||||
<NewTaskToolbarTrigger
|
||||
accessibilityLabel="Workspace"
|
||||
icon="point.topleft.down.curvedto.point.bottomright.up"
|
||||
label={workspaceLabel}
|
||||
/>
|
||||
</ControlPillMenu>
|
||||
</ScrollView>
|
||||
{toolbarScrollEdges.showLeftFade ? (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
bottom: 0,
|
||||
experimental_backgroundImage: `linear-gradient(to right, ${sheetFadeOpaque} 0%, ${sheetFadeTransparent} 100%)`,
|
||||
left: 0,
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
width: TOOLBAR_FADE_WIDTH,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{toolbarScrollEdges.showRightFade ? (
|
||||
<View
|
||||
pointerEvents="none"
|
||||
style={{
|
||||
bottom: 0,
|
||||
experimental_backgroundImage: `linear-gradient(to right, ${sheetFadeTransparent} 0%, ${sheetFadeOpaque} 100%)`,
|
||||
position: "absolute",
|
||||
right: 0,
|
||||
top: 0,
|
||||
width: TOOLBAR_FADE_WIDTH,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</View>
|
||||
<ControlPill
|
||||
accessibilityLabel={flow.submitting ? "Starting task" : "Start task"}
|
||||
icon="arrow.up"
|
||||
label={flow.submitting ? "Starting" : "Start"}
|
||||
onPress={() => void handleStart()}
|
||||
variant="primary"
|
||||
disabled={
|
||||
@@ -488,7 +705,7 @@ export function NewTaskDraftScreen(props: {
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</KeyboardStickyView>
|
||||
</KeyboardAvoidingView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user