Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 160 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@testing-library/jest-native": "^5.4.3",
"@testing-library/react-native": "^12.3.0",
"@types/jest": "^29.5.4",
"@types/react": "^18.2.12",
"@types/react": "^19.1.3",
"jest": "^29.7.0",
"prettier": "^3.0.2",
"ts-jest": "^29.1.1",
Expand All @@ -58,5 +58,9 @@
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"dependencies": {
"@gorhom/bottom-sheet": "^5.1.4",
"react-native-gesture-handler": "^2.25.0"
}
}
6 changes: 5 additions & 1 deletion src/OtpInput/OtpInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { styles } from "./OtpInput.styles";
import { OtpInputProps, OtpInputRef } from "./OtpInput.types";
import { VerticalStick } from "./VerticalStick";
import { useOtpInput } from "./useOtpInput";
import { BottomSheetTextInput } from "@gorhom/bottom-sheet";

export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
const {
Expand All @@ -13,6 +14,7 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
forms: { setTextWithRef },
} = useOtpInput(props);
const {
variant = "normal",
disabled,
numberOfDigits = 6,
autoFocus = true,
Expand Down Expand Up @@ -65,6 +67,8 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
...(!!placeholder ? placeholderTextStyle : []),
};

const InputComponent = variant === "bottom-sheet" ? BottomSheetTextInput : TextInput;

return (
<View style={[styles.container, containerStyle, inputsContainerStyle]}>
{Array(numberOfDigits)
Expand Down Expand Up @@ -107,7 +111,7 @@ export const OtpInput = forwardRef<OtpInputRef, OtpInputProps>((props, ref) => {
</Pressable>
);
})}
<TextInput
<InputComponent
value={text}
onChangeText={handleTextChange}
maxLength={numberOfDigits}
Expand Down
1 change: 1 addition & 0 deletions src/OtpInput/OtpInput.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface OtpInputProps {
textProps?: TextProps;
type?: "alpha" | "numeric" | "alphanumeric";
placeholder?: string;
variant?: "normal" | "bottom-sheet";
}

export interface OtpInputRef {
Expand Down
3 changes: 2 additions & 1 deletion src/OtpInput/useOtpInput.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo, useRef, useState } from "react";
import { Keyboard, TextInput } from "react-native";
import { Keyboard } from "react-native";
import { OtpInputProps } from "./OtpInput.types";
import { TextInput } from "react-native-gesture-handler";

const regexMap = {
alpha: /[^a-zA-Z]/,
Expand Down
Loading