-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Opening Modal prevents proper resizing of layout #387
Comments
I also attempted to use the KeyboardAvoidingView component instead, but encountered the same issue. It appears that when the Modal is displayed (with coverScreen=true), the animation breaks, leaving layout in the same position as when keyboard is open. |
Hi @krystianhub Thank you for opening the issue ❤️ Indeed this is kind of known issue. The problem is that as soon as modal appears it handles keyboard on its own way and prevents events propagation to the root view - as a result I'm not receiving events that keyboard is hidden and because of that you see a space which is equal to keyboard size (even if keyboard is already closed). The fix should be implemented on a native side, but right now there is no way to get a So as a workaround you have 2 choices:
import {
KeyboardController,
KeyboardEvents,
} from "react-native-keyboard-controller";
let isClosed = true;
KeyboardEvents.addListener("keyboardDidHide", _ => {
isClosed = true;
});
KeyboardEvents.addListener("keyboardDidShow", _ => {
isClosed = false;
});
const utils = {
waitToBeClosed: () =>
new Promise(resolve => {
if (isClosed) {
resolve(undefined);
return;
}
const subscription = KeyboardEvents.addListener("keyboardDidHide", _ => {
resolve(undefined);
subscription.remove();
});
KeyboardController.dismiss();
}),
};
export default utils; and the before showing a modal we use it like: import KeyboardUtils from './keyboard';
// ...
const onPress = async () => {
await KeyboardUtils.waitToBeClosed();
setModalVisible(true);
}; This is not the best solution, but gives quite pleasant UI and UX so... as a temporary solution we use it 🙂 As I said before - I'm planning to fix the integration with |
Thank you for your quick response. Thanks! |
Describe the bug
When the keyboard is open, launching a Modal (from either the react-native or react-native-modal package) results in the keyboard closing but without correctly adjusting the layout size.
Code snippet
Repo for reproducing
https://github.com/krystianhub/RN-Modal-Issue - Expo Managed workflow; requires compiled app with expo-dev-client.
I can provide the apk if needed. Alternatively, to build it locally yourself:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Keyboard should close and properly resize layout back to its default height.
Video of expected behaviour (recorded with disabled Keyboard Provider, same as default RN behaviour):
https://github.com/kirillzyusko/react-native-keyboard-controller/assets/1358334/afb4ac15-82a9-4e3e-86eb-a5524d50a4ba
Screenshots
Video of the current behaviour:
https://github.com/kirillzyusko/react-native-keyboard-controller/assets/1358334/ca572fdd-72f9-406d-88cd-cc3070a3a1e6
Smartphone (please complete the following information):
Additional context
I discovered a partial solution by adjusting the "coverScreen" attribute to "false" within the Modal element and manually dismissing the keyboard when pressing the "Open Modal" button simultaneously. Nonetheless, when dealing with navigation and headers, the opacity of the Modal's background only extends to the parent view rather than the entire screen. Regrettably, this workaround doesn't fully meet my expectations.
Video of the workaround:
https://github.com/kirillzyusko/react-native-keyboard-controller/assets/1358334/bd90fd3d-aa04-44e7-ad99-e308e5c9f448
The text was updated successfully, but these errors were encountered: