Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

SecretTextInput.android.tsx

56 lines2.2 KB

1import { requireNativeView } from "expo";
2import { processColor, View, type NativeSyntheticEvent, type ViewProps } from "react-native";
3​
4import { flattenThemeColor } from "../../lib/mobileTheme";
5import { useUniwindTheme } from "../../lib/useUniwindTheme";
6import type { SecretTextInputProps } from "./SecretTextInput.types";
7​
8interface NativeSecretInputProps extends ViewProps {
9 readonly inputLabel: string;
10 readonly value: string;
11 readonly placeholder: string;
12 readonly textColor: number;
13 readonly placeholderColor: number;
14 readonly cursorColor: number;
15 readonly fontSize: number;
16 readonly editable: boolean;
17 readonly onChangeText: (event: NativeSyntheticEvent<{ readonly value: string }>) => void;
18 readonly onSubmit: (event: NativeSyntheticEvent<{ readonly value: string }>) => void;
20​
21const NativeSecretInput = requireNativeView<NativeSecretInputProps>("T3SecretInput");
22​
23const FONT_SIZE = 16;
24const LINE_HEIGHT = 24;
25​
26function nativeColor(value: string) {
27 const color = processColor(value);
28 return typeof color === "number" ? color : 0;
30​
31/**
32 * Android's React Native TextInput cannot opt out of credential autofill, so password managers
33 * offer logins above the keyboard. This field is a native EditText that reports no autofill type.
34 * The frame matches AppTextInput's.
35 */
36export function SecretTextInput(props: SecretTextInputProps) {
37 const theme = useUniwindTheme();
38 const surface = theme["--color-input"];
39 return (
40 <View className="min-h-13.5 justify-center rounded-2xl border border-input-border bg-input px-3.5">
41 <NativeSecretInput
42 inputLabel={props.accessibilityLabel}
43 value={props.value}
44 placeholder={props.placeholder}
45 textColor={nativeColor(flattenThemeColor(theme["--color-foreground"], surface))}
46 placeholderColor={nativeColor(flattenThemeColor(theme["--color-placeholder"], surface))}
47 cursorColor={nativeColor(flattenThemeColor(theme["--color-focus"], surface))}
48 fontSize={FONT_SIZE}
49 editable={props.editable}
50 onChangeText={(event) => props.onChangeText(event.nativeEvent.value)}
51 onSubmit={(event) => props.onSubmitEditing(event.nativeEvent.value)}
52 style={{ height: LINE_HEIGHT }}
53 />
54 </View>
55 );