Skip to content

Commit

Permalink
Merge pull request #3 from hegelstad/master
Browse files Browse the repository at this point in the history
fixed measuring in scrollviews
  • Loading branch information
AndreiCalazans authored Aug 2, 2018
2 parents 00cc9f8 + fe2bb38 commit ea8ac51
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Tooltip extends React.Component<Props, State> {

toggleTooltip = () => {
const { onClose } = this.props;
this.getElementPosition();
this.setState(prevState => {
if (prevState.isVisible && !isIOS) {
onClose && onClose();
Expand Down Expand Up @@ -167,20 +168,17 @@ class Tooltip extends React.Component<Props, State> {
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() {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ea8ac51

Please sign in to comment.