I've been trying to figure out how to use Portal.js (since there's no official docs, yet)
https://github.com/facebook/react-native/blob/master/Libraries/Portal/Portal.js
now although the comment at the top says:
* Never use `<Portal>` in your code. There is only one Portal instance rendered
* by the top-level `renderApplication`.
if I don't render <Portal> I get: Calling showModal but no Portal has been rendered.
from reading the docs, it sounds like <Portal> is being auto-rendered somehow...
it is still unclear to me if I should be using Portal at all...
it doesn't seem to be integrated with Modal - which seems to offer a nicer interface...
in any case;
after tinkering around for a bit, I got an example working, if anyone's interested:
import React from 'react-native';
const { View, StyleSheet, AppRegistry } = React;
import Portal from 'react-native/Libraries/Portal/Portal';
import MainAppView from './MyApp/MainAppView';
class MyPortalExample extends React.Component {
componentDidMount() {
const tag = Portal.allocateTag();
setTimeout( ()=> {
Portal.showModal(tag, this._modalComponent());
}, 1000);
setTimeout( ()=> {
Portal.closeModal(tag);
}, 2000);
}
_modalComponent() {
return (<View style={styles.modal} />);
}
render() {
const MainAppView = (<View/>); // load what ever you need
return (
<View style={styles.screen}>
<MainAppView />
<Portal />
</View>
);
}
}
const styles = StyleSheet.create({
screen: {
flex: 1,
// needed since the <Portal> modalsContainer style is using `position: 'absolute'`
backgroundColor: 'transparent'
},
modal: {
width: 200,
height: 200,
backgroundColor: 'rgba(255,255,255, 0.5)'
}
});
AppRegistry.registerComponent('MyPortalExample', () => MyPortalExample);
am I using it correctly?
I've been trying to figure out how to use
Portal.js(since there's no official docs, yet)https://github.com/facebook/react-native/blob/master/Libraries/Portal/Portal.js
now although the comment at the top says:
if I don't render
<Portal>I get:Calling showModal but no Portal has been rendered.from reading the docs, it sounds like
<Portal>is being auto-rendered somehow...it is still unclear to me if I should be using
Portalat all...it doesn't seem to be integrated with
Modal- which seems to offer a nicer interface...in any case;
after tinkering around for a bit, I got an example working, if anyone's interested:
am I using it correctly?