React-native-reanimated: How to control pointerEvents props with a sharedValue ?

Created on 1 Aug 2020  路  4Comments  路  Source: software-mansion/react-native-reanimated

Description

I'd like to control the pointerEvents value of an Animated.View, so I was thinking doing something like :

Code


  const translateY = useSharedValue(0);

  ...

  const animatedProps = useAnimatedProps(() => {
    const pointerEvents = translateY.value === 1 ? undefined : 'box-none';

    return {
      pointerEvents,
    };
  });

  return (
    <Animated.View {...animatedProps} style={styles.container}>
      // CONTENT
    </Animated.View>
  );

Except it doesn't work the way I expected it to work. Someone knows how to solve this ?
Thanks.

Package versions

  • React: latest
  • React Native: 0.63.2
  • React Native Reanimated: alphaV4

ANSWER :
I found this issue right after :
https://github.com/software-mansion/react-native-reanimated/issues/895

Got it to work like that :


  const translateY = useSharedValue(0);

  ...

  const animatedProps = useAnimatedProps(() => {
    const pointerEvents = translateY.value === 1 ? 'auto' : 'box-none';

    return {
      pointerEvents,
    };
  });

  return (
    <Animated.View {...{ animatedProps }} style={styles.container}>
      // CONTENT
    </Animated.View>
  );
鉂換uestion 馃彔 Reanimated2

Most helpful comment

By the way you can use both booleans and strings as shared values :)

All 4 comments

Hi, could u please let us know how you resolved this ?

At the end of my first message

@Daavidaviid thank you

By the way you can use both booleans and strings as shared values :)

Was this page helpful?
0 / 5 - 0 ratings