diff --git a/packages/react-navigation/examples/NavigationPlayground/js/App.js b/packages/react-navigation/examples/NavigationPlayground/js/App.js index bf27dd5c..4769706b 100644 --- a/packages/react-navigation/examples/NavigationPlayground/js/App.js +++ b/packages/react-navigation/examples/NavigationPlayground/js/App.js @@ -109,10 +109,10 @@ const ExampleInfo = { name: 'Animated Tabs Example', description: 'Tab transitions have custom animations', }, - // TabsWithNavigationFocus: { - // name: 'withNavigationFocus', - // description: 'Receive the focus prop to know when a screen is focused', - // }, + TabsWithNavigationFocus: { + name: 'withNavigationFocus', + description: 'Receive the focus prop to know when a screen is focused', + }, }; const ExampleRoutes = { @@ -139,8 +139,8 @@ const ExampleRoutes = { screen: SimpleTabs, path: 'settings', }, - TabAnimations: TabAnimations, - // TabsWithNavigationFocus: TabsWithNavigationFocus, + TabAnimations, + TabsWithNavigationFocus, }; type State = { diff --git a/packages/react-navigation/examples/NavigationPlayground/js/TabsWithNavigationFocus.js b/packages/react-navigation/examples/NavigationPlayground/js/TabsWithNavigationFocus.js index a2f0df26..f957e2dd 100644 --- a/packages/react-navigation/examples/NavigationPlayground/js/TabsWithNavigationFocus.js +++ b/packages/react-navigation/examples/NavigationPlayground/js/TabsWithNavigationFocus.js @@ -3,40 +3,75 @@ */ import React from 'react'; -import { SafeAreaView, Text } from 'react-native'; +import { Button, SafeAreaView, Text } from 'react-native'; import { TabNavigator, withNavigationFocus } from 'react-navigation'; import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons'; import SampleText from './SampleText'; -const createTabScreen = (name, icon, focusedIcon, tintColor = '#673ab7') => { - const TabScreen = ({ isFocused }) => ( - - - {'Tab ' + name.toLowerCase()} +class Child extends React.Component { + render() { + return ( + + {this.props.isFocused + ? 'I know that my parent is focused!' + : 'My parent is not focused! :O'} - {'props.isFocused: ' + (isFocused ? ' true' : 'false')} - - ); + ); + } +} - TabScreen.navigationOptions = { - tabBarLabel: name, - tabBarIcon: ({ tintColor, focused }) => ( - - ), - }; +const ChildWithNavigationFocus = withNavigationFocus(Child); +const createTabScreen = (name, icon, focusedIcon, tintColor = '#673ab7') => { + class TabScreen extends React.Component { + static navigationOptions = { + tabBarLabel: name, + tabBarIcon: ({ tintColor, focused }) => ( + + ), + }; + + state = { showChild: false }; + + render() { + const { isFocused } = this.props; + + return ( + + + {'Tab ' + name.toLowerCase()} + + + {'props.isFocused: ' + (isFocused ? ' true' : 'false')} + + {this.state.showChild ? ( + + ) : ( +