From a782b6f5a1598203e44dd5de80d978a943f4304b Mon Sep 17 00:00:00 2001 From: Nadiia D Date: Fri, 2 Apr 2021 13:06:10 -0700 Subject: [PATCH] Remove unsafe lifecycles usage Summary: Changelog: [General][Changed] - [Modal] removed UNSAFE_componentWillReceiveProps lifecycle usage Reviewed By: lunaleaps Differential Revision: D27523213 fbshipit-source-id: 288b91bc6c479c62313ba17047069893cd19588c --- Libraries/Modal/Modal.js | 34 +++++++++++-------- .../js/examples/Modal/ModalExample.js | 1 + 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Libraries/Modal/Modal.js b/Libraries/Modal/Modal.js index 9423b11f3ea624..6b6688cf5b05b8 100644 --- a/Libraries/Modal/Modal.js +++ b/Libraries/Modal/Modal.js @@ -154,6 +154,20 @@ export type Props = $ReadOnly<{| onOrientationChange?: ?DirectEventHandler, |}>; +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 { static defaultProps: {|hardwareAccelerated: boolean, visible: boolean|} = { visible: true, @@ -167,7 +181,9 @@ class Modal extends React.Component { constructor(props: Props) { super(props); - Modal._confirmProps(props); + if (__DEV__) { + confirmProps(props); + } this._identifier = uniqueModalIdentifier++; } @@ -190,19 +206,9 @@ class Modal extends React.Component { } } - 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); } } diff --git a/packages/rn-tester/js/examples/Modal/ModalExample.js b/packages/rn-tester/js/examples/Modal/ModalExample.js index fec5a88bb54908..1cfae6d4d93f25 100644 --- a/packages/rn-tester/js/examples/Modal/ModalExample.js +++ b/packages/rn-tester/js/examples/Modal/ModalExample.js @@ -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 => , },