Skip to content

Commit f51c9e9

Browse files
fix(mobile): improve palette and thread row interactions
1 parent 1cf2240 commit f51c9e9

6 files changed

Lines changed: 323 additions & 159 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { ComponentProps, ReactNode } from "react";
2+
import { Pressable, View } from "react-native";
3+
import { GestureDetector } from "react-native-gesture-handler";
4+
5+
import { cn } from "../lib/cn";
6+
import { useHoverGesture } from "../lib/useHoverGesture";
7+
8+
/** Shared row feedback, layered over the background so selection stays visible. */
9+
export function RowPressable({
10+
children,
11+
className,
12+
interactionClassName = "bg-foreground",
13+
...props
14+
}: Omit<ComponentProps<typeof Pressable>, "children"> & {
15+
readonly children: ReactNode;
16+
readonly interactionClassName?: string;
17+
}) {
18+
const { hovered, hoverGesture } = useHoverGesture(props.disabled ?? false);
19+
return (
20+
<GestureDetector gesture={hoverGesture}>
21+
<Pressable {...props} className={cn("relative overflow-hidden", className)}>
22+
{({ pressed }) => (
23+
<>
24+
<View
25+
pointerEvents="none"
26+
className={cn("absolute inset-0", interactionClassName)}
27+
style={{ opacity: props.disabled ? 0 : pressed ? 0.2 : hovered ? 0.1 : 0 }}
28+
/>
29+
{children}
30+
</>
31+
)}
32+
</Pressable>
33+
</GestureDetector>
34+
);
35+
}

‎apps/mobile/src/features/keyboard/CommandPalette.tsx‎

