@@ -62,7 +62,7 @@ export const useTextField = (props: TextFieldProps) => {
6262
6363 const { isRTL } = I18nManager ;
6464 const disabled = props . editable === false || props . status === 'disabled' ;
65- const isFloating = isFocused || ! ! props . value || ! ! props . placeholder ;
65+ const isFloating = isFocused || ! ! props . value ;
6666 const hasAccessory = isRTL ? ! ! props . RightAccessory : ! ! props . LeftAccessory ;
6767 const hasError = props . status === 'error' ;
6868
@@ -73,18 +73,19 @@ export const useTextField = (props: TextFieldProps) => {
7373 const { selectionColor : $selectionColor , cursorColor : $cursorColor } =
7474 getAccentColors ( { theme, hasError } ) ;
7575
76- const $placeholderTextColor = theme . colors . onSurfaceVariant ;
77-
7876 // =======================
7977 // LABEL ANIMATION
8078 // =======================
8179
82- const { $animatedLabelWrapperStyle, $animatedLabelTextStyle } =
83- useTextFieldLabelAnimation ( {
84- variant,
85- isFloating,
86- hasAccessory,
87- } ) ;
80+ const {
81+ $animatedLabelWrapperStyle,
82+ $animatedLabelTextStyle,
83+ $animatedPlaceholderStyle,
84+ } = useTextFieldAnimation ( {
85+ variant,
86+ isFloating,
87+ hasAccessory,
88+ } ) ;
8889
8990 // =======================
9091 // HANDLERS
@@ -118,6 +119,7 @@ export const useTextField = (props: TextFieldProps) => {
118119 hasError,
119120 $animatedLabelWrapperStyle,
120121 $animatedLabelTextStyle,
122+ $animatedPlaceholderStyle,
121123 } ;
122124
123125 const LeadingAccessory = isRTL ? props . RightAccessory : props . LeftAccessory ;
@@ -130,10 +132,10 @@ export const useTextField = (props: TextFieldProps) => {
130132 const $pressableStyles = [ $pressableStyle , $pressableStyleOverride ] ;
131133
132134 const data = {
135+ isFocused,
133136 $pressableStyles,
134137 $selectionColor,
135138 $cursorColor,
136- $placeholderTextColor,
137139 LeadingAccessory,
138140 TrailingAccessory,
139141 onFocusHandler,
@@ -154,7 +156,7 @@ export const useTextField = (props: TextFieldProps) => {
154156 } ;
155157} ;
156158
157- const useTextFieldLabelAnimation = ( {
159+ const useTextFieldAnimation = ( {
158160 variant,
159161 isFloating,
160162 hasAccessory,
@@ -165,6 +167,7 @@ const useTextFieldLabelAnimation = ({
165167} ) : {
166168 $animatedLabelWrapperStyle : Animated . WithAnimatedObject < ViewStyle > ;
167169 $animatedLabelTextStyle : Animated . WithAnimatedObject < TextStyle > ;
170+ $animatedPlaceholderStyle : Animated . WithAnimatedObject < TextStyle > ;
168171} => {
169172 const progress = useRef ( new Animated . Value ( isFloating ? 1 : 0 ) ) . current ;
170173
@@ -192,10 +195,16 @@ const useTextFieldLabelAnimation = ({
192195 outputRange : [ INACTIVE_LABEL_TOP_POSITION , activeTop ] ,
193196 } ) ;
194197
198+ const opacity = progress . interpolate ( {
199+ inputRange : [ 0 , 1 ] ,
200+ outputRange : [ 0 , 1 ] ,
201+ } ) ;
202+
195203 if ( variant === 'filled' ) {
196204 return {
197205 $animatedLabelWrapperStyle : { top } ,
198206 $animatedLabelTextStyle : { fontSize } ,
207+ $animatedPlaceholderStyle : { opacity } ,
199208 } ;
200209 }
201210
@@ -216,6 +225,7 @@ const useTextFieldLabelAnimation = ({
216225 ] ,
217226 } ,
218227 $animatedLabelTextStyle : { fontSize } ,
228+ $animatedPlaceholderStyle : { opacity } ,
219229 } ;
220230 } , [ variant , hasAccessory , progress ] ) ;
221231} ;
0 commit comments