-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextInput onContentSizeChange triggers twice inside a Modal #47186
Comments
@ilaloov Is this happening on New architecture as well? |
@shubhamguptadream11 Yes, both with new architecture enabled and disabled |
|
Hey @ilaloov, do you see this issue happening on both Android and iOS? I can see the issue happening on Android but it seems to be fine on iOS. |
@coado I double-checked on iOS (emulator). It might be the emulator, but it triggers twice as well. However, the returned value (height) is constant, whereas on Android, it varies (20.39215660095215, 39.607845306396484). |
@ilaloov This is how it works for me on iPhone 16 emulator. The onContentSizeChange.movcodeimport {Button, Modal, SafeAreaView, StyleSheet, TextInput} from 'react-native';
import React, {useState} from 'react';
export default function App() {
const [modal, setModal] = useState(false);
return (
<SafeAreaView style={styles.container}>
<TextInput
multiline
onContentSizeChange={e => console.log("outside: ", e.nativeEvent.contentSize.height)}
style={styles.textInput}
/>
<Button onPress={() => setModal(true)} title="Show modal" />
<Modal visible={modal}>
<TextInput
multiline
onContentSizeChange={e =>
console.log("inside: ", e.nativeEvent.contentSize.height)
}
style={[styles.textInput, styles.textInputModal]}
/>
<Button onPress={() => setModal(false)} title="Hide modal" />
</Modal>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#ecf0f1',
flex: 1,
justifyContent: 'center',
padding: 8,
},
textInput: {
backgroundColor: 'gray',
},
textInputModal: {
marginTop: 100,
},
}); |
I think I found what causes this issue. The problem is that on Android the screen size in modal view state is updated asynchronous which leads to triggering onLayout in |
Description
When using a TextInput inside a Modal, the onContentSizeChange callback is triggered twice instead of once. Outside the Modal the event triggers correctly (only once).
Steps to reproduce
React Native Version
0.76.0
Affected Platforms
Runtime - Android, Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/ilaloov/textinput-issue
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: