简体   繁体   English

将Multilpe组件导入index.ios.js

[英]Importing multilpe components to index.ios.js

I'm trying to import my navigation (with routing) and my main.js to index.ios.js as such: 我正在尝试将我的导航(通过路由)和main.jsindex.ios.js ,如下所示:

import PRSNT_demo from './src/main.js'
import NavAllDay from './src/components/navigation.js';

This just renders the last named Component (so only shows my navigation), I couldn't find anything on the subject and I've tried importing the nav into my main.js . 这只是呈现了最后一个命名的Component(因此仅显示了我的导航),我在主题上找不到任何内容,并且尝试将nav导入到main.js Does anyone have documentation on where to find the solution or does anyone know the solution? 有没有人在哪里找到解决方案的文档?是否有人知道解决方案?

Navigation.js (I know this won't really do anything yet I just want it to show both views): Navigation.js (我知道这实际上不会做任何事情,我只希望它显示两个视图):

 import React, { Component } from 'react';
import { AppRegistry, Text, Navigator, TouchableHighlight } from 'react-native';
import Style from '../Style';

console.log('doing this');

export default class NavAllDay extends Component {
    render() {
        const routes = [
            {title: 'First Scene', index: 0},
            {title: 'Second Scene', index: 1},
        ];
        return (
            <Navigator
                style={Style.header}
                initialRoute={routes[0]}
                renderScene={(route, navigator) =>
                    <TouchableHighlight onPress={() => {
                        if (route.index === 0) {
                            navigator.push(routes[1]);
                        } else {
                            navigator.pop();
                        }
                    }}>
                    <Text>Hello {route.title}!</Text>
                    </TouchableHighlight>
                }
                navigationBar={
                    <Navigator.NavigationBar
                        routeMapper={{
                            LeftButton: (route, navigator, index, navState) =>
                                {
                                    if (route.index === 0) {
                                        return null;
                                    } else {
                                        return (
                                            <TouchableHighlight onPress={() => navigator.pop()}>
                                                <Text>Back</Text>
                                            </TouchableHighlight>
                                        );
                                    }
                                },
                            RightButton: (route, navigator, index, navState) =>
                                {
                                    if (route.index === 1) {
                                        return null;
                                    } else {
                                        return (
                                            <TouchableHighlight onPress={() => navigator.push(routes[1])}>

                                                <Text>Done</Text>

                                            </TouchableHighlight>
                                        );
                                    }
                                },
                            Title: (route, navigator, index, navState) =>
                                { return (<Text>Awesome Nav Bar</Text>); },
                        }}
                        style={Style.header}
                        />
                }
            />
        );
    }
}

AppRegistry.registerComponent('PRSNT_demo', () => NavAllDay)

Main.js: Main.js:

import React, { Component } from 'react';
import Style from './Style';

import {
  AppRegistry,
  Text,
  View
} from 'react-native';

export default class PRSNT_demo extends Component {
  render() {
    return (
      <View style={Style.container}>

        <View style={Style.invites}>
          <Text style={Style.presentListText}> Section</Text>
        </View>
        <View style={Style.presentList}>
          <Text style={Style.presentListText}>
            List
          </Text>
        </View>
      </View>
    );
  }
}

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

AppRegistry.registerComponent('PRSNT_demo', () => PRSNT_demo); this line should only exist in you index.ios.js and index.android.js file. 该行仅应存在于index.ios.js和index.android.js文件中。

Also, to import files you just place these at the top of the file you want to use them: 另外,要导入文件,只需将它们放在要使用它们的文件的顶部:

import PRSNT_demo from './src/main.js'

import NavAllDay from './src/components/navigation.js'

if you wanted to use them in your index.ios.js file you need to do something like this: 如果要在index.ios.js文件中使用它们,则需要执行以下操作:

    import React, { Component } from 'react';
    import {
        AppRegistry,
        View
    } from 'react-native';

    import PRSNT_demo from './src/main.js'
    import NavAllDay from './src/components/navigation.js'

    export default class Main extends Component {
        render() {
            return (
                <View>
                   <PRSNT_demo />
                   <NavAllDay />
                </View>
            )
        }
    }

    AppRegistry.registerComponent('PRSNT_demo', () => Main);

The AppRegistry is saying which component you want initially rendered. AppRegistry表示要最初呈现的组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM