简体   繁体   English

没有 onLongPress 用于反应导航 HeaderBackButton

[英]No onLongPress for react-navigation HeaderBackButton

I am trying to add onLongPress functionality on a custom header back button, but this doesn't seem like an existing prop.我正在尝试在自定义标题后退按钮上添加 onLongPress 功能,但这似乎不是现有的道具。 Is there a way around it?有办法解决吗?

I want this functionality as my app is for people with Parkinson's disease, so for users with a tremor, I have an option to only allow onLongPress (so successive keypresses will be ignored and misfires can be avoided).我想要这个功能,因为我的应用程序是为患有帕金森氏症的人设计的,所以对于有震颤的用户,我可以选择只允许 onLongPress(这样连续的按键将被忽略并且可以避免失火)。 So, if the long press option has been enabled, the onPress functionality will be ignored, and only onLongPress will work.因此,如果启用了长按选项,则 onPress 功能将被忽略,并且只有 onLongPress 会起作用。 If the option has not been enabled, both onPress and onLongPress should work.如果该选项尚未启用,则 onPress 和 onLongPress 都应该起作用。

I've made other custom buttons for the header, but I want the back button to maintain the navigation stack, so it goes back to the page the user came from.我为标题制作了其他自定义按钮,但我希​​望后退按钮维护导航堆栈,因此它返回到用户来自的页面。 Is there a way to add a standard touchable opacity, with the same onPress functionality as the HeaderBackButton, so I can add the onLongPress functionality.有没有办法添加标准的可触摸不透明度,具有与 HeaderBackButton 相同的 onPress 功能,因此我可以添加 onLongPress 功能。

You can add headerLeft prop in your navigation configuration, which given a function is passed to it, provides arguments, such as (onPress, label, ...) .您可以在导航配置中添加headerLeft道具,该道具给定一个函数传递给它,提供参数,例如(onPress, label, ...) You can call that onPress in your custom component's onLongPress function to maintain the same functionality.您可以在自定义组件的onLongPress函数中调用该onPress以保持相同的功能。

Here's an example code:这是一个示例代码:

navigationOptions: {
  headerLeft: (onPress) => {
    return <TouchableOpacity ... onLongPress={onPress}>...</TouchableOpacity>
  }
}

You can read more about this here .您可以在此处阅读更多相关信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM