Skip to content

Commit

Permalink
Merge pull request #49789 from bernhardoj/fix/49488-pronouns-field-la…
Browse files Browse the repository at this point in the history
…bel-moving-right-to-left-when-activated

Fix pronouns input label is not aligned to the left when activated
  • Loading branch information
grgia authored Oct 3, 2024
2 parents 897da0e + 7fb059c commit e9d445e
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 37 deletions.
1 change: 0 additions & 1 deletion src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ function BaseTextInput(
to prevent text overlapping with label when scrolling */}
{isMultiline && <View style={[styles.textInputLabelBackground, styles.pointerEventsNone]} />}
<TextInputLabel
isLabelActive={isLabelActive.current}
label={label}
labelTranslateY={labelTranslateY}
labelScale={labelScale}
Expand Down
1 change: 0 additions & 1 deletion src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ function BaseTextInput(
to prevent text overlapping with label when scrolling */}
{isMultiline && <View style={[styles.textInputLabelBackground, styles.pointerEventsNone]} />}
<TextInputLabel
isLabelActive={isLabelActive.current}
label={label}
labelTranslateY={labelTranslateY}
labelScale={labelScale}
Expand Down
28 changes: 3 additions & 25 deletions src/components/TextInput/TextInputLabel/index.native.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
import React, {useState} from 'react';
import React from 'react';
import {Animated} from 'react-native';
import * as styleConst from '@components/TextInput/styleConst';
import useThemeStyles from '@hooks/useThemeStyles';
import type TextInputLabelProps from './types';

function TextInputLabel({isLabelActive, label, labelScale, labelTranslateY}: TextInputLabelProps) {
function TextInputLabel({label, labelScale, labelTranslateY}: TextInputLabelProps) {
const styles = useThemeStyles();
const [width, setWidth] = useState(0);

return (
<Animated.Text
allowFontScaling={false}
onLayout={({nativeEvent}) => {
setWidth(nativeEvent.layout.width);
}}
style={[
styles.textInputLabel,
styles.textInputLabelTransformation(
labelTranslateY,
labelScale.interpolate({
inputRange: [styleConst.ACTIVE_LABEL_SCALE, styleConst.INACTIVE_LABEL_SCALE],
outputRange: [-(width - width * styleConst.ACTIVE_LABEL_SCALE) / 2, 0],
}),
labelScale,
),
// If the label is active but the width is not ready yet, the above translateX value will be 0,
// making the label sits at the top center instead of the top left of the input. To solve it
// move the label by a percentage value with left style as translateX doesn't support percentage value.
width === 0 &&
isLabelActive && {
left: `${-((1 - styleConst.ACTIVE_LABEL_SCALE) * 100) / 2}%`,
},
]}
style={[styles.textInputLabel, styles.textInputLabelTransformation(labelTranslateY, labelScale)]}
>
{label}
</Animated.Text>
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInput/TextInputLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function TextInputLabel({for: inputId = '', label, labelTranslateY, labelScale}:
<Animated.Text
ref={textRef(labelRef)}
role={CONST.ROLE.PRESENTATION}
style={[styles.textInputLabel, styles.textInputLabelDesktop, styles.textInputLabelTransformation(labelTranslateY, 0, labelScale), styles.pointerEventsNone]}
style={[styles.textInputLabel, styles.textInputLabelTransformation(labelTranslateY, labelScale), styles.pointerEventsNone]}
>
{label}
</Animated.Text>
Expand Down
3 changes: 0 additions & 3 deletions src/components/TextInput/TextInputLabel/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ type TextInputLabelProps = {
/** Label scale */
labelScale: Animated.Value;

/** Whether the label is currently active or not */
isLabelActive: boolean;

/** For attribute for label */
for?: string;
};
Expand Down
9 changes: 3 additions & 6 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,7 @@ const styles = (theme: ThemeColors) =>
...FontUtils.fontFamily.platform.EXP_NEUE,
width: '100%',
zIndex: 1,
transformOrigin: 'left center',
},

textInputLabelBackground: {
Expand All @@ -1206,13 +1207,9 @@ const styles = (theme: ThemeColors) =>
backgroundColor: theme.componentBG,
},

textInputLabelDesktop: {
transformOrigin: 'left center',
},

textInputLabelTransformation: (translateY: AnimatableNumericValue, translateX: AnimatableNumericValue, scale: AnimatableNumericValue) =>
textInputLabelTransformation: (translateY: AnimatableNumericValue, scale: AnimatableNumericValue) =>
({
transform: [{translateY}, {translateX}, {scale}],
transform: [{translateY}, {scale}],
} satisfies TextStyle),

baseTextInput: {
Expand Down

0 comments on commit e9d445e

Please sign in to comment.