Summary
I want to have text next to the TextInput
's value. This text should not be editable but also needs to be responsive, i.e., it moves as the content length of the TextInput changes so that is always X characters after the TextInput
's value.
Current code
- Having adjacent
TextInput
andText
components does not result in responsive behavior.
<View style={{flexDirection:"row"}}>
<TextInput
defaultValue={stringValue}
{...props}
/>
<Text>%</Text>
</View>
- Modifying
stringValue
to add extra text means that it can be edited by the user.
newStringValue = stringValue + "%";
return (
<View style={{flexDirection:"row"}}>
<TextInput
defaultValue={newStringValue}
{...props}
/>
<Text>%</Text>
</View>
);
Desired behavior
- The text should move as the length of
TextInput
's value changes. - The text is not editable and the cursor in
TextInput
cannot move through the adjacent text.
How can this be achieved?