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

Add error about functional components being used with old API #3240

Merged
merged 1 commit into from
Nov 28, 2024

Conversation

m-bert
Copy link
Contributor

@m-bert m-bert commented Nov 27, 2024

Description

Old API does not support functional components as it requires assigning ref to handler's child. If someone tries to pass functional component into handler, behavior differs based on platform:

  • Android - app will crash with the following error message:
image
  • Web - app will crash in GestureHandlerDelegate:

    • Cannot read properties of undefined (reading 'isButtonInConfig')
  • iOS - app won't crash, but the handler doesn't work anyway

This PR adds error that will be thrown when handler cannot obtain target view. This will unify behavior across platforms, as well as provide explanation of what went wrong.

Test plan

Tested on the following code:
import React from 'react';
import { View } from 'react-native';
import { TapGestureHandler } from 'react-native-gesture-handler';

const MyView = () => {
  return <View />;
};

export default function RectButtonBorders() {
  return (
    <TapGestureHandler onHandlerStateChange={() => console.log('click')}>
      <MyView />
    </TapGestureHandler>
  );
}

@m-bert m-bert requested review from j-piasecki and latekvo November 27, 2024 12:18
@m-bert m-bert merged commit fe66fe1 into main Nov 28, 2024
1 check passed
@m-bert m-bert deleted the @mbert/old-api-fc branch November 28, 2024 09:18
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