|
6 | 6 | Modal as RNModal,
|
7 | 7 | ModalProps as RNModalProps,
|
8 | 8 | TouchableWithoutFeedback,
|
9 |
| - GestureResponderEvent |
| 9 | + GestureResponderEvent, |
| 10 | + KeyboardAvoidingView, |
| 11 | + KeyboardAvoidingViewProps |
10 | 12 | } from 'react-native';
|
11 | 13 | import {BlurViewPackage} from '../../optionalDependencies';
|
12 | 14 | import {Constants, asBaseComponent} from '../../commons/new';
|
@@ -46,6 +48,14 @@ export interface ModalProps extends RNModalProps {
|
46 | 48 | * Should add a GestureHandlerRootView (Android only)
|
47 | 49 | */
|
48 | 50 | useGestureHandlerRootView?: boolean;
|
| 51 | + /** |
| 52 | + * Should add a KeyboardAvoidingView (iOS only) |
| 53 | + */ |
| 54 | + useKeyboardAvoidingView?: boolean; |
| 55 | + /** |
| 56 | + * Send additional props to the KeyboardAvoidingView (iOS only) |
| 57 | + */ |
| 58 | + keyboardAvoidingViewProps?: KeyboardAvoidingViewProps; |
49 | 59 | }
|
50 | 60 |
|
51 | 61 | /**
|
@@ -93,20 +103,35 @@ class Modal extends Component<ModalProps> {
|
93 | 103 | }
|
94 | 104 |
|
95 | 105 | render() {
|
96 |
| - const {blurView, enableModalBlur, visible, useGestureHandlerRootView, ...others} = this.props; |
| 106 | + const { |
| 107 | + blurView, |
| 108 | + enableModalBlur, |
| 109 | + visible, |
| 110 | + useGestureHandlerRootView, |
| 111 | + useKeyboardAvoidingView, |
| 112 | + keyboardAvoidingViewProps, |
| 113 | + ...others |
| 114 | + } = this.props; |
97 | 115 | const defaultContainer = enableModalBlur && Constants.isIOS && BlurView ? BlurView : View;
|
98 | 116 | const useGestureHandler = useGestureHandlerRootView && Constants.isAndroid;
|
99 | 117 | const GestureContainer = useGestureHandler ? GestureHandlerRootView : React.Fragment;
|
100 | 118 | const gestureContainerProps = useGestureHandler ? {style: styles.fill} : {};
|
| 119 | + const useKeyboardAvoiding = useKeyboardAvoidingView && Constants.isIOS; |
| 120 | + const KeyboardAvoidingContainer = useKeyboardAvoiding ? KeyboardAvoidingView : React.Fragment; |
| 121 | + const keyboardAvoidingContainerProps = useKeyboardAvoiding |
| 122 | + ? {behavior: 'padding', ...keyboardAvoidingViewProps, style: [styles.fill, keyboardAvoidingViewProps?.style]} |
| 123 | + : {}; |
101 | 124 | const Container: any = blurView ? blurView : defaultContainer;
|
102 | 125 |
|
103 | 126 | return (
|
104 | 127 | <RNModal visible={Boolean(visible)} {...others}>
|
105 | 128 | <GestureContainer {...gestureContainerProps}>
|
106 |
| - <Container style={styles.fill} blurType="light"> |
107 |
| - {this.renderTouchableOverlay()} |
108 |
| - {this.props.children} |
109 |
| - </Container> |
| 129 | + <KeyboardAvoidingContainer {...keyboardAvoidingContainerProps}> |
| 130 | + <Container style={styles.fill} blurType="light"> |
| 131 | + {this.renderTouchableOverlay()} |
| 132 | + {this.props.children} |
| 133 | + </Container> |
| 134 | + </KeyboardAvoidingContainer> |
110 | 135 | </GestureContainer>
|
111 | 136 | </RNModal>
|
112 | 137 | );
|
|
0 commit comments