7
7
} from 'react-native' ;
8
8
import type { StyleProp , ViewStyle , TextStyle } from 'react-native' ;
9
9
import { TextInput , Text } from 'react-native-paper' ;
10
+ import type { TextInputProps } from 'react-native-paper' ;
10
11
11
12
type OtpInputProps = {
12
13
maxLength : number ;
@@ -18,6 +19,7 @@ type OtpInputProps = {
18
19
otpTextStyle ?: StyleProp < TextStyle > ;
19
20
otpBorderColor ?: string ;
20
21
otpBorderFocusedColor ?: string ;
22
+ textInputProps ?: TextInputProps ;
21
23
} ;
22
24
23
25
export default function OtpInput ( {
@@ -30,6 +32,7 @@ export default function OtpInput({
30
32
otpTextStyle,
31
33
otpBorderColor = '#F6F6F6' ,
32
34
otpBorderFocusedColor = '#6200EE' ,
35
+ textInputProps,
33
36
} : OtpInputProps ) {
34
37
const [ isInputBoxFocused , setIsInputBoxFocused ] = React . useState ( autoFocus ) ;
35
38
const [ otp , setOtp ] = React . useState ( '' ) ;
@@ -58,11 +61,31 @@ export default function OtpInput({
58
61
const handleOnBlur = ( ) => {
59
62
setIsInputBoxFocused ( false ) ;
60
63
} ;
64
+
65
+ const containerStyleObject = StyleSheet . flatten ( [
66
+ defaultStyles . container ,
67
+ containerStyle ,
68
+ ] ) ;
69
+
70
+ const otpContainerStylesObject = StyleSheet . flatten ( [
71
+ defaultStyles . otpContainer ,
72
+ otpContainerStyle ,
73
+ ] ) ;
74
+
75
+ const otpBoxStyleObject = StyleSheet . flatten ( [
76
+ defaultStyles . otpBox ,
77
+ otpBoxStyle ,
78
+ ] ) ;
79
+
80
+ const otpTextStyleObject = StyleSheet . flatten ( [
81
+ defaultStyles . otpText ,
82
+ otpTextStyle ,
83
+ ] ) ;
61
84
return (
62
- < View style = { containerStyle ? containerStyle : styles . container } >
85
+ < View style = { containerStyleObject } >
63
86
< TextInput
64
87
mode = "outlined"
65
- style = { styles . textInput }
88
+ style = { defaultStyles . textInput }
66
89
theme = { {
67
90
roundness : 10 ,
68
91
} }
@@ -73,11 +96,9 @@ export default function OtpInput({
73
96
onBlur = { handleOnBlur }
74
97
keyboardType = "numeric"
75
98
autoFocus = { autoFocus }
99
+ { ...textInputProps }
76
100
/>
77
- < Pressable
78
- style = { otpContainerStyle ? otpContainerStyle : styles . otpContainer }
79
- onPress = { handleOnPress }
80
- >
101
+ < Pressable style = { otpContainerStylesObject } onPress = { handleOnPress } >
81
102
{ boxArray . map ( ( _ , index ) => {
82
103
const isCurrentValue = index === otp . length ;
83
104
const isLastValue = index === maxLength - 1 ;
@@ -86,10 +107,6 @@ export default function OtpInput({
86
107
const isValueFocused =
87
108
isCurrentValue || ( isLastValue && isCodeComplete ) ;
88
109
89
- const otpBoxStyleObject = otpBoxStyle
90
- ? ( otpBoxStyle as ViewStyle )
91
- : styles . otpBox ;
92
-
93
110
return (
94
111
< View
95
112
key = { index }
@@ -101,9 +118,7 @@ export default function OtpInput({
101
118
: otpBorderColor ,
102
119
} }
103
120
>
104
- < Text style = { otpTextStyle ? otpTextStyle : styles . otpText } >
105
- { otp [ index ] || '' }
106
- </ Text >
121
+ < Text style = { otpTextStyleObject } > { otp [ index ] || '' } </ Text >
107
122
</ View >
108
123
) ;
109
124
} ) }
@@ -112,7 +127,7 @@ export default function OtpInput({
112
127
) ;
113
128
}
114
129
115
- const styles = StyleSheet . create ( {
130
+ const defaultStyles = StyleSheet . create ( {
116
131
container : {
117
132
justifyContent : 'center' ,
118
133
alignItems : 'center' ,
0 commit comments