| 12 | * Portal host is the component which actually renders all Portals. |
| 13 | */ |
| 14 | export default class PortalManager extends React.PureComponent<{}, State> { |
| 15 | state: State = { |
| 16 | portals: [], |
| 17 | }; |
| 18 | |
| 19 | mount = (key: number, children: React.ReactNode) => { |
| 20 | this.setState((state) => ({ |
| 21 | portals: [...state.portals, { key, children }], |
| 22 | })); |
| 23 | }; |
| 24 | |
| 25 | update = (key: number, children: React.ReactNode) => |
| 26 | this.setState((state) => ({ |
| 27 | portals: state.portals.map((item) => { |
| 28 | if (item.key === key) { |
| 29 | return { ...item, children }; |
| 30 | } |
| 31 | return item; |
| 32 | }), |
| 33 | })); |
| 34 | |
| 35 | unmount = (key: number) => |
| 36 | this.setState((state) => ({ |
| 37 | portals: state.portals.filter((item) => item.key !== key), |
| 38 | })); |
| 39 | |
| 40 | render() { |
| 41 | return this.state.portals.map(({ key, children }) => ( |
| 42 | <View |
| 43 | key={key} |
| 44 | collapsable={ |
| 45 | false /* Need collapsable=false here to clip the elevations, otherwise they appear above sibling components */ |
| 46 | } |
| 47 | pointerEvents="box-none" |
| 48 | style={StyleSheet.absoluteFill} |
| 49 | > |
| 50 | {children} |
| 51 | </View> |
| 52 | )); |
| 53 | } |
| 54 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…