I’m working on a React Native TextInput where I want to style the decimal part differently from the whole number. I’ve set up a basic structure, but I’m facing challenges in properly styling the decimal part to be 50% smaller than the whole number after the dot.
enter image description hereenter image description here
Thnaks for the help …
<TextInput
style={[
{ color: parseInt(amount) > 0 ? "black" : "gray" },
amount.split('.')[1] ? { fontSize: 16 } : { fontSize: 32 }
]}
value={amount}
keyboardType="numeric"
onChangeText={handleAmountChange}
placeholder="0.000"
placeholderTextColor="#aaa"
/>
2
Answers
You can use text input as a wrapper component and add value as children inside text input, but if you add a children component, you can’t pass a value prop in text input.
Checkout below code:
export default App;
You can modify how the text looks inside textinput by adding conditions and logic.
To style the decimal part of a number in a React Native TextInput differently from the whole number, you can achieve this by using two Text components inside a TextInput or managing the display using a separate Text component layered beneath/above the TextInput.