[v 1.6.0] Unsupported top level event type “onGestureHandlerStateChange” dispatched

On some phones, we encounter this error.
Current versions:
react-native-gesture-handler: 1.6.0
Expo client: 2.15.4
RN: sdk 37

There is a closed issue with the problem. People are recommending to
import 'react-native-gesture-handler' in App.js
Unfortunately, it does not help.

There are some related closed issues where people still report this error
#320
#439

1 possible answer(s) on “[v 1.6.0] Unsupported top level event type “onGestureHandlerStateChange” dispatched

  1. This works for me
    #320 (comment)

    just a bit refactored:

    import { NativeModules } from 'react-native'
    
    const { UIManager } = NativeModules
    
    if (UIManager) {
      UIManager.genericDirectEventTypes = {
        ...UIManager.genericDirectEventTypes,
        onGestureHandlerEvent: { registrationName: 'onGestureHandlerEvent' },
        onGestureHandlerStateChange: {
          registrationName: 'onGestureHandlerStateChange',
        },
      }
    }
    ...
    import React, { Component } from 'react'