问题
I want to resize text with emoji in TextInput, only text works well but when insert emoji not.
const [fontSize, setFontSize] = useState(16);
const input = useRef(null);
// resize Input func
const onFontSizeChange = () => {
setFontSize(fontSize + 5);
input.current.setNativeProps({
style: {
fontSize: fontSize + 5,
},
});
}
<TextInput
ref={input}
multiline={true}
style={{fontSize: 16}}
forceStrutHeight={true}
value={textValue}
onChangeText={typedText => {
validate(typedText);
}}
/>
How to I do this?
回答1:
Just use a state object as style and mutate the style object when you click the button.
const [style, setStyle] = useState({ fontSize: 16})
const onButtonClick = () => {
setStyle({ fontSize: 20, lineHeight: 23 })
}
<TextInput
multiline={true}
style={style}
forceStrutHeight={true}
value={textValue}
onChangeText={typedText => {
validate(typedText);
}}
/>
来源:https://stackoverflow.com/questions/58917257/react-native-resize-emoji-and-text-size-in-textinput-together