Lines changed: 183 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useNavigation } from "@react-navigation/native";
22
import { THREAD_JUMP_KEYBINDING_COMMANDS } from "@t3tools/contracts";
33
import { threadPullRequestSearchTerms } from "@t3tools/shared/threadPullRequests";
4-
import { useEffect, useMemo, useRef, useState } from "react";
4+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
55
import {
66
FlatList,
77
KeyboardAvoidingView,
@@ -10,9 +10,15 @@ import {
1010
TextInput,
1111
useWindowDimensions,
1212
View,
13+
type CellRendererProps,
1314
} from "react-native";
1415

15-
import { AppText as Text, AppTextInput } from "../../components/AppText";
16+
import { GestureHandlerRootView } from "react-native-gesture-handler";
17+
18+
import { RowPressable } from "../../components/RowPressable";
19+
import { AppText as Text } from "../../components/AppText";
20+
import { SymbolView, type AppSymbolName } from "../../components/AppSymbol";
21+
import { GlassSurface } from "../../components/GlassSurface";
1622
import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
1723
import { T3KeyboardCommands } from "../../native/T3KeyboardCommands";
1824
import { useProjects, useThreadShell, useThreadShells } from "../../state/entities";
@@ -35,7 +41,82 @@ const PALETTE_COMMANDS: ReadonlyArray<HardwareKeyboardCommand> = [
3541
"palettePrevious",
3642
...THREAD_JUMP_KEYBINDING_COMMANDS,
3743
];
38-
const ROW_HEIGHT = 64;
44+
const ROW_HEIGHT = 50;
45+
46+
const ACTION_ICONS: Record<string, AppSymbolName> = {
47+
newTask: "square.and.pencil",
48+
newThread: "square.and.pencil",
49+
addProject: "folder.badge.plus",
50+
settings: "gearshape",
51+
appearance: "paintbrush",
52+
environments: "desktopcomputer",
53+
usage: "chart.bar.xaxis",
54+
archive: "archivebox",
55+
files: "doc.text",
56+
terminal: "terminal",
57+
review: "arrow.triangle.pull",
58+
copyThreadReference: "link",
59+
};
60+
61+
function itemIcon(item: CommandPaletteItem): AppSymbolName {
62+
if (item.kind === "project") return "folder";
63+
if (item.kind === "thread") return "text.bubble";
64+
return ACTION_ICONS[item.key] ?? "ellipsis";
65+
}
66+
67+
function PaletteCell({
68+
children,
69+
style,
70+
onLayout,
71+
onFocusCapture,
72+
}: CellRendererProps<CommandPaletteItem>) {
73+
// Keep gesture-enabled rows behind stable native cell boundaries as
74+
// virtualization inserts and removes cells from the scroll content.
75+
const viewProps = { style, onLayout, onFocusCapture };
76+
return (
77+
<View {...viewProps} collapsable={false}>
78+
{children}
79+
</View>
80+
);
81+
}
82+
83+
function PaletteRow(props: {
84+
readonly item: CommandPaletteItem;
85+
readonly index: number;
86+
readonly selected: boolean;
87+
readonly onSelect: () => void;
88+
}) {
89+
return (
90+
<RowPressable
91+
accessibilityRole="button"
92+
accessibilityState={{ selected: props.selected }}
93+
onPress={props.onSelect}
94+
className={
95+
props.selected
96+
? "mx-2 flex-row items-center gap-3 rounded-xl bg-primary/10 px-3"
97+
: "mx-2 flex-row items-center gap-3 rounded-xl px-3"
98+
}
99+
style={{ height: ROW_HEIGHT }}
100+
>
101+
<View className="w-7 items-center">
102+
<SymbolView name={itemIcon(props.item)} size={20} tintColorClassName="accent-icon" />
103+
</View>
104+
<View className="flex-1">
105+
<Text numberOfLines={1} className="text-base">
106+
{props.item.title}
107+
</Text>
108+
{props.item.detail ? (
109+
<Text numberOfLines={1} className="text-sm text-foreground-muted">
110+
{props.item.detail}
111+
</Text>
112+
) : null}
113+
</View>
114+
{props.index < 9 ? (
115+
<Text className="text-sm text-foreground-muted">⌘{props.index + 1}</Text>
116+
) : null}
117+
</RowPressable>
118+
);
119+
}
39120

40121
/** Mounted only while open, so the app root does not subscribe to the full thread catalog. */
41122
export function CommandPalette(props: {
@@ -255,6 +336,24 @@ export function CommandPalette(props: {
255336
}
256337
}, [selectedIndex, selectedKey]);
257338

339+
const dismissed = useRef(false);
340+
const handleDismissed = useCallback(() => {
341+
if (dismissed.current) return;
342+
dismissed.current = true;
343+
// Present navigation sheets only after UIKit has dismissed this modal.
344+
props.onClose();
345+
pendingAction.current?.();
346+
}, [props]);
347+
348+
// iOS drops Modal onDismiss when the VC is dismissed mid-presentation (e.g.
349+
// ⌘K during the fade-in) or raced by another sheet — without a fallback the
350+
// palette stays mounted-but-invisible and ⌘K dead-ends on a stale open state.
351+
useEffect(() => {
352+
if (visible) return;
353+
const fallback = setTimeout(handleDismissed, 400);
354+
return () => clearTimeout(fallback);
355+
}, [visible, handleDismissed]);
356+
258357
function close(run?: () => void) {
259358
if (closing.current) return;
260359
closing.current = true;
@@ -283,104 +382,90 @@ export function CommandPalette(props: {
283382
animationType="fade"
284383
onShow={() => inputRef.current?.focus()}
285384
onRequestClose={() => close()}
286-
onDismiss={() => {
287-
// Present navigation sheets only after UIKit has dismissed this modal.
288-
props.onClose();
289-
pendingAction.current?.();
290-
}}
385+
onDismiss={handleDismissed}
291386
>
292-
<T3KeyboardCommands enabledCommands={PALETTE_COMMANDS} onCommand={onCommand}>
293-
<KeyboardAvoidingView
294-
behavior="padding"
295-
className="flex-1 items-center justify-center bg-black/40 p-4"
296-
>
297-
<Pressable
298-
className="absolute inset-0"
299-
accessibilityLabel="Close command palette"
300-
onPress={() => close()}
301-
/>
302-
<View
303-
accessibilityViewIsModal
304-
className="overflow-hidden rounded-2xl border border-border bg-sheet-solid"
305-
style={{ width: Math.min(600, width - 32), height: Math.min(520, height - 80) }}
387+
<GestureHandlerRootView className="flex-1">
388+
<T3KeyboardCommands enabledCommands={PALETTE_COMMANDS} onCommand={onCommand}>
389+
<KeyboardAvoidingView
390+
behavior="padding"
391+
className="flex-1 items-center justify-center p-4"
306392
>
307-
<View className="flex-row items-center gap-2 border-b border-border p-3">
308-
<AppTextInput
309-
ref={inputRef}
310-
accessibilityLabel="Search commands, projects, and threads"
311-
placeholder="Search commands, projects, and threads…"
312-
autoCorrect={false}
313-
autoCapitalize="none"
314-
className="flex-1"
315-
value={query}
316-
onChangeText={(value) => {
317-
setQuery(value);
318-
setSelection(null);
319-
listRef.current?.scrollToOffset({ offset: 0, animated: false });
320-
}}
321-
returnKeyType="go"
322-
submitBehavior="submit"
323-
onSubmitEditing={() => {
324-
const item = results[selectedIndex];
325-
if (item) close(item.run);
326-
}}
327-
/>
328-
<Pressable
329-
accessibilityRole="button"
330-
accessibilityLabel="Close command palette"
331-
className="min-h-11 justify-center px-2"
332-
onPress={() => close()}
333-
>
334-
<Text className="text-primary">Cancel</Text>
335-
</Pressable>
336-
</View>
337-
<FlatList
338-
ref={listRef}
339-
data={results}
340-
extraData={selectedKey}
341-
keyboardShouldPersistTaps="handled"
342-
keyExtractor={(item) => item.key}
343-
getItemLayout={(_, index) => ({
344-
length: ROW_HEIGHT,
345-
offset: ROW_HEIGHT * index,
346-
index,
347-
})}
348-
ListEmptyComponent={
349-
<Text className="p-5 text-center text-foreground-muted">
350-
{search.isPending ? "Searching…" : "No results"}
351-
</Text>
352-
}
353-
renderItem={({ item, index }) => (
354-
<Pressable
355-
accessibilityRole="button"
356-
accessibilityState={{ selected: item.key === selectedKey }}
357-
onPress={() => close(item.run)}
358-
className={
359-
item.key === selectedKey
360-
? "flex-row items-center gap-3 bg-primary/10 px-4"
361-
: "flex-row items-center gap-3 px-4"
362-
}
363-
style={{ height: ROW_HEIGHT }}
364-
>
365-
<View className="flex-1">
366-
<Text numberOfLines={1} className="text-base">
367-
{item.title}
368-
</Text>
369-
{item.detail ? (
370-
<Text numberOfLines={1} className="text-sm text-foreground-muted">
371-
{item.detail}
372-
</Text>
373-
) : null}
374-
</View>
375-
{index < 9 ? (
376-
<Text className="text-sm text-foreground-muted">⌘{index + 1}</Text>
377-
) : null}
378-
</Pressable>
379-
)}
393+
<Pressable
394+
className="absolute inset-0 bg-black/15"
395+
accessibilityLabel="Close command palette"
396+
onPress={() => close()}
380397
/>
381-
</View>
382-
</KeyboardAvoidingView>
383-
</T3KeyboardCommands>
398+
<GlassSurface
399+
accessibilityViewIsModal
400+
style={{
401+
width: Math.min(600, width - 32),
402+
height: Math.min(520, height - 80),
403+
borderRadius: 20,
404+
}}
405+
>
406+
<View className="px-3 pb-2.5 pt-3.5">
407+
<View className="h-[38px] flex-row items-center gap-1.5 pr-2.5 pl-[11px]">
408+
<SymbolView
409+
name="magnifyingglass"
410+
size={15}
411+
tintColorClassName="accent-foreground-muted"
412+
type="monochrome"
413+
/>
414+
<TextInput
415+
ref={inputRef}
416+
accessibilityLabel="Search commands, projects, and threads"
417+
placeholder="Search commands, projects, and threads…"
418+
placeholderTextColorClassName="accent-placeholder"
419+
autoCorrect={false}
420+
autoCapitalize="none"
421+
clearButtonMode="while-editing"
422+
className="h-[34px] flex-1 px-0 py-0 font-sans text-base text-foreground"
423+
value={query}
424+
onChangeText={(value) => {
425+
setQuery(value);
426+
setSelection(null);
427+
listRef.current?.scrollToOffset({ offset: 0, animated: false });
428+
}}
429+
returnKeyType="go"
430+
submitBehavior="submit"
431+
onSubmitEditing={() => {
432+
const item = results[selectedIndex];
433+
if (item) close(item.run);
434+
}}
435+
/>
436+
</View>
437+
</View>
438+
<FlatList
439+
ref={listRef}
440+
CellRendererComponent={PaletteCell}
441+
data={results}
442+
extraData={selectedKey}
443+
keyboardShouldPersistTaps="handled"
444+
keyExtractor={(item) => item.key}
445+
getItemLayout={(_, index) => ({
446+
length: ROW_HEIGHT,
447+
offset: ROW_HEIGHT * index,
448+
index,
449+
})}
450+
contentContainerClassName="pb-2"
451+
ListEmptyComponent={
452+
<Text className="p-5 text-center text-foreground-muted">
453+
{search.isPending ? "Searching…" : "No results"}
454+
</Text>
455+
}
456+
renderItem={({ item, index }) => (
457+
<PaletteRow
458+
item={item}
459+
index={index}
460+
selected={item.key === selectedKey}
461+
onSelect={() => close(item.run)}
462+
/>
463+
)}
464+
/>
465+
</GlassSurface>
466+
</KeyboardAvoidingView>
467+
</T3KeyboardCommands>
468+
</GestureHandlerRootView>
384469
</Modal>
385470
);
386471
}

0 commit comments

Comments
 (0)