Skip to content

Conversation

m-bert
Copy link
Contributor

@m-bert m-bert commented Sep 17, 2025

Description

This PR adds logic that filters config object before passing it to native side.

Test plan

Tested on the following code:
import * as React from 'react';
import { Animated, Button } from 'react-native';
import {
  GestureHandlerRootView,
  NativeDetector,
  useTap,
} from 'react-native-gesture-handler';

export default function App() {
  const [visible, setVisible] = React.useState(true);

  const gesture = useTap({
    onEnd: (e) => {
      'worklet';
      console.log('tap', e.handlerData);
    },

    numberOfTaps: 2,
  });

  return (
    <GestureHandlerRootView
      style={{ flex: 1, backgroundColor: 'white', paddingTop: 8 }}>
      <Button
        title="Toggle visibility"
        onPress={() => {
          setVisible(!visible);
        }}
      />

      {visible && (
        <NativeDetector gesture={gesture}>
          <Animated.View
            style={[
              {
                width: 150,
                height: 150,
                backgroundColor: 'blue',
                opacity: 0.5,
                borderWidth: 10,
                borderColor: 'green',
                marginTop: 20,
                marginLeft: 40,
              },
            ]}
          />
        </NativeDetector>
      )}
    </GestureHandlerRootView>
  );
}

@m-bert m-bert requested a review from j-piasecki September 17, 2025 12:33
Comment on lines 104 to 106
if (PropsToFilter.has(key)) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the whitelist would be a better pick here. We could have known passable props (the configs), known unpassable props (what is currently in PropsToFilter), and we could warn about anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean something like

if (whitelist.has(prop)) {
  ...
} else if (PropsToFilter.has(prop)) {
  continue;
} else {
  console.warn(...)
}

?

Copy link
Member

@j-piasecki j-piasecki Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, yes. There should be arrays of all possible values for each handler somewhere already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that we cannot simply take specific gesture properties. Let's say we pick Pan props to be in whitelist, then, for example, mouseButton is not direct Pan property, therefore it will be ignored.

On the other hand I can see why this may be useful, so we could make list of common props, then merge them with handlers' properties 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one 4ff105a seems to do the job. Let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually not really, I forgot that this is function which prepares config to be passed into native side. In that case some of the props are wrongly white-listed, as Pan doesn't accept for example activeOffsetX, but rather activeOffsetXStart and activeOffsetXEnd etc.

In that case I think we will have to make those lists, since they don't exist in old types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that this is function which prepares config to be passed into native side.

Okay, I've fixed that... though to get rid of circular dependencies I had to split types and hooks, so it grew quite large 🙈

Let me know what you think about this whitelist approach, and if you have any thoughts/ideas how to make it look better than it is now. Also, I'm not sure about how it will work with #3731 🙈

cc @akwasniewski

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see it won't conflict with #3731. But we'll have to test to make sure.

Base automatically changed from @mbert/add-event-calculators to next October 3, 2025 14:54
@m-bert m-bert requested a review from j-piasecki October 3, 2025 17:31
[SingleGestureName.Fling, withCommonProps(flingGestureHandlerProps)],
]);

const EMPTY_WHILE_LIST = new Set<string>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar thing will be added in #3689, so we will have to find good place to keep it 😅

@m-bert m-bert marked this pull request as draft October 6, 2025 12:18
@m-bert m-bert marked this pull request as ready for review October 6, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants