File tree 7 files changed +33
-9
lines changed
7 files changed +33
-9
lines changed Original file line number Diff line number Diff line change 1
1
import { useEffect } from 'react' ;
2
2
import { StyleSheet , Animated , useAnimatedValue } from 'react-native' ;
3
+ import { DEFAULT_DARK_COLOR } from '../constants' ;
4
+ import { useTextInputOTP } from '../hooks/use-text-input-otp' ;
3
5
4
- export function AnimatedCaret ( ) {
6
+ export function Caret ( ) {
5
7
const opacity = useAnimatedValue ( 0 ) ;
8
+ const { caretColor } = useTextInputOTP ( ) ;
6
9
7
10
useEffect ( ( ) => {
8
11
Animated . loop (
@@ -21,14 +24,20 @@ export function AnimatedCaret() {
21
24
) . start ( ) ;
22
25
} , [ opacity ] ) ;
23
26
24
- return < Animated . View style = { [ styles . caret , { opacity } ] } /> ;
27
+ return (
28
+ < Animated . View
29
+ style = { [
30
+ styles . caret ,
31
+ { opacity, backgroundColor : caretColor ?? DEFAULT_DARK_COLOR } ,
32
+ ] }
33
+ />
34
+ ) ;
25
35
}
26
36
27
37
const styles = StyleSheet . create ( {
28
38
caret : {
29
39
width : 2 ,
30
40
height : 16 ,
31
41
borderRadius : 16 ,
32
- backgroundColor : '#030712' ,
33
42
} ,
34
43
} ) ;
Original file line number Diff line number Diff line change 1
1
import { View , StyleSheet } from 'react-native' ;
2
+ import { DEFAULT_DARK_COLOR } from '../constants' ;
2
3
import type { TextInputOTPSeparatorProps } from '../types' ;
3
4
4
5
export function TextInputOTPSeparator ( {
@@ -13,7 +14,7 @@ const styles = StyleSheet.create({
13
14
separator : {
14
15
width : 10 ,
15
16
height : 4 ,
16
- backgroundColor : '#030712' ,
17
+ backgroundColor : DEFAULT_DARK_COLOR ,
17
18
borderRadius : 15 ,
18
19
} ,
19
20
} ) ;
Original file line number Diff line number Diff line change 1
1
import { memo } from 'react' ;
2
2
import { Pressable , Text , StyleSheet } from 'react-native' ;
3
- import { AnimatedCaret } from './animated- caret' ;
3
+ import { Caret } from './caret' ;
4
4
import { useTextInputOTP } from '../hooks/use-text-input-otp' ;
5
5
import { useSlotBorderStyles } from '../hooks/use-slot-border-styles' ;
6
6
import { SLOT_HEIGHT , SLOT_WIDTH } from '../constants' ;
@@ -45,7 +45,7 @@ function TextInputOTPSlotComponent({
45
45
</ Text >
46
46
) }
47
47
48
- { shouldRenderCaret && < AnimatedCaret /> }
48
+ { shouldRenderCaret && < Caret /> }
49
49
</ Pressable >
50
50
) ;
51
51
}
Original file line number Diff line number Diff line change 1
- export const BACKSPACE_KEY = 'Backspace' ;
2
1
export const SLOT_WIDTH = 50 ;
3
2
export const SLOT_HEIGHT = 50 ;
3
+ export const FOCUSED_SLOT_HEIGHT = 54 ;
4
+ export const DEFAULT_DARK_COLOR = '#030712' ;
5
+ export const DEFAULT_LIGHT_COLOR = '#E4E7EC' ;
Original file line number Diff line number Diff line change
1
+ import {
2
+ DEFAULT_DARK_COLOR ,
3
+ DEFAULT_LIGHT_COLOR ,
4
+ FOCUSED_SLOT_HEIGHT ,
5
+ SLOT_HEIGHT ,
6
+ } from '../constants' ;
1
7
import type { UseSlotBorderStylesProps } from '../types' ;
2
8
3
9
export function useSlotBorderStyles ( {
@@ -6,8 +12,8 @@ export function useSlotBorderStyles({
6
12
isLast,
7
13
} : UseSlotBorderStylesProps ) {
8
14
return {
9
- height : isFocused ? 54 : 50 ,
10
- borderColor : isFocused ? '#030712' : '#E4E7EC' ,
15
+ height : isFocused ? FOCUSED_SLOT_HEIGHT : SLOT_HEIGHT ,
16
+ borderColor : isFocused ? DEFAULT_DARK_COLOR : DEFAULT_LIGHT_COLOR ,
11
17
borderTopWidth : 2 ,
12
18
borderBottomWidth : 2 ,
13
19
borderLeftWidth : isFocused || isFirst ? 2 : 1 ,
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ export function TextInputOTPProvider({
32
32
onFilled,
33
33
onChangeText,
34
34
caretHidden = false ,
35
+ caretColor,
35
36
children,
36
37
} : TextInputOTPProviderProps ) {
37
38
const [ code , setCode ] = useState ( value ) ;
@@ -98,6 +99,7 @@ export function TextInputOTPProvider({
98
99
blur,
99
100
clear,
100
101
caretHidden,
102
+ caretColor,
101
103
} ) ,
102
104
[
103
105
clear ,
@@ -108,6 +110,7 @@ export function TextInputOTPProvider({
108
110
setValue ,
109
111
value ,
110
112
caretHidden ,
113
+ caretColor ,
111
114
]
112
115
) ;
113
116
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ export type TextInputOTPContextProps = {
20
20
blur : ( ) => void ;
21
21
clear : ( ) => void ;
22
22
caretHidden : boolean ;
23
+ caretColor ?: string ;
23
24
} ;
24
25
25
26
export type TextInputOTPProviderProps = PropsWithChildren <
@@ -31,6 +32,7 @@ export type TextInputOTPProviderProps = PropsWithChildren<
31
32
| 'onFilled'
32
33
| 'value'
33
34
| 'caretHidden'
35
+ | 'caretColor'
34
36
>
35
37
> ;
36
38
@@ -74,4 +76,5 @@ export type TextInputOTPProps = {
74
76
maxLength : number ;
75
77
onFilled ?: ( text : string ) => void ;
76
78
containerStyles ?: StyleProp < ViewStyle > ;
79
+ caretColor ?: string ;
77
80
} & Omit < TextInputProps , 'style' > ;
You can’t perform that action at this time.
0 commit comments