Skip to content

Throw error when detectors are not placed inside GestureHandlerRootView#3798

Merged
m-bert merged 3 commits into
nextfrom
@mbert/throw-detector-error
Nov 5, 2025
Merged

Throw error when detectors are not placed inside GestureHandlerRootView#3798
m-bert merged 3 commits into
nextfrom
@mbert/throw-detector-error

Conversation

@m-bert

@m-bert m-bert commented Nov 3, 2025

Copy link
Copy Markdown
Collaborator

Description

For now, NativeDetector doesn't throw error when it is used outside of GestureHandlerRootView. This PR moves check from LegacyDetector to GestureDetector.

Test plan

Tested on the following example:
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { usePan, GestureDetector } from 'react-native-gesture-handler';

export default function EmptyExample() {
  const pan = usePan({});

  return (
    <View style={styles.container}>
      <GestureDetector gesture={pan}>
        <View style={{ width: 300, height: 300, backgroundColor: 'green' }} />
      </GestureDetector>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});

@m-bert m-bert requested a review from j-piasecki November 3, 2025 11:00
@j-piasecki

Copy link
Copy Markdown
Member

Will we be exporting LegacyGestureDetector as a standalone component? If so, the check should stay in both.

@m-bert

m-bert commented Nov 3, 2025

Copy link
Copy Markdown
Collaborator Author

Will we be exporting LegacyGestureDetector as a standalone component? If so, the check should stay in both.

Well, if exporting everything as GestureDetector works fine I don't think we have to export it as a standalone component. WDYT @akwasniewski?

@akwasniewski

Copy link
Copy Markdown
Contributor

Will we be exporting LegacyGestureDetector as a standalone component? If so, the check should stay in both.

Well, if exporting everything as GestureDetector works fine I don't think we have to export it as a standalone component. WDYT @akwasniewski?

The idea of putting all detectors in the new GestureDetector was not to export them seperately. We only want to export this multi-use component, I think it's less effort for the user.

@m-bert m-bert merged commit ad2029d into next Nov 5, 2025
2 checks passed
@m-bert m-bert deleted the @mbert/throw-detector-error branch November 5, 2025 10:05
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