From 114dde99ce579d2ce93d11a3efb244b79b8a23dc Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Mon, 4 Apr 2016 08:47:11 -0700 Subject: [PATCH] Fix TouchableNativeFeedback state propagating to children Summary:For some reason Android propagates the the pressed state to all of the ViewGroup's children when calling `setPressed`. This caused the issue described in #3952. Luckily we can override the `dispatchSetPressed` method of ViewGroup to prevent it from doing so. Had to dig in the Android source a bit to find this one, here's the relevant pieces : https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/View.java#L7883 https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewGroup.java#L3722 **Test plan (required)** Reproduced the bug using [this gist](https://gist.github.com/janicduplessis/9f1d42c670aefd660afb4c96e8bb6a4f) in UIExplorer. Touching the parent should not trigger the ripple on the children. I also made sure all the touchable still work properly. Fixes #3952 Closes https://github.com/facebook/react-native/pull/6783 Differential Revision: D3133407 fb-gh-sync-id: 317e55de2652ea185a1082cd96b8fe3a8b807962 fbshipit-source-id: 317e55de2652ea185a1082cd96b8fe3a8b807962 --- .../java/com/facebook/react/views/view/ReactViewGroup.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java index fcd2fd5eb6f..76fa422c2f4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.java @@ -377,6 +377,12 @@ public class ReactViewGroup extends ViewGroup implements return mPointerEvents; } + @Override + protected void dispatchSetPressed(boolean pressed) { + // Prevents the ViewGroup from dispatching the pressed state + // to it's children. + } + /*package*/ void setPointerEvents(PointerEvents pointerEvents) { mPointerEvents = pointerEvents; }