react-native-bottom-sheet: [Bug]: Android+iOS TextInput Keyboard lagging BottomSheetModal - Reanimated error
Version
v5
Reanimated Version
v3
Gesture Handler Version
v2
Platforms
Android
What happened?
Keyboard is lagging - Meanwhile this is logging in the console:
Reanimated] Reading from `value` during component render. Please ensure that you do not access the `value` property or use `get` method of a shared value while React is rendering a component.
If you don't want to see this message, you can disable the `strict` mode. Refer to:
https://docs.swmansion.com/react-native-reanimated/docs/debugging/logger-configuration for more details.
Code:
const [text, setText] = useState("")
<BottomSheetModal ref={bottomSheetModalRef} index={1} snapPoints={snapPoints} enablePanDownToClose enableDismissOnClose >
<BottomSheetView>
<BottomSheetTextInput
placeholder='Text...'
value={text}
onChangeText={setText}
/>
</BottomSheetView>
</BottomSheetModal>
-> The error only occurs if the TextInput is connected to a useState.
If I remove this:
value={text} onChangeText={setText}
everything is normal.
https://github.com/user-attachments/assets/0e7359b0-ea6f-466d-b2f2-311edb0282fd
Reproduction steps
Use the code above on Android with BottomSheetModal
Reproduction sample
https://snack.expo.dev/UwhwaCo1GT5m3B_F9dYwX
Relevant log output
WARN [Reanimated] Reading from `value` during component render. Please ensure that you do not access the `value` property or use `get` method of a shared value while React is rendering a component.
If you don't want to see this message, you can disable the `strict` mode. Refer to:
https://docs.swmansion.com/react-native-reanimated/docs/debugging/logger-configuration for more details.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 8
- Comments: 48
Hey I just fixed this using Direct Manipulation
I found a way to fix the flickering issue. So basically we know that the issue is only with the “value” prop. So instead of using it, you need to use defaultValue and ALSO the “key” prop.
Why the key prop ? Let’s imagine we want to change the value of the defaultValue after pressing a button or selecting another component that should have updated the value of the inputText. When using defaultValue, it’s impossible to refresh the value unless… we use the ‘key’ property to reload the inputText and update the text in the inputText
Example :
when I select a cards that I created, my inputText need to updates the text linked to the card. So I use the following example to reload the inputText
And then No flikering issue and i can refresh the inputText normaly
The error still occurs.
This worked for me, thank you 🎉
I just replaced the value prop with the defaultValue prop
Create a TextInput component
its work for me
Yep! you shouldn’t use the prop
valueanymore or at least make sure to keep that initial value outside of react. I think this is not an issue with the library itself, it just can happen when the react tree is not completely updated and you send a new updateYou’re right, thanks! I’m happy enough with this solution until Gorhom addresses it. Thanks again!
I just left the house, but before leaving I noticed that if I comment out the “BottomSheetBackdrop”, meaning I disable it, the input works fine. I hope this helps as a temporary solution until @gorhom can address it.
drop-in replacement for the TextInput, based the solution from @nowayX
@nowayX works for me. Thank you! 🙏
Same issue for me but only if i put TextInput in
<BottomSheetModal> and <BottomSheetView>Even if it’s gorhom or default react textInput