diff --git a/src/components/Modal.js b/src/components/Modal.js index 7d983014fd..e1ea5a15da 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -66,17 +66,19 @@ type State = { * render() { * const { visible } = this.state; * return ( - * - * - * Example Modal - * - * - * + * + * + * + * Example Modal + * + * + * + * * ); * } * } diff --git a/src/components/Portal/PortalConsumer.js b/src/components/Portal/PortalConsumer.js index 6ecdcb0e15..ad4b984ccf 100644 --- a/src/components/Portal/PortalConsumer.js +++ b/src/components/Portal/PortalConsumer.js @@ -11,13 +11,7 @@ type Props = {| export default class PortalConsumer extends React.Component { async componentDidMount() { - if (!this.props.manager) { - throw new Error( - 'Looks like you forgot to wrap your root component with `Provider` component from `react-native-paper`.\n\n' + - "Please read our getting-started guide and make sure you've followed all the required steps.\n\n" + - 'https://callstack.github.io/react-native-paper/getting-started.html' - ); - } + this._checkManager(); // Delay updating to prevent React from going to infinite loop await Promise.resolve(); @@ -26,15 +20,28 @@ export default class PortalConsumer extends React.Component { } componentDidUpdate() { + this._checkManager(); + this.props.manager.update(this._key, this.props.children); } componentWillUnmount() { + this._checkManager(); + this.props.manager.unmount(this._key); } _key: any; + _checkManager() { + if (!this.props.manager) { + throw new Error( + 'Looks like you forgot to wrap your root component with `Provider` component from `react-native-paper`.\n\n' + + "Please read our getting-started guide and make sure you've followed all the required steps.\n\n" + + 'https://callstack.github.io/react-native-paper/getting-started.html' + ); + } + } render() { return null; }