Handle touches when root is a ViewRootImpl

Sometimes (maybe in modals?) the root is not a ReactRootView, it’s an
object which is not castable to a View.  Check for these cases before
trying to cast.
This commit is contained in:
Jonathan Chang
2016-08-30 20:58:51 -07:00
parent 8950c3204d
commit d864296b41
@@ -109,13 +109,25 @@ public class RNSVGSvgView extends ViewGroup {
}
private int getAbsoluteLeft(View view) {
int thisLeft = view.getLeft() - view.getScrollX();
if (view.getParent() == view.getRootView() || view.getParent() instanceof ReactRootView) {
return thisLeft;
}
View parent = (View) view.getParent();
return view.getLeft() - view.getScrollX() + (parent instanceof ReactRootView ? 0 : getAbsoluteLeft(parent));
return thisLeft + getAbsoluteLeft(parent);
}
private int getAbsoluteTop(View view) {
int thisTop = view.getTop() - view.getScrollY();
if (view.getParent() == view.getRootView() || view.getParent() instanceof ReactRootView) {
return thisTop;
}
View parent = (View) view.getParent();
return view.getTop() - view.getScrollY() + (parent instanceof ReactRootView ? 0 : getAbsoluteTop(parent));
return thisTop + getAbsoluteTop(parent);
}
private void dispatch(MotionEvent ev, TouchEventType type) {