@@ -2,7 +2,7 @@ import React, {useContext, useRef, useCallback, useState, useMemo} from 'react';
2
2
import { Animated , LayoutChangeEvent , StyleSheet , Platform } from 'react-native' ;
3
3
import { useDidUpdate } from 'hooks' ;
4
4
import { FloatingPlaceholderProps , ValidationMessagePosition } from './types' ;
5
- import { getColorByState } from './Presenter' ;
5
+ import { getColorByState , shouldPlaceholderFloat } from './Presenter' ;
6
6
import { Colors } from '../../style' ;
7
7
import { Constants } from '../../commons/new' ;
8
8
import View from '../../components/view' ;
@@ -11,31 +11,32 @@ import FieldContext from './FieldContext';
11
11
12
12
const FLOATING_PLACEHOLDER_SCALE = 0.875 ;
13
13
14
- const FloatingPlaceholder = ( {
15
- placeholder ,
16
- floatingPlaceholderColor = Colors . $textNeutralLight ,
17
- floatingPlaceholderStyle ,
18
- floatOnFocus ,
19
- validationMessagePosition,
20
- extraOffset = 0 ,
21
- testID
22
- } : FloatingPlaceholderProps ) => {
14
+ const FloatingPlaceholder = ( props : FloatingPlaceholderProps ) => {
15
+ const {
16
+ placeholder ,
17
+ floatingPlaceholderColor = Colors . $textNeutralLight ,
18
+ floatingPlaceholderStyle ,
19
+ validationMessagePosition,
20
+ extraOffset = 0 ,
21
+ testID
22
+ } = props ;
23
23
const context = useContext ( FieldContext ) ;
24
24
const [ placeholderOffset , setPlaceholderOffset ] = useState ( {
25
25
top : 0 ,
26
26
left : 0
27
27
} ) ;
28
- const animation = useRef ( new Animated . Value ( Number ( ( floatOnFocus && context . isFocused ) || context . hasValue ) ) ) . current ;
28
+
29
+ const shouldFloat = shouldPlaceholderFloat ( props , context . isFocused , context . hasValue , context . value ) ;
30
+ const animation = useRef ( new Animated . Value ( Number ( shouldFloat ) ) ) . current ;
29
31
const hidePlaceholder = ! context . isValid && validationMessagePosition === ValidationMessagePosition . TOP ;
30
32
31
33
useDidUpdate ( ( ) => {
32
- const toValue = floatOnFocus ? context . isFocused || context . hasValue : context . hasValue ;
33
34
Animated . timing ( animation , {
34
- toValue : Number ( toValue ) ,
35
+ toValue : Number ( shouldFloat ) ,
35
36
duration : 200 ,
36
37
useNativeDriver : true
37
38
} ) . start ( ) ;
38
- } , [ floatOnFocus , context . isFocused , context . hasValue ] ) ;
39
+ } , [ shouldFloat ] ) ;
39
40
40
41
const animatedStyle = useMemo ( ( ) => {
41
42
return {
0 commit comments