Skip to content

Commit

Permalink
Remove unsafe lifecycles usage
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[General][Changed] - [Modal] removed UNSAFE_componentWillReceiveProps lifecycle usage

Reviewed By: lunaleaps

Differential Revision: D27523213

fbshipit-source-id: 288b91bc6c479c62313ba17047069893cd19588c
  • Loading branch information
Nadiia D authored and facebook-github-bot committed Apr 2, 2021
1 parent 1b50722 commit a782b6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
34 changes: 20 additions & 14 deletions Libraries/Modal/Modal.js
Expand Up @@ -154,6 +154,20 @@ export type Props = $ReadOnly<{|
onOrientationChange?: ?DirectEventHandler<OrientationChangeEvent>,
|}>;

function confirmProps(props: Props) {
if (__DEV__) {
if (
props.presentationStyle &&
props.presentationStyle !== 'overFullScreen' &&
props.transparent === true
) {
console.warn(
`Modal with '${props.presentationStyle}' presentation style and 'transparent' value is not supported.`,
);
}
}
}

class Modal extends React.Component<Props> {
static defaultProps: {|hardwareAccelerated: boolean, visible: boolean|} = {
visible: true,
Expand All @@ -167,7 +181,9 @@ class Modal extends React.Component<Props> {

constructor(props: Props) {
super(props);
Modal._confirmProps(props);
if (__DEV__) {
confirmProps(props);
}
this._identifier = uniqueModalIdentifier++;
}

Expand All @@ -190,19 +206,9 @@ class Modal extends React.Component<Props> {
}
}

UNSAFE_componentWillReceiveProps(nextProps: Props) {
Modal._confirmProps(nextProps);
}

static _confirmProps(props: Props) {
if (
props.presentationStyle &&
props.presentationStyle !== 'overFullScreen' &&
props.transparent === true
) {
console.warn(
`Modal with '${props.presentationStyle}' presentation style and 'transparent' value is not supported.`,
);
componentDidUpdate() {
if (__DEV__) {
confirmProps(this.props);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/rn-tester/js/examples/Modal/ModalExample.js
Expand Up @@ -298,6 +298,7 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
exports.examples = [
{
title: 'Modal Presentation',
name: 'basic',
description: 'Modals can be presented with or without animation',
render: (): React.Node => <ModalExample />,
},
Expand Down

0 comments on commit a782b6f

Please sign in to comment.