admin管理员组文章数量:1393049
I am trying to implement autoresizing multiline TextInput.
I searched the web and asked several chat AIs and I got the following code snippet. It works when text is updated by a user with a keyboard.
But it does not work when text is updated programatically by using setText
function. How do I make it work as I intended?
import React, { useState } from 'react';
import { View, TextInput } from 'react-native';
const AutoResizingTextInput = () => {
const [text, setText] = useState('');
const [height, setHeight] = useState(40);
return (
<View>
<TextInput
style={{ height: Math.max(40, height) }}
multiline
onChangeText={setText}
value={text}
onContentSizeChange={(event) => {
setHeight(event.nativeEvent.contentSize.height);
}}
/>
</View>
);
};
本文标签:
版权声明:本文标题:How do I make multiline TextInput resize automatically with text updated programatically in React Native? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744745764a2622867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论