mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-25 01:28:16 +00:00
* add withNavigationFocus HOC See: - https://github.com/react-navigation/react-navigation/issues/51#issuecomment-276003658 - https://github.com/react-navigation/react-navigation/issues/51#issuecomment-278761705 - https://github.com/react-navigation/react-navigation/pull/3345#issuecomment-360260067 * typos * remove unused import * Add withNavigationFocus export * add example TabsWithNavigationFocus * add example TabsWithNavigationFocus * withNavigationFocus: get navigation from context or props * subs => subscriptions * fix flow issues
49 lines
1020 B
JavaScript
49 lines
1020 B
JavaScript
/**
|
|
* @flow
|
|
*/
|
|
|
|
import React from 'react';
|
|
import { SafeAreaView } from 'react-native';
|
|
import { TabNavigator, withNavigationFocus } from 'react-navigation';
|
|
|
|
import SampleText from './SampleText';
|
|
|
|
const createTabScreen = name => {
|
|
const TabScreen = ({ isFocused }) => (
|
|
<SafeAreaView
|
|
forceInset={{ horizontal: 'always', top: 'always' }}
|
|
style={{
|
|
flex: 1,
|
|
alignItems: 'center',
|
|
justifyContent: 'center',
|
|
}}
|
|
>
|
|
<SampleText>{'Tab=' + name}</SampleText>
|
|
<SampleText>{'IsFocused=' + isFocused ? 'true' : 'false'}</SampleText>
|
|
</SafeAreaView>
|
|
);
|
|
|
|
return withNavigationFocus(TabScreen);
|
|
};
|
|
|
|
const TabsWithNavigationFocus = TabNavigator(
|
|
{
|
|
One: {
|
|
screen: createTabScreen('One'),
|
|
},
|
|
Two: {
|
|
screen: createTabScreen('Two'),
|
|
},
|
|
Three: {
|
|
screen: createTabScreen('Three'),
|
|
},
|
|
},
|
|
{
|
|
tabBarPosition: 'bottom',
|
|
animationEnabled: true,
|
|
swipeEnabled: true,
|
|
}
|
|
);
|
|
|
|
export default TabsWithNavigationFocus;
|