内置自定义组件的TouchableWithoutFeedback不会触发onPress回调 [英] TouchableWithoutFeedback with custom component inside doesn't fires onPress callback
问题描述
我做了 DEMO
I made a DEMO
所以问题是第三个按钮不起作用。按钮之间的唯一区别是我在Header组件中传递它们的方式。
so the problem is that third button isn't working. The only difference between buttons is the way I passed them in Header component.
<Header secondButton={<View style={styles.button}><Text>Second Button</Text></View>}
thirdButton={<ThirdButton />}
onPress={this._handlePress} />
推荐答案
@brentvatne回答 github
answered by @brentvatne on github
我能够在这个例子中修复它 - 请注意我更改了
ThirdButton
中的
< View>
,以包含{.. .this.props}
I was able to fix it in this example - notice that I changed the
<View>
in yourThirdButton
to include{...this.props}
<View style={styles.button} {...this.props}>
.. etc
</View>
原因是 TouchableWithoutFeedback
将在该组件上设置responder
props,但是 ThirdButton
只是一个复合组件
,没有支持 UIView
,所以我想把它们传递给 View
。
看看我在这里谈论的是什么
The reason for this is that TouchableWithoutFeedback
will set responder
props on that component, but ThirdButton
is just a composite component
with no backing UIView
, so I want to pass those on to the View
.
See what I'm talking about here
这篇关于内置自定义组件的TouchableWithoutFeedback不会触发onPress回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!