当我从我放置它的地方删除我专门创建的组件菜单时,我没有收到错误消息,但是当我的组件在那里时我收到了错误消息。感谢您的评论。
import Menu from './Navigator'
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
import { faBars } from '@fortawesome/free-solid-svg-icons';
export default class HeaderLeft extends Component {
constructor(props){
super(props);
this.state={check:false}
}
render() {
return (<SafeAreaView><View onStartShouldSetResponderCapture={() => { this.setState({ check: !this.state.check }) }} style={styles.align}>
<FontAwesomeIcon icon={faBars} size={16} color={"#2D6A4F"} /><Menu check={this.state.check}></Menu></View></SafeAreaView>)
}
}
const styles = StyleSheet.create({
align: {
height: 60, display: 'flex', justifyContent: 'center', padding: 20
},
});```
答案 0 :(得分:0)
在您的代码中按照以下代码进行更改,尝试一下:
在构造函数中添加以下内容:
this.handleResponderCapture = this.handleResponderCapture.bind(this)
添加以下方法:
handleResponderCapture = () => {
this.setState({
check: !this.state.check
})
}
在视图中进行如下更改
<View
onStartShouldSetResponderCapture={this.handleResponderCapture}
style={styles.align}
>