diff --git a/src/Tooltip.js b/src/Tooltip.js index dea7250..47b98cf 100644 --- a/src/Tooltip.js +++ b/src/Tooltip.js @@ -52,6 +52,7 @@ class Tooltip extends React.Component { toggleTooltip = () => { const { onClose } = this.props; + this.getElementPosition(); this.setState(prevState => { if (prevState.isVisible && !isIOS) { onClose && onClose(); @@ -167,20 +168,17 @@ class Tooltip extends React.Component { setTimeout(this.getElementPosition, 500); } - getElementPosition = () => { - if (this.renderedElement) { - NativeMethodsMixin.measureInWindow.call( - this.renderedElement, - (x, y, width, height) => { - this.setState({ - xOffset: x, - yOffset: y, - elementWidth: width, - elementHeight: height, - }); - }, - ); - } + getElementPosition = (event) => { + this.renderedElement && this.renderedElement.measure( + (frameOffsetX, frameOffsetY, width, height, pageOffsetX, pageOffsetY) => { + this.setState({ + xOffset: pageOffsetX, + yOffset: pageOffsetY, + elementWidth: width, + elementHeight: height, + }); + } + ); }; render() { @@ -217,7 +215,7 @@ Tooltip.propTypes = { popover: PropTypes.element, toggleOnPress: PropTypes.bool, height: PropTypes.number, - width: PropTypes.number, + width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), containerStyle: ViewPropTypes.style, pointerColor: PropTypes.string, onClose: PropTypes.func,