React-Native在TextInput中重新调整表情符号的大小和文本大小 [英] React-Native resize emoji and text size in TextInput together

查看:332
本文介绍了React-Native在TextInput中重新调整表情符号的大小和文本大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在TextInput中使用表情符号调整文本大小,只有文本能很好地工作,但插入表情符号时不行。

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);
    }}
/>

我该怎么做?

推荐答案

只需使用状态对象作为样式,并在单击按钮时更改样式对象即可。

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);
    }}
/>

这篇关于React-Native在TextInput中重新调整表情符号的大小和文本大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