React-Navigation tabBarVisible的

2018-05-10  本文已影响158人  文达IOS

最近在研究React-Native,在使用facebook的框架React-Navigation的时候,隐藏Tabbar遇到了问题。

import React from 'react';
import { View, Text, TouchableOpacity ,YellowBox} from 'react-native';

import {
    createStackNavigator,
    createBottomTabNavigator,
} from 'react-navigation';

const HomeScreen = ({ navigation: { push } }) => (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <TouchableOpacity
            onPress={() => push('HomeDetail', { id: Math.round(Math.random() * 10) })}>
            <Text>Open HomeDetail Screen</Text>
        </TouchableOpacity>
    </View>
);

const HomeDetailScreen = () => (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text style={{ color: 'red', marginBottom: 20, fontWeight: 'bold' }}>
            HomeDetail Screen
        </Text>
    </View>
);

const HomeStack = createStackNavigator({
    Home: { screen: HomeScreen, navigationOptions: { title: 'Home' } },
    HomeDetail: {
        screen: HomeDetailScreen,
        navigationOptions: { title: 'HomeDetail' },
    },
});

HomeStack.navigationOptions = ({ navigation }) => {
    return {
        tabBarVisible: navigation.state.index === 0,
    };
};

const Navigator = createBottomTabNavigator({
    Home: HomeStack,
});

export default () => <Navigator />;

console.ignoredYellowBox = [
    'Warning: componentWillMount',
    'Warning: componentWillReceiveProps',
    'Warning: componentWillUpdate',
];

至于代码的架构就需要大家各自处理了。

参考资料如下:

如果有更好的处理方法,请大家及时告知我谢谢。

上一篇 下一篇

猜你喜欢

热点阅读