From d864296b4199e49394912ce3a50a7d9d50a691f9 Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Tue, 30 Aug 2016 20:58:51 -0700 Subject: [PATCH] Handle touches when root is a ViewRootImpl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../main/java/com/horcrux/svg/RNSVGSvgView.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/horcrux/svg/RNSVGSvgView.java b/android/src/main/java/com/horcrux/svg/RNSVGSvgView.java index 2053902f..fbaca806 100644 --- a/android/src/main/java/com/horcrux/svg/RNSVGSvgView.java +++ b/android/src/main/java/com/horcrux/svg/RNSVGSvgView.java @@ -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) {