Skip to content

Commit 08194df

Browse files
committed
Add coverScreen prop
Fixes: mmazzarolo#120
1 parent 0a9366b commit 08194df

File tree

4 files changed

+37
-20
lines changed

4 files changed

+37
-20
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ const styles = StyleSheet.create({
178178
| keyboardVerticalOffset | number | undefined | keyboardVerticalOffset for iOS |
179179
| verticalButtons | bool | false | Renders button vertically |
180180
| useNativeDriver | bool | false | Defines if animations should use native driver |
181+
| coverScreen | bool | true | Whether an RN modal will be used to cover the entire screen |
181182
182183
### Dialog.Input props
183184
@@ -191,14 +192,14 @@ const styles = StyleSheet.create({
191192
192193
### Dialog.CodeInput props
193194
194-
| Name | Type | Default | Description |
195-
| --------------------------- | ------ | --------- | ------------------------------------------------------------ |
196-
| wrapperStyle | any | undefined | The style applied to the input wrapper View |
197-
| digitContainerStyle | any | undefined | The style applied to the digit container View |
198-
| digitContainerFocusedStyle | any | undefined | The style applied to the digit container View when in focus |
199-
| digitStyle | any | undefined | The style applied to the digit text |
200-
| codeLength | number | 4 | The total number of digits |
201-
| onCodeChange | func | undefined | Called when the input changed |
195+
| Name | Type | Default | Description |
196+
| -------------------------- | ------ | --------- | ----------------------------------------------------------- |
197+
| wrapperStyle | any | undefined | The style applied to the input wrapper View |
198+
| digitContainerStyle | any | undefined | The style applied to the digit container View |
199+
| digitContainerFocusedStyle | any | undefined | The style applied to the digit container View when in focus |
200+
| digitStyle | any | undefined | The style applied to the digit text |
201+
| codeLength | number | 4 | The total number of digits |
202+
| onCodeChange | func | undefined | Called when the input changed |
202203
203204
`Dialog.CodeInput` also accepts all the React-Native's `TextInput` component props.
204205

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Container.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export type DialogContainerProps = PropsWithChildren<{
3737
onRequestClose?: () => void;
3838
keyboardVerticalOffset?: number;
3939
useNativeDriver?: boolean;
40+
coverScreen?: boolean;
4041
}>;
4142

4243
const DialogContainer: React.FC<DialogContainerProps> = (props) => {

src/Modal.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
StyleProp,
1010
StyleSheet,
1111
TouchableWithoutFeedback,
12+
View,
1213
ViewStyle,
1314
} from "react-native";
1415

@@ -63,6 +64,7 @@ export interface ModalProps extends ReactNativeModalProps {
6364
visible?: boolean;
6465
contentStyle?: StyleProp<ViewStyle>;
6566
useNativeDriver?: boolean;
67+
coverScreen?: boolean;
6668
}
6769

6870
interface ModalState {
@@ -76,6 +78,7 @@ export class Modal extends Component<ModalProps, ModalState> {
7678
onHide: () => null,
7779
visible: false,
7880
useNativeDriver: false,
81+
coverScreen: true,
7982
};
8083

8184
state: ModalState = {
@@ -139,6 +142,7 @@ export class Modal extends Component<ModalProps, ModalState> {
139142
children,
140143
onBackdropPress,
141144
contentStyle,
145+
coverScreen,
142146
...otherProps
143147
} = this.props;
144148
const { currentAnimation, visible } = this.state;
@@ -176,13 +180,8 @@ export class Modal extends Component<ModalProps, ModalState> {
176180
}),
177181
};
178182

179-
return (
180-
<ReactNativeModal
181-
transparent
182-
animationType="none"
183-
{...otherProps}
184-
visible={visible}
185-
>
183+
const content = (
184+
<>
186185
<TouchableWithoutFeedback onPress={onBackdropPress}>
187186
<Animated.View style={[styles.backdrop, backdropAnimatedStyle]} />
188187
</TouchableWithoutFeedback>
@@ -201,18 +200,33 @@ export class Modal extends Component<ModalProps, ModalState> {
201200
{children}
202201
</Animated.View>
203202
)}
203+
</>
204+
);
205+
206+
if (!coverScreen && visible) {
207+
return (
208+
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}>
209+
{content}
210+
</View>
211+
);
212+
}
213+
214+
return (
215+
<ReactNativeModal
216+
transparent
217+
animationType="none"
218+
{...otherProps}
219+
visible={visible}
220+
>
221+
{content}
204222
</ReactNativeModal>
205223
);
206224
}
207225
}
208226

209227
const styles = StyleSheet.create({
210228
backdrop: {
211-
position: "absolute",
212-
top: 0,
213-
bottom: 0,
214-
left: 0,
215-
right: 0,
229+
...StyleSheet.absoluteFillObject,
216230
backgroundColor: "black",
217231
opacity: 0,
218232
},

0 commit comments

Comments
 (0)