2017-07-11 84 views
2

如何添加我自己的標題組件,以便我可以在nav中添加圖像?react-navigation添加自定義標題

我設置我的標題這樣,我可以設置組件的權利和左,但如何添加一個居中的圖像到我的導航?

const headerStyle = { 
    paddingHorizontal: theme.metrics.mainPadding, 
    paddingTop: 2, 
    paddingBottom: 2, 
    backgroundColor: theme.colors.purple, 
    justifyContent: 'center', 
}; 

const headerTitleStyle = { 
    textAlign: 'center', 
    alignSelf: 'stretch', 
    alignItems: 'center', 
    ...theme.fontStyles.appBarTitle, 
}; 

const headerRight = <Text>logo here</Text>; 
const headerLeft = <Text>text here</Text>; 

export default { 
    title, 
    headerStyle, 
    headerTitleStyle, 
    headerRight, 
    headerLeft, 
}; 

回答

0

您必須在每個組件中設置標題可見性以隱藏標題。

static navigationOptions = { 
header: { 
    visible: false, 
} 
}; 

REACT航海改變了API用於從v1.0.0-beta.9隱藏首部。改爲使用header: null

static navigationOptions = { 
header: null 
}; 
+0

謝謝,我如何添加一個頭,一旦我已經隱藏的默認嗎? – Bomber

+0

使用'native-base',您可以在'

...
'元素之間添加您的代碼。 –