-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add coverScreen
prop
#145
base: master
Are you sure you want to change the base?
Add coverScreen
prop
#145
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { | |
StyleProp, | ||
StyleSheet, | ||
TouchableWithoutFeedback, | ||
View, | ||
ViewStyle, | ||
} from "react-native"; | ||
|
||
|
@@ -63,6 +64,7 @@ export interface ModalProps extends ReactNativeModalProps { | |
visible?: boolean; | ||
contentStyle?: StyleProp<ViewStyle>; | ||
useNativeDriver?: boolean; | ||
coverScreen?: boolean; | ||
} | ||
|
||
interface ModalState { | ||
|
@@ -76,6 +78,7 @@ export class Modal extends Component<ModalProps, ModalState> { | |
onHide: () => null, | ||
visible: false, | ||
useNativeDriver: false, | ||
coverScreen: true, | ||
}; | ||
|
||
state: ModalState = { | ||
|
@@ -139,6 +142,7 @@ export class Modal extends Component<ModalProps, ModalState> { | |
children, | ||
onBackdropPress, | ||
contentStyle, | ||
coverScreen, | ||
...otherProps | ||
} = this.props; | ||
const { currentAnimation, visible } = this.state; | ||
|
@@ -176,13 +180,8 @@ export class Modal extends Component<ModalProps, ModalState> { | |
}), | ||
}; | ||
|
||
return ( | ||
<ReactNativeModal | ||
transparent | ||
animationType="none" | ||
{...otherProps} | ||
visible={visible} | ||
> | ||
const content = ( | ||
<> | ||
<TouchableWithoutFeedback onPress={onBackdropPress}> | ||
<Animated.View style={[styles.backdrop, backdropAnimatedStyle]} /> | ||
</TouchableWithoutFeedback> | ||
|
@@ -201,18 +200,33 @@ export class Modal extends Component<ModalProps, ModalState> { | |
{children} | ||
</Animated.View> | ||
)} | ||
</> | ||
); | ||
|
||
if (!coverScreen && visible) { | ||
return ( | ||
<View pointerEvents="box-none" style={StyleSheet.absoluteFill}> | ||
{content} | ||
</View> | ||
); | ||
} | ||
|
||
return ( | ||
<ReactNativeModal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically, following what I'm saying above, you can replace const ModalComponent = props.CustomModalComponent || ReactNativeModal; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. Can do, I'll update the PR shortly. |
||
transparent | ||
animationType="none" | ||
{...otherProps} | ||
visible={visible} | ||
> | ||
{content} | ||
</ReactNativeModal> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
backdrop: { | ||
position: "absolute", | ||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
...StyleSheet.absoluteFillObject, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL :) |
||
backgroundColor: "black", | ||
opacity: 0, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, in the other thread I suggested to just provide a
coverScreen
prop like we're doing in react-native-modal. Still, I think an even better approach for the maintainability of the project would be to instead allow providing aCustomModalComponent
props that we'll just swap withReactNativeModal
below, if provided.Why? Because with the current approach in the future people will also require something like
coverScreenWrapperProps
to inject here, and so on, making the surface area of this API even bigger.The drawback of the
CustomModalComponent
approach is that users will need to maintain the wrapper (so line 208 to 210 in their app — but I'm 100% OK with it given that it's not something that I want to/can maintain withinreact-native-dialog
:/Hope it makes sense.