From 5c3f9547c6b1812c5d73def4000d748bd2fefb21 Mon Sep 17 00:00:00 2001 From: Andy Street Date: Thu, 15 Sep 2016 11:01:15 -0700 Subject: [PATCH] Unbreak nodes that use ScrollViews Reviewed By: foghina Differential Revision: D3870895 fbshipit-source-id: e01130f19cca96ae1bcd0b8040e78552727fd6dc --- .../java/com/facebook/react/views/scroll/BUCK | 1 + .../react/views/scroll/ReactScrollView.java | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/BUCK index 22caa2763..1b987d814 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/BUCK @@ -10,6 +10,7 @@ android_library( react_native_target('java/com/facebook/react/touch:touch'), react_native_target('java/com/facebook/react/uimanager:uimanager'), react_native_target('java/com/facebook/react/uimanager/annotations:annotations'), + react_native_dep('libraries/fbcore/src/main/java/com/facebook/common/logging:logging'), react_native_dep('third-party/java/infer-annotations:infer-annotations'), react_native_dep('third-party/java/jsr-305:jsr-305'), react_native_dep('third-party/android/support/v4:lib-support-v4'), diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index f8d6acc74..cf498fceb 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -20,7 +20,9 @@ import android.view.View; import android.widget.OverScroller; import android.widget.ScrollView; +import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.Assertions; +import com.facebook.react.bridge.JSApplicationCausedNativeException; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.common.ReactConstants; @@ -29,6 +31,7 @@ import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.NativeGestureUtil; import com.facebook.react.uimanager.ReactClippingViewGroup; import com.facebook.react.uimanager.ReactClippingViewGroupHelper; +import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.views.view.ReactViewGroup; import com.facebook.react.views.view.ReactViewManager; @@ -47,6 +50,7 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou private static Field sScrollerField; private static boolean sTriedToGetScrollerField = false; + private static boolean sHasWarnedAboutStickyHeaders = false; private final OnScrollDispatchHelper mOnScrollDispatchHelper = new OnScrollDispatchHelper(); private final OverScroller mScroller; @@ -63,7 +67,7 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou private @Nullable Drawable mEndBackground; private int mEndFillColor = Color.TRANSPARENT; private @Nullable int[] mStickyHeaderIndices; - private ReactViewManager mViewManager; + private ViewGroupManager mViewManager; private final ReactViewGroup.ChildDrawingOrderDelegate mContentDrawingOrderDelegate = new ReactViewGroup.ChildDrawingOrderDelegate() { @@ -81,7 +85,7 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou super(context); UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class); - mViewManager = (ReactViewManager) uiManager.getUIImplementation().getViewManager(ReactViewManager.REACT_CLASS); + mViewManager = (ViewGroupManager) uiManager.getUIImplementation().getViewManager(ReactViewManager.REACT_CLASS); mFpsListener = fpsListener; @@ -350,6 +354,19 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou View previousHeader = null; View currentHeader = null; View nextHeader = null; + View firstChild = getChildAt(0); + + if (!(firstChild instanceof ReactViewGroup)) { + if (!sHasWarnedAboutStickyHeaders) { + FLog.w( + ReactConstants.TAG, + "'stickyHeaderIndices' isn't a supported prop type for this UIImplementation (nodes). " + + "It'd be awesome if you could help us support it by sending a diff or PR :)"); + sHasWarnedAboutStickyHeaders = true; + } + return; + } + ReactViewGroup contentView = (ReactViewGroup) getChildAt(0); if (contentView == null) { return;