1
1
import { isEmpty } from 'lodash' ;
2
2
import React , { useMemo , useCallback , useState , useRef } from 'react' ;
3
3
import { StyleSheet , StyleProp , ViewStyle , TextStyle } from 'react-native' ;
4
- import { useDidUpdate , useThemeProps } from 'hooks' ;
4
+ import { useDidUpdate , useThemeProps } from '../../hooks' ;
5
+ import { Colors } from '../../style' ;
5
6
import MaskedInput from '../maskedInput/new' ;
6
7
import TextField , { TextFieldProps , TextFieldRef } from '../../incubator/TextField' ;
7
8
import View from '../view' ;
@@ -97,6 +98,7 @@ function NumberInput(props: NumberInputProps, ref: any) {
97
98
const initialNumber = getInitialNumber ( propsInitialNumber , options ) ;
98
99
const [ data , setData ] = useState < NumberInputData > ( parseInput ( `${ initialNumber } ` , options , propsInitialNumber ) ) ;
99
100
const textField = useRef < TextFieldRef > ( ) ;
101
+ const [ isFocused , setIsFocused ] = useState ( textFieldProps ?. autoFocus ?? false ) ;
100
102
101
103
useDidUpdate ( ( ) => {
102
104
setOptions ( generateOptions ( locale , fractionDigits ) ) ;
@@ -154,11 +156,19 @@ function NumberInput(props: NumberInputProps, ref: any) {
154
156
} , [ data ] ) ;
155
157
156
158
const onBlur = useCallback ( ( ) => {
159
+ setIsFocused ( false ) ;
157
160
if ( textFieldProps ?. validateOnBlur ) {
158
161
textField . current ?. validate ( ) ;
159
162
}
160
- } ,
161
- [ textFieldProps ?. validateOnBlur ] ) ;
163
+ } , [ textFieldProps ?. validateOnBlur ] ) ;
164
+
165
+ const onFocus = useCallback ( ( ) => {
166
+ setIsFocused ( true ) ;
167
+ } , [ ] ) ;
168
+
169
+ const dynamicFieldStyle = useCallback ( ( ) => {
170
+ return isFocused ? { borderBottomColor : Colors . $outlinePrimary } : undefined ;
171
+ } , [ isFocused ] ) ;
162
172
163
173
const renderNumberInput = useCallback ( ( value ?: string ) => {
164
174
return (
@@ -170,16 +180,18 @@ function NumberInput(props: NumberInputProps, ref: any) {
170
180
testID = { `${ testID } .visual` }
171
181
value = { value }
172
182
formatter = { formatter }
183
+ dynamicFieldStyle = { dynamicFieldStyle }
173
184
floatingPlaceholder = { false }
174
185
leadingAccessory = { leadingAccessory }
175
186
trailingAccessory = { trailingAccessory }
176
187
containerStyle = { [ styles . textFieldContainerStyle , textFieldProps ?. containerStyle ] }
177
188
keyboardType = { 'numeric' }
189
+ autoFocus = { false }
178
190
/>
179
191
</ View >
180
192
) ;
181
193
} ,
182
- [ containerStyle , formatter , leadingAccessory , textFieldProps , trailingAccessory , testID ] ) ;
194
+ [ containerStyle , dynamicFieldStyle , formatter , leadingAccessory , textFieldProps , trailingAccessory , testID ] ) ;
183
195
184
196
return (
185
197
< MaskedInput
@@ -191,7 +203,9 @@ function NumberInput(props: NumberInputProps, ref: any) {
191
203
onChangeText = { onChangeText }
192
204
contextMenuHidden = { contextMenuHidden }
193
205
onBlur = { onBlur }
206
+ onFocus = { onFocus }
194
207
editable = { textFieldProps ?. editable }
208
+ autoFocus = { textFieldProps ?. autoFocus }
195
209
/>
196
210
) ;
197
211
}
0 commit comments