【问题标题】:react-native: TouchableOpacity'a onPress() doesn't get called in modals on slower Android devicesreact-native: TouchableOpacity\'a onPress() doesn\'t get called in modals on slower Android devices
【发布时间】:2022-12-26 21:00:34
【问题描述】:

On older and slower Android devices, the onPress() method on TouchableOpacity might not be called even though the button is pressed and you can see the opacity effect on the view.

What's weird is that it's statistical, on a Samsung Galaxy A8 around 20% of the time the press did work, on my Pixel 6 Pro the press works 100% of the time.

onPressIn() is always called but onPress() is uncertain.

【问题讨论】:

    标签: android react-native touchableopacity


    【解决方案1】:

    tl;dr Don't use react-native-modals, it's buggy, find an alternative (I use react-native-modal instead)

    I spent a while trying to figure out why onPressIn() was called successfully while onPress() wasn't, I read the logic in react-native's code, which uses the Gesture Responder System on determining whether a callback should be called.

    When the press works, those are the signals I see from the touch events system:

    RESPONDER_GRANT // (touch detected on View, causes onPressIn() to be called)
    
    DELAY // (can determine whether we want onPress() or onPressLong())
    
    RESPONDER_RELEASE // (finger lifted, depending on DELAY now onPress() / onPressOut() are called)
    

    and when the press doesn't work:

    RESPONDER_RELEASE
    
    RESPONDER_TERMINATED // (nothing happens)
    

    RESPONDER_TERMINATED means that someone else took control of the gesture responder system, why does it happen? I'm not sure, I couldn't figure out why react-native-modals caused it to happen but eventually I tried using react-native-modal instead and it acted correctly, nothing hijacked my presses!

    【讨论】:

      猜你喜欢
      • 2022-08-22
      • 1970-01-01
      • 2018-08-20
      • 2019-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      • 2021-05-08
      相关资源
      最近更新 更多