Open History to see the last commit
1import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
2import { useAtomSet, useAtomValue } from "@effect/atom-react";
3import { AsyncResult } from "effect/reactivity";
4import { Platform } from "react-native";
5import { useSafeAreaInsets } from "react-native-safe-area-context";
6
7import { AppText as Text } from "../../components/ui/AppText";
8import {
9 DEFAULT_COMPOSER_ENTER_BEHAVIOR,
10 type ComposerEnterBehavior,
11} from "../../lib/composerEnterBehavior";
12import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
13import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
14import { SettingsScreen } from "./components/SettingsScreen";
15import { SettingsSection } from "./components/SettingsSection";
16
17const SEND_MODIFIER = Platform.OS === "android" ? "Ctrl" : "Command";
18
19const ENTER_BEHAVIOR_OPTIONS: ReadonlyArray<{
20 readonly behavior: ComposerEnterBehavior;
21 readonly label: string;
22 readonly description: string;
23}> = [
24 {
25 behavior: "send",
26 label: "Send message",
27 description: "Return sends the message. Shift-Return inserts a new line.",
28 },
29 {
30 behavior: "newline",
31 label: "Insert new line",
32 description: `Return inserts a new line. ${SEND_MODIFIER}-Return sends the message.`,
33 },
34];
35
36export function SettingsKeyboardRouteScreen() {
37 const insets = useSafeAreaInsets();
38 const preferencesResult = useAtomValue(mobilePreferencesAtom);
39 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
40 const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
41 const selectedBehavior = AsyncResult.isSuccess(preferencesResult)
42 ? (preferencesResult.value.composerEnterBehavior ?? DEFAULT_COMPOSER_ENTER_BEHAVIOR)
43 : null;
44
45 return (
46 <SettingsScreen title="Keyboard">
47 <ScrollView
48 contentInsetAdjustmentBehavior="automatic"
49 showsVerticalScrollIndicator={false}
50 className="flex-1"
51 contentContainerClassName="gap-3 px-5 pt-4"
52 contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
53 >
54 <SettingsSection title="Return key">
55 {ENTER_BEHAVIOR_OPTIONS.map((option, index) => (
56 <SettingsChoiceRow
57 key={option.behavior}
58 label={option.label}
59 description={option.description}
60 selected={selectedBehavior === option.behavior}
61 separated={index > 0}
62 disabled={!preferencesReady}
63 onPress={() => savePreferences({ composerEnterBehavior: option.behavior })}
64 />
65 ))}
66 </SettingsSection>
67 <Text className="px-2 text-sm text-foreground-muted">
68 Applies to the composer when a hardware keyboard is connected.
69 </Text>
70 </ScrollView>
71 </SettingsScreen>
72 );
73}