Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] [TouchableNativeFeedback] parent pressed state also applied to child elements #3952

Closed
ghost opened this issue Nov 6, 2015 · 4 comments
Labels
Help Wanted :octocat: Issues ideal for external contributors. Resolution: Locked This issue was locked by the bot.

Comments

@ghost
Copy link

ghost commented Nov 6, 2015

react-native: 0.14.0-rc

If I have a parent view which is wrapped into an TouchableNativeFeedback element and this parent view has children which are also wrapped into TouchableNativeFeedback, the child elements also show the pressed state as soon as I press the parent.
Already spent some time looking into TouchableNativeFeedback.android.js but I guess that's a problem somewhere deeper.
Kinda behaves like I set the android:duplicateParentState to true on a View.
http://developer.android.com/reference/android/view/View.html#attr_android:duplicateParentState

touchablenativefeedback

'use strict';

var React = require('react-native');

var {
  View,
  TouchableNativeFeedback,
} = React;

var TouchableIssue = React.createClass({

  render() {
    return (
      <TouchableNativeFeedback background={TouchableNativeFeedback.SelectableBackground()} delayPressIn={0}>
        <View style={styles.root}>

          <TouchableNativeFeedback background={TouchableNativeFeedback.SelectableBackgroundBorderless()} delayPressIn={0}>
            <View style={styles.action} />
          </TouchableNativeFeedback>

          <TouchableNativeFeedback background={TouchableNativeFeedback.SelectableBackgroundBorderless()} delayPressIn={0}>
            <View style={styles.action} />
          </TouchableNativeFeedback>

          <TouchableNativeFeedback background={TouchableNativeFeedback.SelectableBackgroundBorderless()} delayPressIn={0}>
            <View style={styles.action} />
          </TouchableNativeFeedback>

        </View>
      </TouchableNativeFeedback>
    )
  },

});

var styles = React.StyleSheet.create({

  root: {
    flexDirection: 'row',
    height: 200,
    margin: 16,
    alignItems: 'center',
    justifyContent: 'space-around',
    backgroundColor: 'rgba(0, 0, 0, .1)',
  },

  action: {
    width: 48,
    height: 48,
    backgroundColor: 'rgba(255, 0, 0, .5)',
  },

});

module.exports = TouchableIssue;
@ide ide added the Android label Nov 6, 2015
@satya164
Copy link
Contributor

+1

@satya164 satya164 added the Help Wanted :octocat: Issues ideal for external contributors. label Dec 24, 2015
@artwyman
Copy link

+1

@janicduplessis
Copy link
Contributor

Thanks @astuetz for the great bug report. I managed to find the problem and fixed it!

@ghost
Copy link
Author

ghost commented Apr 4, 2016

@janicduplessis Awesome, thanks!

@ghost ghost closed this as completed in 114dde9 Apr 4, 2016
zebulgar pushed a commit to nightingale/react-native that referenced this issue Jun 18, 2016
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 facebook#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 facebook#3952
Closes facebook#6783

Differential Revision: D3133407

fb-gh-sync-id: 317e55de2652ea185a1082cd96b8fe3a8b807962
fbshipit-source-id: 317e55de2652ea185a1082cd96b8fe3a8b807962
@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Help Wanted :octocat: Issues ideal for external contributors. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants