Skip to content

Commit a782b6f

Browse files
Nadiia Dfacebook-github-bot
authored andcommitted
Remove unsafe lifecycles usage
Summary: Changelog: [General][Changed] - [Modal] removed UNSAFE_componentWillReceiveProps lifecycle usage Reviewed By: lunaleaps Differential Revision: D27523213 fbshipit-source-id: 288b91bc6c479c62313ba17047069893cd19588c
1 parent 1b50722 commit a782b6f

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

Libraries/Modal/Modal.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,20 @@ export type Props = $ReadOnly<{|
154154
onOrientationChange?: ?DirectEventHandler<OrientationChangeEvent>,
155155
|}>;
156156

157+
function confirmProps(props: Props) {
158+
if (__DEV__) {
159+
if (
160+
props.presentationStyle &&
161+
props.presentationStyle !== 'overFullScreen' &&
162+
props.transparent === true
163+
) {
164+
console.warn(
165+
`Modal with '${props.presentationStyle}' presentation style and 'transparent' value is not supported.`,
166+
);
167+
}
168+
}
169+
}
170+
157171
class Modal extends React.Component<Props> {
158172
static defaultProps: {|hardwareAccelerated: boolean, visible: boolean|} = {
159173
visible: true,
@@ -167,7 +181,9 @@ class Modal extends React.Component<Props> {
167181

168182
constructor(props: Props) {
169183
super(props);
170-
Modal._confirmProps(props);
184+
if (__DEV__) {
185+
confirmProps(props);
186+
}
171187
this._identifier = uniqueModalIdentifier++;
172188
}
173189

@@ -190,19 +206,9 @@ class Modal extends React.Component<Props> {
190206
}
191207
}
192208

193-
UNSAFE_componentWillReceiveProps(nextProps: Props) {
194-
Modal._confirmProps(nextProps);
195-
}
196-
197-
static _confirmProps(props: Props) {
198-
if (
199-
props.presentationStyle &&
200-
props.presentationStyle !== 'overFullScreen' &&
201-
props.transparent === true
202-
) {
203-
console.warn(
204-
`Modal with '${props.presentationStyle}' presentation style and 'transparent' value is not supported.`,
205-
);
209+
componentDidUpdate() {
210+
if (__DEV__) {
211+
confirmProps(this.props);
206212
}
207213
}
208214

packages/rn-tester/js/examples/Modal/ModalExample.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class ModalExample extends React.Component<{...}, $FlowFixMeState> {
298298
exports.examples = [
299299
{
300300
title: 'Modal Presentation',
301+
name: 'basic',
301302
description: 'Modals can be presented with or without animation',
302303
render: (): React.Node => <ModalExample />,
303304
},

0 commit comments

Comments
 (0)