Skip to content

Commit e703272

Browse files
committed
[V4] fix themes related examples
1 parent cf2be78 commit e703272

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

website/versioned_docs/version-4.x/themes.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class MyButton extends React.Component {
112112
static contextType = ThemeContext;
113113

114114
render() {
115+
const theme = this.context;
115116
return (
116117
<TouchableOpacity
117118
style={{ backgroundColor: theme === 'light' ? '#000' : '#fff' }}
@@ -341,7 +342,11 @@ Okay, that's a lot of code. There isn't much going on here aside from passing th
341342
A regrettable limitation of the current implementation of `navigationOptions` is that we are unable to access React context for use in properties such as `headerStyle` and `headerTintColor`. We can and should use them in properties that access React components, for example in `headerRight` we could provide a component like `ThemedHeaderButton`. To apply the theme to other properties we need to use `screenProps`.
342343

343344
```jsx
344-
import { createAppContainer, createStackNavigator } from 'react-navigation';
345+
import {
346+
createAppContainer,
347+
createStackNavigator,
348+
ThemeContext
349+
} from 'react-navigation';
345350

346351
class HomeScreen extends React.Component {
347352
static navigationOptions = ({ screenProps }) => {
@@ -409,6 +414,7 @@ import {
409414
createStackNavigator,
410415
createBottomTabNavigator,
411416
BottomTabBar,
417+
ThemeContext
412418
} from 'react-navigation';
413419

414420
const ThemeConstants = {

0 commit comments

Comments
 (0)