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][New Arch] Buttons inside Animated.View with translate are not clickable #6676

Open
delphinebugner opened this issue Nov 7, 2024 · 2 comments
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided

Comments

@delphinebugner
Copy link

delphinebugner commented Nov 7, 2024

Description

On my app, I have buttons inside Animated Views that translate up.
Right after the translation finished, the pressable action of the button is not executed on click.
If we execute another action (ex. navigating on an other tab and come back), the pressable action is executed on click.

This is what we see on the repro below:

ReproButtonReanimated

Additional notes:

  • New Arch + Android only
  • On real device only, not on emulator (😅 really weird)
  • Pressable and Buttons have the same error
  • Pressable and Buttons variable opacity are triggered when we click the first time; only the onPress callback is'nt triggered
  • On an animated view with only a variable opacity, no error; it's linked to the translation operation

Code

Code looks like this:

export const AnimatedButton = () => {
  const shiftAmount = useSharedValue(-100);
  const shiftDownStyle = useAnimatedStyle(() => ({
    transform: [{ translateY: shiftAmount.value }],
  }));

  if (shiftAmount.value !== 0) {
    shiftAmount.value = withTiming(0, { duration: 450 });
  }

  return (
    <Animated.View style={shiftDownStyle}>
      <Button
        title="Press me"
        onPress={() => Alert.alert("Im clicked")} // 🚨 not triggered the first time
      />
    </Animated.View>
  );

A full example can be found here: https://github.com/delphinebugner/repro

Further notes

Thanks for working on the lib 🙂

If the problem is linked to a messy Reanimated usage in the component, happy to correct my code!

Steps to reproduce

On the repro application:

  1. Run it on a real device (error does not occur on emulator)
  2. Just after mounting the Home, try to clic on a "Press me" button : nothing happens 🚨
  3. Click on "Explore" Tab
  4. Return to "Home" Tab
  5. Click on a "Press me" button: an alert shows up ✅
  6. Click on the "Toggle animated buttons" to unmount-remount them
  7. Click again a "Press me" button: nothing happens 🚨

Snack or a link to a repository

https://github.com/delphinebugner/repro

Reanimated version

3.16.1

React Native version

0.75.0

Platforms

Android

JavaScript runtime

Hermes

Workflow

Expo Dev Client

Architecture

Fabric (New Architecture)

Build type

Debug app & dev bundle

Device

Real device

Device model

Samsung Galaxy S22

Acknowledgements

Yes

@github-actions github-actions bot added Repro provided A reproduction with a snippet of code, snack or repo is provided Platform: Android This issue is specific to Android Missing info The user didn't precise the problem enough and removed Missing info The user didn't precise the problem enough labels Nov 7, 2024
@hamdij0maa
Copy link

+1

@JoaoMosmann
Copy link

I had a similar problem. To fix it I had to use the Pressable component exported by the react-native-gesture-handler library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided
Projects
None yet
Development

No branches or pull requests

3 participants