简体   繁体   English

反应本地调用自定义视图

[英]react-native calling custom view

I have a custom header view and I have call this inside my class but for some reason it is not showing. 我有一个自定义header视图,并且在类中调用了此视图,但由于某种原因,它没有显示。

export default class App extends Component<Props> {

customHeader(){
       <View style={{height:80, width:'100%', backgroundColor: 'blue'}}>
           <TouchableOpacity>
              <Text>Header</Text>
           </TouchableOpacity>
       </View>
}

  render() {
    return (
      <View style={styles.container}>
//Calling my custom header
        {this.customHeader()}
      </View>
    );
  }
}

I feel like my code is correct but the header is not showing. 我觉得我的代码是正确的,但是标题没有显示。 Any idea why? 知道为什么吗?

Your customHeader function must return something. 您的customHeader函数必须返回某些内容。 Right now it just runs jsx and returns nothing. 现在,它只运行jsx,什么也不返回。 Fix it like this for example: 像这样修复它:

customHeader(){
  return (
    <View style={{height:80, width:'100%', backgroundColor: 'blue'}}>
      <TouchableOpacity>
        <Text>Header</Text>
      </TouchableOpacity>
    </View>
  )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM