Make sure the showHandler is called only once

This commit is contained in:
Jean Regisser
2015-06-12 16:30:36 +02:00
parent 286148477d
commit fff9affc26

View File

@@ -53,10 +53,13 @@ var Popover = React.createClass({
var {width, height} = x.nativeEvent.layout; var {width, height} = x.nativeEvent.layout;
var contentSize = {width: width, height: height}; var contentSize = {width: width, height: height};
var geom = this.computeGeometry({contentSize: contentSize}); var geom = this.computeGeometry({contentSize: contentSize});
this.setState(Object.assign(geom, {contentSize: contentSize}), () => {
var awaitingShowHandler = this.state.awaitingShowHandler;
this.setState(Object.assign(geom,
{contentSize: contentSize, awaitingShowHandler: undefined}), () => {
// Once state is set, call the showHandler so it can access all the geometry // Once state is set, call the showHandler so it can access all the geometry
// from the state // from the state
this.state.delayedShowHandler(this.transition); awaitingShowHandler && awaitingShowHandler(this.transition);
}); });
}, },
computeGeometry({contentSize, placement}) { computeGeometry({contentSize, placement}) {
@@ -197,7 +200,9 @@ var Popover = React.createClass({
if (willBeVisible) { if (willBeVisible) {
var showHandler = customShowHandler || defaultShowHandler; var showHandler = customShowHandler || defaultShowHandler;
this.setState({contentSize: {}, delayedShowHandler: showHandler}); // We want to call the showHandler only when contentSize is known
// so that it can have logic depending on the geometry
this.setState({contentSize: {}, awaitingShowHandler: showHandler});
} else { } else {
var hideHandler = customHideHandler || defaultHideHandler; var hideHandler = customHideHandler || defaultHideHandler;
hideHandler(this.transition); hideHandler(this.transition);