-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Modals on iOS do not respond to the presence of the on-screen keyboard #4218
Comments
Having the same issue |
@Bi0max please add your issue reproduction |
@lukewalczak , hi , it's literally the same as the OP described. It is reproduced just with and empty Modal and an opened keyboard on iOS. |
Hello! I confirm the issue. It seems there is a problem with Portal and its keyboard avoiding behavior on iOS. It also makes SnackBar (placed in Portal) appear under the keyboard on iOS. Reproduced it the same way the issue's author described. Screen.Recording.2024-01-27.at.15.51.45.movMy environment
|
Same issue after upgrading to latest and placing modal within Portal component. |
Same issue, Portal does not response to keybored in IOS even with KeyboardAvoidingView, for anyone who is looking for a solution, you can use Modal from react nativre for IOS with keyboredAvoidView, it works fine |
Has there been any update or progress on this? |
I have fixed this by patching the Here I share the changes in case it's helpful for others. There's probably a better approach, but this might suffice while RNP implement an actual fix. cc @lukewalczak Please ignore some formatting changes in here diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx
index 313ecee43bde4a0b6be9cbd13b673452725f0f6e..12a7e3d0494a5e256ba5e22a89d71572df547789 100644
--- a/src/components/Modal.tsx
+++ b/src/components/Modal.tsx
@@ -7,6 +7,8 @@ import {
Pressable,
View,
ViewStyle,
+ KeyboardAvoidingView,
+ Platform,
} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
@@ -177,11 +179,7 @@ function Modal({
return true;
};
- const subscription = addEventListener(
- BackHandler,
- 'hardwareBackPress',
- onHardwareBackPress
- );
+ const subscription = addEventListener(BackHandler, 'hardwareBackPress', onHardwareBackPress);
return () => subscription.remove();
}, [dismissable, dismissableBackButton, hideModal, visible]);
@@ -204,17 +202,16 @@ function Modal({
<Animated.View
pointerEvents={visible ? 'auto' : 'none'}
accessibilityViewIsModal
- accessibilityLiveRegion="polite"
+ accessibilityLiveRegion='polite'
style={StyleSheet.absoluteFill}
onAccessibilityEscape={hideModal}
- testID={testID}
- >
+ testID={testID}>
<AnimatedPressable
accessibilityLabel={overlayAccessibilityLabel}
- accessibilityRole="button"
+ accessibilityRole='button'
disabled={!dismissable}
onPress={dismissable ? hideModal : undefined}
- importantForAccessibility="no"
+ importantForAccessibility='no'
style={[
styles.backdrop,
{
@@ -225,21 +222,20 @@ function Modal({
testID={`${testID}-backdrop`}
/>
<View
- style={[
- styles.wrapper,
- { marginTop: top, marginBottom: bottom },
- style,
- ]}
- pointerEvents="box-none"
- testID={`${testID}-wrapper`}
- >
- <Surface
- testID={`${testID}-surface`}
- theme={theme}
- style={[{ opacity }, styles.content, contentContainerStyle]}
- >
- {children}
- </Surface>
+ style={[styles.wrapper, { marginTop: top, marginBottom: bottom }, style]}
+ pointerEvents='box-none'
+ testID={`${testID}-wrapper`}>
+ <KeyboardAvoidingView
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
+ keyboardVerticalOffset={100}
+ style={styles.keyboardAvoidingView}>
+ <Surface
+ testID={`${testID}-surface`}
+ theme={theme}
+ style={[{ opacity }, styles.content, contentContainerStyle]}>
+ {children}
+ </Surface>
+ </KeyboardAvoidingView>
</View>
</Animated.View>
);
@@ -260,4 +256,10 @@ const styles = StyleSheet.create({
backgroundColor: 'transparent',
justifyContent: 'center',
},
+ keyboardAvoidingView: {
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'stretch',
+ justifyContent: 'center',
+ },
});
Here's proof of it working: iOSiPhone.15.Pro.Screen.Recording.Aug.21.mp4AndroidShot.2024-08-21.at.18.10.45.mp4 |
Still the issue has been there (Not resolved) |
Current behaviour
On web and Android, the Modal component respects the state of the keyboard, adjusting it's height accordingly. On iOS, however, the Modal does not move up when the keyboard is opened.
This issue is likely related to 2172
Expected behaviour
The Modal component should respect the positions of the keyboard and respond accordingly on all platforms.
How to reproduce?
Preview
iOS:
Android:
What have you tried so far?
We're currently following the workaround listed here.
Your Environment
The text was updated successfully, but these errors were encountered: