簡體   English   中英

反應本地調用自定義視圖

[英]react-native calling custom view

我有一個自定義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>
    );
  }
}

我覺得我的代碼是正確的,但是標題沒有顯示。 知道為什么嗎?

您的customHeader函數必須返回某些內容。 現在,它只運行jsx,什么也不返回。 像這樣修復它:

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