Open megantaylor opened 2 years ago
The issue is valid!
Hi @megantaylor, Thanks for submitting an issue!
I can't seem to reproduce this from the given steps. Could you please provide a simple self-contained snippet of code that reproduces the problem?
Cheers
Hi @kacperkapusciak, thanks for the reply! (I work with @megantaylor)
I've reproduced the issue here: https://github.com/jparkrr/repro-kav-bug
Here's a video. Keep an eye on whether the contents of tab two's KeyboardAvoidingView is vertically centered, as it should be based on the styles.
https://user-images.githubusercontent.com/872456/143946892-8bd6e395-48a6-4293-bbb4-4381075850c7.mp4
I'm actually facing the same issue before, but at the time I don't have time to submit an issue.
So basically the issue in my case was:
KeyboardAvoidingView
in both screen 1 & screen 2, KeyboardAvoidingView
will be stuck in the opening state on screen 1However, the issue only happens on iOS.
I'm facing the same issue as mentioned by @chungweileong94
any movement on this issue? we'd love to use reactFreeze in our app, but can't until there's a solution for this problem.
Not sure how easily this is addressed with react-native-screens/react-native-freeze
, but I have a working solution that requires a minor patch to react native KeyBoardAvoidingView
diff --git a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
index 26897f1..831bb90 100644
--- a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
+++ b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js
@@ -104,7 +104,7 @@ class KeyboardAvoidingView extends React.Component<Props, State> {
};
_updateBottomIfNecesarry = () => {
- if (this._keyboardEvent == null) {
+ if (this._keyboardEvent == null || !this.props.enabled) {
this.setState({bottom: 0});
return;
}
and using useIsFocused
hook on the actual KeyboardAvoidingView component.
import { useIsFocused } from "@react-navigation/native";
...
const isFocussed = useIsFocused();
return (
<KeyboardAvoidingView enabled={isFocussed}>
...
</KeyboardAvoidingView>
);
That way the delayed onLayout view changes wont be triggered on the frozen screens when returning.
also ran into this issue recently. workaround from @owinter86 solved it for now
Another option is providing a key to the KeyboardAvoidingView
<KeyboardAvoidingView
key={isFocused ? 'focused' : 'not-focused'}
This will force a React re-render of the keyboardAvoidingView :)
Another option is providing a key to the KeyboardAvoidingView
<KeyboardAvoidingView key={isFocused ? 'focused' : 'not-focused'}
This will force a React re-render of the keyboardAvoidingView :)
Triggering a re-render of a keyboard avoiding view on every navigation hurts performance too much (at least for us). @owinter86's patch is far more performant.
@cjshearer interesting! I only use KeyboardAvoidingView in screens where it is needed so it does not hurt me as much. How did you measure this?
@cjshearer interesting! I only use KeyboardAvoidingView in screens where it is needed so it does not hurt me as much. How did you measure this?
We're trying to use the KeyboardAvoidingView in a generic ScreenLayout component that wraps each of our screens to avoid duplication, but I see how your approach would make re-rendering on navigation far more palatable.
As for performance measuring, it was purely qualitative. The only thing "measured" was my patience as several seconds went by per-navigation 🙃. Granted, that was in debug mode, but it I can't imagine that would translate well into a release build (and development would still be torture).
Not sure how easily this is addressed with
react-native-screens/react-native-freeze
, but I have a working solution that requires a minor patch to react nativeKeyBoardAvoidingView
diff --git a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js index 26897f1..831bb90 100644 --- a/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js +++ b/node_modules/react-native/Libraries/Components/Keyboard/KeyboardAvoidingView.js @@ -104,7 +104,7 @@ class KeyboardAvoidingView extends React.Component<Props, State> { }; _updateBottomIfNecesarry = () => { - if (this._keyboardEvent == null) { + if (this._keyboardEvent == null || !this.props.enabled) { this.setState({bottom: 0}); return; }
and using
useIsFocused
hook on the actual KeyboardAvoidingView component.import { useIsFocused } from "@react-navigation/native"; ... const isFocussed = useIsFocused(); return ( <KeyboardAvoidingView enabled={isFocussed}> ... </KeyboardAvoidingView> );
That way the delayed onLayout view changes wont be triggered on the frozen screens when returning.
I have this issue in specific place and places where I didn't add enabled
prop become broken after this fix.
So here is my version:
- if (this._keyboardEvent == null) {
+ if (this._keyboardEvent == null || typeof this.props.enabled === 'boolean' && !this.props.enabled) {
Description
Screen A and Screen B are two tabs in a react-navigation bottom tabs navigator.
When switching from Screen A to Screen B after opening and closing the keyboard on Screen A, the KeyboardAvoidingView on Screen B has bottom padding as though the keyboard was still open.
This happens somewhat inconsistently, like every other time I switch.
It seems as though KBAV is not recognizing that the keyboard was closed, or not updating the bottom padding size correctly.
Screenshots
Actual Behavior:
Expected Behavior:
Steps To Reproduce
Expected behavior
KeyboardAvoidingView should not have bottom padding on Screen B
Actual behavior
KeyboardAvoidingView has bottom padding on Screen B
Platform
Workflow
Package versions