diff --git a/src/components/TextInput/Label/InputLabel.tsx b/src/components/TextInput/Label/InputLabel.tsx index df5ade3812..cd9536add6 100644 --- a/src/components/TextInput/Label/InputLabel.tsx +++ b/src/components/TextInput/Label/InputLabel.tsx @@ -1,5 +1,11 @@ import React from 'react'; -import { Animated, StyleSheet, Dimensions } from 'react-native'; +import { + Animated, + ColorValue, + Platform, + StyleSheet, + useWindowDimensions, +} from 'react-native'; import AnimatedText from '../../Typography/AnimatedText'; import type { InputLabelProps } from '../types'; @@ -41,7 +47,7 @@ const InputLabel = (props: InputLabelProps) => { testID, } = props; - const { width } = Dimensions.get('window'); + const { width } = useWindowDimensions(); const paddingOffset = paddingLeft && paddingRight ? { paddingLeft, paddingRight } : {}; @@ -100,7 +106,20 @@ const InputLabel = (props: InputLabelProps) => { ], }; - const textColor = labelError && errorColor ? errorColor : placeholderColor; + const commonStyles = [ + placeholderStyle, + { + top: topPosition, + }, + labelStyle, + paddingOffset || {}, + ]; + + const textColor = ( + labelError && errorColor ? errorColor : placeholderColor + ) as ColorValue; + + const maxWidth = width - (placeholderStyle.paddingHorizontal || 0); return ( // Position colored placeholder and gray placeholder on top of each other and crossfade them @@ -110,7 +129,8 @@ const InputLabel = (props: InputLabelProps) => { style={[ StyleSheet.absoluteFill, styles.labelContainer, - { opacity, width }, + Platform.OS !== 'web' && { width }, + { opacity }, labelTranslationX, ]} > @@ -132,12 +152,7 @@ const InputLabel = (props: InputLabelProps) => { onLayout={onLayoutAnimatedText} onTextLayout={onLabelTextLayout} style={[ - placeholderStyle, - { - top: topPosition, - }, - labelStyle, - paddingOffset || {}, + commonStyles, { color: activeColor, }, @@ -151,15 +166,11 @@ const InputLabel = (props: InputLabelProps) => {