Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce a new method to show tooltip with coordinates #16

Closed
wants to merge 2 commits into from

Conversation

Arthraim
Copy link

@Arthraim Arthraim commented Jun 8, 2016

Hi @chirag04

I'm facing a very tricky problem when I'm using tooltip with redux. I have to call show method during componentDidUpdate stage, but by the time, container view of tooltip would still be in the wrong position. So I add a method to put the container to right place before it gets rendered.

More specifically, I form my view like this

        <WebView>
            <View pointerEvents="none" style={ {
                position: 'absolute',
                top: this.props.targetPosition.clickY,
                left: this.props.targetPosition.clickX,
                width: 1,
                height: 1,
              } }>
              <ToolTip
                ref="theToolTip"
                actions={ this.props.toolTipActions }
                underlayColor='transparent'
                disabled={ true }
                style={ styles.toolTip } />
            </View>
        </WebView>

So the flow is,
-> someone clicks WebView, it tells component where to show the tooltip
-> reducer changes coordinates in states, also map to props
-> componentDidUpdate state: WebView gets new coordinates, call showMenu
-> re-render, apply the new coordinates to the View

What's tricky is when it's in the stage of componentDidUpdate, View has not re-rended yet, so the tooltip shows from old coordinates. Also there's no callback to allow me to do anything (like calling showMenu) after view got re-rendered.

So I expose a new method here to show the tooltip with coordinate, called showFromRect, and I change the container to where it should be. Of course when app runs into render stage it will update the coordinate of the container again, but as long as we passed same coordinates before that, it will remain same position.

Might be too specific, hope someone else would want this too :)

@chirag04
Copy link
Owner

chirag04 commented Jun 8, 2016

How about leveraging onLayout and using that callback for calling showMenu?

@Arthraim
Copy link
Author

Arthraim commented Jun 8, 2016

@chirag04 work a charm! never know I can access new ordinates in onLayout. Thanks for you help and patience. I think the PR could be closed as well.

@chirag04 chirag04 closed this Jun 8, 2016
@fungilation
Copy link

Tangential to the onLayout prop, I'm relying on TouchableHighlight's original x, y coordinates that I expected to carry over in Tooltip. But I see that x, y are always 0, as I filed in #26

@Arthraim, by accessing ordinates, did you mean e.nativeEvent.layout.x and .y?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants