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

TouchableHighlight component not showing underlayColor on touch unless onPress property is set. #14908

Closed
shadowm2 opened this issue Jul 8, 2017 · 11 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@shadowm2
Copy link

shadowm2 commented Jul 8, 2017

Is this a bug report?

Yes

Have you read the Bugs section of the Contributing to React Native Guide?

No

Environment

  1. react-native -v: react-native-cli: 2.0.1 react-native: 0.45.1
  2. node -v: v6.11.0
  3. npm -v: 3.10.10
  4. yarn --version (if you use Yarn): 0.27.5

Then, specify:

  1. Target Platform (e.g. iOS, Android): Android
  2. Development Operating System (e.g. macOS Sierra, Windows 10): Ubuntu 16.04
  3. Build tools (Xcode or Android Studio version, iOS or Android SDK version, if relevant): SDK 23

Steps to Reproduce

(Write your steps here:)

  1. Create a TouchableHighlight component with a Text as child with some text in it.
  2. Tap on visible Text component and nothing happens(underlay color doesn't affect the text).
  3. Add onPress={aFunction} and it then tap on Text component and underlay color affects the text.

Expected Behavior

I expected the TouchableHighlight component to show underlay color on touch but it doesn't.

Actual Behavior

The TouchableHighlight only shows underlay color on tap, when the onPress property is set for it.

Touching button with onPress property
Touching button without onPresss property

Reproducible Demo

(Paste the link to an example project and exact instructions to reproduce the issue.)
Here's the sample code for this.

import React from 'react';
import {Text, View, StyleSheet, TouchableHighlight} from 'react-native';


export default class StopWatch extends React.Component {
  constructor(props){
    super(props);
    this.styles = this.createStyle();
  };
  submitform() {};
  render() {
    return(
    <View style={this.styles.container}>
        <View style={this.styles.buttonWrapper}>
          <TouchableHighlight style={this.styles.button} onPress={this.submitform} underlayColor="gray">
            <Text>Start</Text>
          </TouchableHighlight>
          <TouchableHighlight style={this.styles.button} underlayColor="gray">
            <Text>Lap</Text>
          </TouchableHighlight>
        </View>
    </View>
    )
  };

  createStyle() {
    return StyleSheet.create({
      container: {
        flex: 1,
        borderColor: 'red',
        borderWidth: 4,
        alignItems: 'stretch'
      }, buttonWrapper: {
        flex: 3,
        borderColor: 'black',
        borderWidth: 4,
        flexDirection : 'row',
        justifyContent: 'space-around',
        alignItems: 'center'
      }, button: {
        borderRadius: 100,
        borderWidth: 4,
        width: 100,
        height: 100,
        justifyContent: 'center',
        alignItems: 'center'
      }
    });
  };
}

@shadowm2 shadowm2 changed the title TouchableHighlight component not showing underlayColor on touch unless onPress property is set(even set to an empty function) TouchableHighlight component not showing underlayColor on touch unless onPress property is set. Jul 8, 2017
@hramos
Copy link
Contributor

hramos commented Jul 10, 2017

Is there a particular use case you have in mind where you would use a TouchableHighlight but not actually assign a onPress function? Why not use a plain old Text component in that case?

@shadowm2
Copy link
Author

@hramos I understand what you're trying to say and actually i have my created my sample application successfully but it just bothers me knowing that i'm living in side of a bug like this.

@hramos
Copy link
Contributor

hramos commented Jul 10, 2017

Fair enough. Seems like something that shouldn't be too hard to fix, feel free to send a PR!

@shadowm2
Copy link
Author

@hramos Sorry I don't know what a PR is. Can you please explain it to me ?

@hramos
Copy link
Contributor

hramos commented Jul 10, 2017

PR = pull request. You can dive into the TouchableHighlight or TouchableWithoutFeedback files and see if you can fix the underlying issue, then submit the fix back to the repo.

dccarmo pushed a commit to dccarmo/react-native that referenced this issue Aug 4, 2017
I was facing the same issue as facebook#14908 and decided to remove the obligation to implement any of the press methods to correctly render touches.
@hramos
Copy link
Contributor

hramos commented Sep 21, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@hramos hramos added the Icebox label Sep 21, 2017
@hramos hramos closed this as completed Sep 21, 2017
@fedealconada
Copy link

@hramos I think this issue is still happening...

@elan
Copy link

elan commented Apr 8, 2018

Can confirm.

@hramos
Copy link
Contributor

hramos commented Apr 9, 2018

New issue, please.

@daveiverson-pear
Copy link

Confirming that this still happens on 0.54.4 when onPress is undefined.

@AliHammoud
Copy link

Hit this particular bug myself.

@facebook facebook locked as resolved and limited conversation to collaborators Sep 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Sep 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants