【发布时间】:2017-01-04 17:54:02
【问题描述】:
我正在尝试创建一个类似于 TouchableHighlight 的组件,但我不想突出显示背景,而是要突出显示文本。我需要挂钩在用户实际按下时触发的 onPress 事件。
我尝试过使用 TouchableWithoutFeedback 和 onPressIn,但它似乎没有触发。这是我一直在测试的代码。
class TouchableTextHighlight extends React.Component {
constructor (props) {
super(props)
this.state = {
isHighlighted: false
}
}
highlight () {
console.log('pressed')
this.setState({
isHighlighted: true
})
}
render () {
let textColor = this.state.isHighlighted ? '#F44336' : null
return (
<TouchableWithoutFeedback {...this.props} onPressIn={() => {this.highlight}} onPress={this.props.onPress}>
<View {...this.props}>
<Text
style={[this.props.textStyle, {color: textColor}]}
>{this.props.text}</Text>
</View>
</TouchableWithoutFeedback>
)
}
}
【问题讨论】:
标签: react-native