React native - 多条路线的React Navigation

时间:2017-10-04 12:37:55

标签: javascript android ios react-native

我想知道是否有任何方法可以使用反应导航在TabNavigator中创建StackNavigator,现在我在 Router.js 中有类似的TabNavigator。我希望在 Add.js (添加屏幕)中的应用程序在ListItem中创建StackNavigator。 ListItem的每个元素都应该将用户带到其他屏幕。所以,如果我按第一个选项,它应该让我去" AddCalendarEvent"等你在 addList 常量

上的 Add.js 文件中看到的

Router.js

import React from 'react';
    import {
        AppRegistry,
        Text,
        View,
        Button
    } from 'react-native';
    import {StackNavigator, TabNavigator} from 'react-navigation';

    import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome';
    import EntypoIcon from 'react-native-vector-icons/Entypo';

    import Login from './Login';
    import Menu from './Menu';
    import Desktop from './Desktop';
    import Notifications from './Notifications';
    import Today from './Today';
    import Add from './Add';

    const onClickNavigation = StackNavigator({
        Login: {screen: Login}
    });

    const estimobileapplication = TabNavigator({
        Add: {
            screen: Add, navigationOptions: {
                title: 'Dodaj',
                label: 'Dodaj',
                tabBarIcon: ({tintColor}) => (<FontAwesomeIcon name="plus-circle" size={24} color="#666"/>)
            }
        },
        Desktop: {
            screen: Desktop, navigationOptions: {
                title: 'Pulpit',
                label: 'Pulpit',
                tabBarIcon: ({tintColor}) => (<FontAwesomeIcon name="th-large" size={24} color="#666"/>)
            }
        },
        Notifications: {
            screen: Notifications, navigationOptions: {
                title: 'Powiadomienia',
                label: 'Powiadomienia',
                tabBarIcon: ({tintColor}) => (<FontAwesomeIcon name="envelope" size={24} color="#666"/>)
            }
        },
        Today: {
            screen: Today, navigationOptions: {
                title: 'Na dziś',
                label: 'Na dziś',
                tabBarIcon: ({tintColor}) => (<FontAwesomeIcon name="check-square" size={24} color="#666"/>)
            }
        },
        Menu: {
            screen: Menu, navigationOptions: {
                title: 'Menu',
                label: 'Menu',
                tabBarIcon: ({tintColor}) => (<EntypoIcon name="menu" size={24} color="#666"/>),
            }
        }
    }, {
        tabBarOptions: {
            activeTintColor: '#26b7ff',
            inactiveTintColor: '#ffffff',
            activeBackgroundColor: '#2E3035',
            style: {
                backgroundColor: '#14191f',
            }
        }
    });


    AppRegistry.registerComponent('estimobileapplication', () => estimobileapplication);

Add.js

import React, {Component} from 'react';
import {
    ScrollView,
    Text,
    View,
    NavigatorIOS
} from 'react-native';

import {List, ListItem} from 'react-native-elements';

import AddCalendarEvent from './add_offer_components/AddCalendarEvent';
import AddOfferFull from './add_offer_components/AddOfferFull';
import AddOfferQuick from './add_offer_components/AddOfferQuick';
import AddQuestion from './add_offer_components/AddQuestion';
import AddUser from './add_offer_components/AddUser';
import GetInvoice from './add_offer_components/GetInvoice';
import SellBuyTransaction from './add_offer_components/SellBuyTransaction';
import SendEmailToClient from './add_offer_components/SendEmailToClient';
import SendNotification from './add_offer_components/SendNotification';

import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome';

class Add extends Component {

    onShowMore() {
        this.props.navigation.navigate('AddCalendarEvent');
    };

    render() {

        const addList = [
            {
                title: 'Nowa oferta lub zlecenie - szybkie dodanie',
                component: AddOfferQuick
            },
            {
                title: 'Nowa oferta lub zlecenie - pełne dodanie',
                component: AddOfferFull
            },
            {
                title: 'Nowe zapytanie',
                component: AddQuestion
            },
            {
                title: 'Nowy termin w kalendarzu',
                component: AddCalendarEvent
            },
            {
                title: 'Wyślij e-mail do klienta',
                component: SendEmailToClient
            },
            {
                title: 'Transakcja kupna/najmu',
                component: SellBuyTransaction
            },
            {
                title: 'Wystaw fakturę',
                component: GetInvoice
            },
            {
                title: 'Wyślij powiadomienie',
                component: SendNotification
            },
            {
                title: 'Dodaj użytkownika',
                component: AddUser
            }
        ];

        return (
            <ScrollView style={{marginTop: 50, paddingLeft: 20}}>
                <View style={{flexDirection: 'row', flexWrap: 'wrap'}}>
                    <FontAwesomeIcon name="plus-circle" size={30} color="#26b7ff"/>
                    <Text style={{textAlign: 'left', fontSize: 30, color: '#444444', marginLeft: 10}}>
                        Dodaj
                    </Text>
                </View>
                <List>
                    {addList.map((item, i) => (
                        <ListItem
                            key={i}
                            title={item.title}
                            onPress={() => this.onShowMore()}
                        />

                    ))}
                </List>
            </ScrollView>
        );
    }
}


export default Add;

1 个答案:

答案 0 :(得分:1)

根据反应导航文档,您可以根据需要嵌套尽可能多的导航器。只需在“屏幕”中为选项卡定义组件,就可以定义StackNavigator。这样,它将显示StakNavigator显示的第一个组件。

然后在每个项目中,您将导航()定义到您需要的下一个屏幕(我假设列表中的每个项目都是相同的屏幕)并将所需数据作为道具传递。