software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.09k stars 978 forks source link

Error in RNGestureHandlerTouchEvent with react-native-gesture-handler ~2.16.1 on Android #3171

Open offcarlospetit opened 1 day ago

offcarlospetit commented 1 day ago

Description

When trying to compile my app using version ~2.16.1 of react-native-gesture-handler, I encounter an error in the init method related to RNGestureHandlerTouchEvent. The error occurs due to an unsafe operation when trying to get the SurfaceId from handler.view. Although I managed to fix the issue by modifying the source code, I believe this should be addressed in the official library.

The build fails with the following error: RNGestureHandlerTouchEvent Type mismatch: inferred type is View! but String was expected

I modified the code in RNGestureHandlerTouchEvent to add null checks in the init method:

private fun <T : GestureHandler<T>> init(handler: T) {
    handler.view?.let { UIManagerHelper.getSurfaceId(it) }
      ?.let { super.init(it, handler.view!!.id) }
    extraData = createEventData(handler)
    coalescingKey = handler.eventCoalescingKey
  }

Steps to reproduce

  1. Create a React Native app with the following setup:
    • React Native: 0.75.4
    • react-native-gesture-handler: ~2.16.1
    • Expo: ^51.0.0
  2. Implement a gesture handler using the RNGestureHandlerTouchEvent function.
  3. Run the project on Android using Android Studio.

Snack or a link to a repository

https://github.com/offcarlospetit/testIssue

Gesture Handler version

2.16.1

React Native version

0.75.4

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

None

Device model

No response

Acknowledgements

Yes

latekvo commented 10 hours ago

Hi @offcarlospetit, thanks for the report! Have you tried using RNGH version 2.20.0? Version 2.16.1 is quite dated and definitely wasn't prepared for React Native version 0.75.4