[英]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.