Skip to content

Commit eec6277

Browse files
authored
Modal - support - KeyboardAvoidingView (#2019)
* Modal - support - KeyboardAvoidingView * Add useKeyboardAvoidingView
1 parent ab7611d commit eec6277

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

demo/src/screens/incubatorScreens/IncubatorDialogScreen.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component} from 'react';
2-
import {StyleSheet, ModalProps} from 'react-native';
2+
import {StyleSheet} from 'react-native';
33
import {FlatList} from 'react-native-gesture-handler';
4-
import {View, Text, Card, Button, Incubator, Colors, Spacings} from 'react-native-ui-lib';
4+
import {View, Text, Card, Button, Incubator, Colors, Spacings, ModalProps} from 'react-native-ui-lib';
55

66
interface Item {
77
value: string;

src/components/modal/index.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import {
66
Modal as RNModal,
77
ModalProps as RNModalProps,
88
TouchableWithoutFeedback,
9-
GestureResponderEvent
9+
GestureResponderEvent,
10+
KeyboardAvoidingView,
11+
KeyboardAvoidingViewProps
1012
} from 'react-native';
1113
import {BlurViewPackage} from '../../optionalDependencies';
1214
import {Constants, asBaseComponent} from '../../commons/new';
@@ -46,6 +48,14 @@ export interface ModalProps extends RNModalProps {
4648
* Should add a GestureHandlerRootView (Android only)
4749
*/
4850
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;
4959
}
5060

5161
/**
@@ -93,20 +103,35 @@ class Modal extends Component<ModalProps> {
93103
}
94104

95105
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;
97115
const defaultContainer = enableModalBlur && Constants.isIOS && BlurView ? BlurView : View;
98116
const useGestureHandler = useGestureHandlerRootView && Constants.isAndroid;
99117
const GestureContainer = useGestureHandler ? GestureHandlerRootView : React.Fragment;
100118
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+
: {};
101124
const Container: any = blurView ? blurView : defaultContainer;
102125

103126
return (
104127
<RNModal visible={Boolean(visible)} {...others}>
105128
<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>
110135
</GestureContainer>
111136
</RNModal>
112137
);

0 commit comments

Comments
 (0)