Skip to content

Commit

Permalink
fix: check if portal manager is not null for update and unmount and f…
Browse files Browse the repository at this point in the history
…ix the modal doc example (callstack#995)

* fix(portal): check if a portal manager is not null for update and unmount

* docs(portal): fix Modal example
  • Loading branch information
Taym95 authored and Trancever committed Jun 27, 2019
1 parent 446ad94 commit 87855b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/components/Appbar/Appbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Appbar extends React.Component<Props> {
'AppbarAction',
'AppbarBackAction',
'AppbarHeader',
// @ts-ignore
].includes(child.type.name)
) {
return child;
Expand Down
21 changes: 14 additions & 7 deletions src/components/Portal/PortalConsumer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ type Props = {

export default class PortalConsumer extends React.Component<Props> {
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();
Expand All @@ -23,15 +17,28 @@ export default class PortalConsumer extends React.Component<Props> {
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
keyboardAppearance="light"
placeholder="Search"
placeholderTextColor="rgba(0, 0, 0, 0.54)"
rejectResponderTermination={true}
returnKeyType="search"
selectionColor="#6200ee"
style={
Expand All @@ -137,7 +138,8 @@ exports[`Appbar does not pass any additional props to Searchbar 1`] = `
},
Object {
"color": "#000000",
"fontFamily": "Helvetica Neue",
"fontFamily": "System",
"fontWeight": "400",
},
undefined,
]
Expand Down

0 comments on commit 87855b8

Please sign in to comment.