javascript - Detect click on header icons - Stack Overflow

I am very new with react native. I am using a header from react-native-elements in my app. This is my c

I am very new with react native. I am using a header from react-native-elements in my app. This is my code

<Header
  leftComponent={{ icon: 'menu', color: '#fff' }}
  centerComponent={{ text: 'MY TITLE', style: { color: '#fff' } }} 
  rightComponent={{ icon: 'home', color: '#fff' }}
/>

I was not able to found any example on how to detect the clicks on the icons and if possible show an extra view. My goal is to achieve something like this : Do you have any example or sample code?

I am very new with react native. I am using a header from react-native-elements in my app. This is my code

<Header
  leftComponent={{ icon: 'menu', color: '#fff' }}
  centerComponent={{ text: 'MY TITLE', style: { color: '#fff' } }} 
  rightComponent={{ icon: 'home', color: '#fff' }}
/>

I was not able to found any example on how to detect the clicks on the icons and if possible show an extra view. My goal is to achieve something like this : Do you have any example or sample code?

Share Improve this question asked Oct 13, 2017 at 8:44 j.doej.doe 4,8896 gold badges24 silver badges31 bronze badges 2
  • In the link you passed, it seems you can pass react ponent (leftComponent={<MyCustomLeftComponent />}), so you can handle the click on the ponent you will pass, can't you? – sjahan Commented Oct 13, 2017 at 8:47
  • I guess you can pass onClick to the ponent. Something like this, leftComponent={{ icon: 'menu', color: '#fff', onClick={//your function} }} – Arslan Tariq Commented Oct 13, 2017 at 8:51
Add a ment  | 

2 Answers 2

Reset to default 8

Write : insted of = , onPress will work

  <Header 
     leftComponent={ {text:'ok',color: '#fff', onPress: () => this.myFunction()}}
     centerComponent={{ text: 'MY TITLE', style: { color: '#fff' } }}
  />

or you can pass your own ponent like

 leftComponent={<MyCustomLeftComponent />}

You have to use onPress instead of onClick.

 <Header
    leftComponent={{ icon: 'menu', color: '#fff' }}
    centerComponent={{ text: 'MY TITLE', style: { color: '#fff' } }} 
    rightComponent={{ icon: 'home', color: '#fff' onPress={() => this.yourFunction} }}
 />

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744928555a4601592.html

相关推荐

  • javascript - Detect click on header icons - Stack Overflow

    I am very new with react native. I am using a header from react-native-elements in my app. This is my c

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信