React-Native resize emoji and text size in TextInput together

佐手、 提交于 2020-01-16 18:22:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!