-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Description
Description
I am working on a chat feature in an app. It works like most chat features. If you type a message and submit, the text is cleared.
The problem is that after clearing the TextInput (input focus is maintained) the first character typed does not fire the onChangeText() callback.
This only is a problem when multiline=true
React Native Version
0.71.10
Output of npx react-native info
System:
OS: macOS 13.4
CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
Memory: 1.30 GB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 16.17.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.6.1 - /usr/local/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.12.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 14.3/14E222b - /usr/bin/xcodebuild
Languages:
Java: 18.0.2 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: Not Found
react-native: Not Found
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
- Tap on TextInput
- Type "hello world"
- Press "submit". Text should be cleared
- Type "H"
- Press "submit". Text will not clear because onChangeText() will not fire.
Snack, code example, screenshot, or link to a repository
const MessageInput = () => {
const [message, setMessage] = useState('');
const submit = () => {
if(!message) {
return;
}
setMessage('');
}
return (
<>
<TextInput
placeholder='Message'
placeholderTextColor={themes.texts.colors.placeholder}
multiline={true}
value={message}
onChangeText={setMessage}
/>
<Button title={'submit'} onPress={() => submit()}/>
</>
);
}