How to use Themeprovider in react-navigation
See original GitHub issueIn my case, i want to manage header backgroundColor with ThemeProvider , how to use them in navigationOptions
, example code below :
/**
* @flow
*/
import React from 'react'
import { Text, View, StatusBar } from 'react-native'
import styled, { withTheme } from 'styled-components/native'
import Ionicons from 'react-native-vector-icons/Ionicons'
let HeaderTitle = styled.TouchableOpacity`
width:100%;
height: 30;
align-self: center;
`
let SearchBar = styled.View`
height: 30;
border-radius:30;
background: #fff;
flex-direction:row;
align-items:center;
justify-content:center;
`
let SearchBarText = styled.Text`
`
let HeaderLeft = styled.TouchableOpacity`
padding-horizontal: 20;
`
let HeaderRight = styled.TouchableOpacity`
padding-horizontal: 20;
`
class HomeScreen extends React.Component {
static navigationOptions =({navigation, screenProps}) => ({
headerStyle: {
backgroundColor: '#E5466E'
},
headerTitle: (
<HeaderTitle>
<SearchBar>
<Ionicons
name={'ios-search'}
size={16}
style={{
paddingRight: 10,
color: '#999'
}}
/>
<SearchBarText>search</SearchBarText>
</SearchBar>
</HeaderTitle>
),
headerRight: (
<HeaderRight>
<Ionicons
name={'ios-mail-outline'}
size={24}
style={{
color: '#fff'
}}
/>
</HeaderRight>
),
headerLeft: (
<HeaderLeft>
<Ionicons
name={'md-aperture'}
size={21}
style={{
color: '#fff'
}}
/>
</HeaderLeft>
)
})
render () {
console.log('render', this.props)
return (
<View>
<StatusBar
barStyle='light-content'
/>
<Text>首页</Text>
</View>
)
}
}
export default withTheme(HomeScreen)
in navigationOptions
i want use theme like this
headerStyle: {
backgroundColor: theme.primaryColor
},
instead of
headerStyle: {
backgroundColor: '#E5466E'
},
I need some help 🆘
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Themes - React Navigation
Themes allow you to change the colors of various components provided by React Navigation. You can use themes to: Customize the colors match...
Read more >Theming with React Navigation · React Native Paper
In this guide we will look into how to apply theming for an application using React Native Paper and React Navigation at the...
Read more >react-native-navigation theming with styled-components
import { Provider } from 'react-redux'; import { ThemeProvider } from 'styled-components'; import theme from './theme'; const Provider = ({ ...
Read more >Simple React Native Theme Provider | by Ike Njoku - Medium
js (shown above containing all themes we want to make available), color palettes are created that will set the theme of the application...
Read more >Theming React Native Applications with Styled Components
Detailed tutorial on adding theming to your React Native applications ... To run the application, navigate to the project directory in a ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ahh sorry I know see that you already applied withTheme. I have never used react-navigation but it seems that there is an extra screenProps which you can use to apply some additional props. As far as I know you have to apply them when you render
HomeScreen
.There might be a better solution for it but this is the only one I am aware of.
updated to v3: