Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Gesture event get different value in iOS & Android. #1681

Closed
ssruoyan opened this issue Oct 30, 2018 · 3 comments
Closed

Gesture event get different value in iOS & Android. #1681

ssruoyan opened this issue Oct 30, 2018 · 3 comments

Comments

@ssruoyan
Copy link

ssruoyan commented Oct 30, 2018

Description

I get a different value in iOS & Android when i bind touch event on an scrollable view.
And i found difference in iOS and Android source code about touch coordinate calculation:
In iOS Source Code Link:

CGPoint screenLocation = [touch locationInView:touch.window];
CGPoint pageLocation = [touch locationInView:_component.weexInstance.rootView];

In my opinion, weexInstance.rootView will always get a weex container not a touch & scroll view. so i often get a equal value of screenX. Why not use touch.view

In Android Source Code Link:

private PointF getEventLocInPageCoordinate(float eventX, float eventY) {
    locEventOffset.set(eventX, eventY);
    locLeftTop.set(0, 0);
    component.computeVisiblePointInViewCoordinate(locLeftTop);

    // here offset scroll length
    locEventOffset.offset(locLeftTop.x, locLeftTop.y);
    return new PointF(WXViewUtils.getWebPxByWidth(locEventOffset.x,component.getInstance().getInstanceViewPortWidth()),
            WXViewUtils.getWebPxByWidth(locEventOffset.y,component.getInstance().getInstanceViewPortWidth()));
  }

 // here computed scrollX, scrollY
 public void computeVisiblePointInViewCoordinate(PointF pointF) {
    View view = getRealView();
    pointF.set(view.getScrollX(), view.getScrollY());
  }

In Android, pageX = eventX + scrollX, which is relative to the scroll view.

Environment

Weex Playground 0.18.0

Broken Example

Link Address: http://dotwe.org/vue/a1cb898b0cdfb5044534b1c849e19e66

See difference in iOS & Android.

Steps to Reproduce

same as above

Thanks

@acton393
Copy link
Member

acton393 commented Oct 31, 2018

The doc for touch.PageX shows, pageX : A long representing the X coordinate of the touch point relative to the viewport, including any scroll offset.

scroll Offset should be taken into consideration, the same as touch.PageY

@ssruoyan
Copy link
Author

ssruoyan commented Oct 31, 2018

Well, i think so. but weexInstance.rootView and scroller view are not the same view for iOS, there is no scroll offset in touch.pageY calculation.

Android set scrollX & scrollY offset by locEventOffset.offset(locLeftTop.x, locLeftTop.y). There is no similar code in iOS

@wqyfavor
Copy link
Member

fixed, #2113

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

No branches or pull requests

4 participants