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

TouchableNativeFeedback ripple position bug #28944

Closed
maickonn opened this issue May 21, 2020 · 5 comments
Closed

TouchableNativeFeedback ripple position bug #28944

maickonn opened this issue May 21, 2020 · 5 comments
Labels
Component: TouchableNativeFeedback Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@maickonn
Copy link

maickonn commented May 21, 2020

Description

When you make the second click on the TouchableNativeFeedback, the ripple effect is occurring at the position of the previous click.

Video sample:

Untitled Project

React Native version:

System:
    OS: Windows 10 10.0.18363
    CPU: (8) x64 Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
    Memory: 5.35 GB / 11.89 GB
  Binaries:
    Node: 12.8.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.10.2 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    Android SDK:
      API Levels: 25, 27, 28, 29
      Build Tools: 28.0.2, 28.0.3, 29.0.0, 29.0.2
      System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
      Android NDK: 21.1.6352462
  IDEs:
    Android Studio: Version  3.6.0.0 AI-192.7142.36.36.6392135
  Languages:
    Java: 12.0.2 - C:\Program Files\Java\jdk-12.0.2\bin\javac.EXE
    Python: 3.7.7 - C:\Program Files (x86)\Python37-32\python.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0
    react-native: 0.62.2 => 0.62.2
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Create a TouchableNativeFeedback, make clicks on many different positions.

Expected Results

Ripple must be always on click position.

Snack, code example, screenshot, or link to a repository:

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


const App = () => {
  return (
    <SafeAreaView style={styles.container}>
      <TouchableNativeFeedback background={TouchableNativeFeedback.Ripple('red')}>
        <View style={styles.buttonContainer}>
          <Text style={styles.textButton}>Touch me</Text>
        </View>
      </TouchableNativeFeedback>
    </SafeAreaView>
  )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center'
  },
  buttonContainer: {
    width: 300,
    height: 70,
    justifyContent: 'center',
    borderColor: '#000',
    borderWidth: 2
  },
  textButton: {
    textAlign: 'center'
  }
})

export default App
@stale
Copy link

stale bot commented Aug 22, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 22, 2020
@stale
Copy link

stale bot commented Aug 29, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Aug 29, 2020
@Aparad
Copy link

Aparad commented Mar 1, 2021

Hi! Was this issue somehow resolved? I'm also experiencing this using react-native 0.63.2. I tried some UI libraries with custom components (like react-native-paper), but it seems to be a problem with react-native components which those libraries apparently rely on.

@vlad-the-compiler
Copy link

vlad-the-compiler commented Mar 21, 2021

This has been bugging me for some time now and I've decided to peek at the sources for TouchableNativeFeedback.
It turns out it's just a plain old order-of-operations issue. The ripple effect is triggered before the hotspot position is being updated - as such, each ripple animation is always using the previous position, causing the described behaviour.
As a quick fix, go to node_modules\react-native\Libraries\Components\Touchable\TouchableNativeFeedback.js, and swap lines 188 and 189.

For reference, you should change
this._dispatchPressedStateChange(true);
this._dispatchHotspotUpdate(event);
into
this._dispatchHotspotUpdate(event);
this._dispatchPressedStateChange(true);

I'll add a PR.

@tucomel
Copy link

tucomel commented May 20, 2021

This has been bugging me for some time now and I've decided to peek at the sources for TouchableNativeFeedback.
It turns out it's just a plain old order-of-operations issue. The ripple effect is triggered before the hotspot position is being updated - as such, each ripple animation is always using the previous position, causing the described behaviour.
As a quick fix, go to node_modules\react-native\Libraries\Components\Touchable\TouchableNativeFeedback.js, and swap lines 188 and 189.

For reference, you should change
this._dispatchPressedStateChange(true);
this._dispatchHotspotUpdate(event);
into
this._dispatchHotspotUpdate(event);
this._dispatchPressedStateChange(true);

I'll add a PR.

THX! I solved my 1month problem with an interpretation of your answer.
I was setting setPressed(ispressed) before set a hotspot, with your answer I moved the setPressed right after set the hotspot and everything works like a charm really thanks! <3 <3 <3 <3 <3 <3 <3 <3

image

facebook-github-bot pushed a commit that referenced this issue Jul 7, 2021
…#31777)

Summary:
TouchableNativeFeedback's ripple starts from previous location on subsequent presses. This is similar to #31669

Fixes #28944

Issue

https://user-images.githubusercontent.com/23293248/123521731-1f375f00-d6d6-11eb-8e4c-fc5ffb322e67.mov

Fix

https://user-images.githubusercontent.com/23293248/123521735-2bbbb780-d6d6-11eb-88b2-be75342cf22a.mov

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - TouchableNativeFeedback ripple starts on previous touch location.

Pull Request resolved: #31777

Test Plan: Tested TouchableNativeFeedback examples in rn-tester app. Registering coordinates before pressed command fixes the issue.

Reviewed By: lunaleaps

Differential Revision: D29496515

Pulled By: kacieb

fbshipit-source-id: 77ac626181a61eee2cd30c4d48e52d10d800f2d8
@facebook facebook locked as resolved and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: TouchableNativeFeedback Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
5 participants