【问题标题】:Icon Function Not being Ran On Press图标功能未在按下时运行
【发布时间】:2018-01-05 17:41:29
【问题描述】:

我正在为我的 React-Native 应用程序使用 React-Native-Router-Flux 来处理我的路线。在我的路线中,我在 MoreIcon 上有一个函数调用,它应该在 onPress 上运行,但除非我删除 Lambda 运算符,否则什么都不会执行,但它会在组件挂载时立即执行它。

我尝试返回而不返回从 onPress 调用的警报函数,但仍然没有运气。

    {/* Live Feed Tab View */}
    <routes.Scene key = "Live" title = "Live" icon={Icons.LiveIcon}>
      <routes.Scene key="LiveFeed" component={LiveFeed} renderRightButton = {() => { return <MoreIcon onPress = { () => {return alert() } }   />; }} renderTitle={() => { return <AppLogo />; }} />
      <routes.Scene  key="Profile" component={Profile} title="Profile" renderRightButton = {() => { return <MoreIcon  />; }} /> 
      <routes.Scene key="Reply" component={Reply} title="Replies" />
      <routes.Scene key="Camera" component={Camera} title="Camera" />
      <routes.Scene key="Preview" component={Preview} title="Preview" />
      <routes.Scene key="MakePost" component={MakePost} title="MakePost" />
    </routes.Scene>

【问题讨论】:

  • 你能提供MoreIcon的代码吗?

标签: javascript reactjs react-native react-native-router-flux


【解决方案1】:

确保 onPress 的 Inside More Icon 是传递给可以处理 TouchableOpacity 等触摸的元素。检查官方文档中的 onPress 函数是如何从环绕图像的 TouchableOpacity 组件触发的。 https://facebook.github.io/react-native/docs/touchableopacity.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-03
    • 1970-01-01
    • 2019-08-17
    • 2015-12-01
    • 2016-07-23
    相关资源
    最近更新 更多