React-Native调整大小的表情符号和TextInput中的文本大小一起

问题描述 投票:0回答:1

我想在TextInput中使用表情符号调整文本大小,只有文本可以正常工作,但插入表情符号时不行。

const input = useRef(null);

// resize Input func
const onFontSizeChange = () => {
    input.current.setNativeProps({
      style: {
        fontSize: 20,
        lineHeight: 23,
      },
    });
}

<TextInput 
    ref={input}
    multiline={true} 
    style={{fontSize: 16}}
    forceStrutHeight={true}  
    value={textValue}
    onChangeText={typedText => {
        validate(typedText);
    }}
/>

我该怎么做?

react-native emoji textinput
1个回答
0
投票

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

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);
    }}
/>
© www.soinside.com 2019 - 2024. All rights reserved.