React-Native Navigator:无法读取未定义的属性“ push”

瑜伽

因此,我在玩React Native,在成功使用第一个导航器后,我制作了另一个导航器以路由到另一个页面。

这是我的文件结构:

项目
-机器人/
-备份/
- IOS /
- node_modules /
- SRC /
- buy.js
- chat.js
- main.js
- nargo.ios.js
- styles.js
- index.android.js /
-index.ios.js /-intro.js
/-main.js
/-package.json
/


这是我的-index.ios.js

import React, { Component } from 'react';
import {
  AppRegistry,
} from 'react-native';
import AppIntro from 'react-native-app-intro';
import Main from './main';


class Project extends Component {

    render() {
      return (
        <Main />
      );
    }
}

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


这是我的-main.js(此代码是到intro.js的成功路由,作为initialRoute):

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

import mainApp from './src/main';
import intro from './intro';
import buy from './src/buy';

const routes = {
  intro,
  mainApp,
  buy
}

module.exports = React.createClass({
  render(){
    return (
      <Navigator
      initialRoute={{name: 'intro'}}
      renderScene={this.renderScene}
      />
    )
  },

  renderScene(route, navigator){
    let Component = routes[route.name];

    return(
      <Component
        navigator={navigator}
      />
    )
  }
});



这是我的-intro.js(在此代码中,当单击“完成”按钮时,我再次成功路由到另一个页面(--main.js)):

import React, { Component } from 'react';
import {
  View,
  Text,
  TextInput,
  TouchableOpacity,
  StyleSheet,
  Image
} from 'react-native';
import AppIntro from 'react-native-app-intro';
import styles from './styles';

const styless = StyleSheet.create({
  slide: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#9DD6EB',
    padding: 15,
  },
  text: {
    color: '#fff',
    fontSize: 30,
    fontWeight: 'bold',
  }, 
  Desc1: {
    paddingTop: 20,
    color: '#fff',
    fontSize: 13,
    fontWeight: '500',
    textAlign: 'center',
    fontFamily: "Raleway-Bold",
  }, 
});


class intro extends Component {
  doneBtnHandle = () => {
    this.props.navigator.push({name: 'mainApp'})
  } 
  onSlideChangeHandle = (index, total) => {
    console.log(index, total);
  }
  render() {
    return (
      <AppIntro
        onNextBtnClick={this.nextBtnHandle}
        onDoneBtnClick={this.doneBtnHandle} 
        onSlideChange={this.onSlideChangeHandle}
        doneBtnLabel='Done'
        skipBtnLabel=''
        nextBtnLabel='>'
      >
      <View style={[styless.slide, { backgroundColor: '#555555' }]}>
        <View level={-25}>
          <Text style={styless.Desc1}>Welcome!</Text> 
        </View>
      </View>
      <View style={[styless.slide,{ backgroundColor: '#527bac' }]}>
        <View level={-25}>
          <Text style={styless.Desc1}>The Answer!</Text> 
        </View>
      </View>
      <View style={[styless.slide, { backgroundColor: '#33691e' }]}>
        <View level={-25}>
          <Text style={styless.Desc1}>The Question!</Text> 
        </View>
      </View>
      </AppIntro>

    );
  }
}

module.exports = intro;



这是我的--main.js(在此代码中,我正在使用TabBarIOS并自动将--nargo.ios.js用作此处的初始页面):

'use strict';

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

import Icon from 'react-native-vector-icons/Ionicons';
import nargo from './nargo.ios';

class Main extends Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedTab: 'nargo'
    };
  }


  render() {
    return (
      <TabBarIOS selectedTab={this.state.selectedTab}
        barTintColor='#dcdcdc'>
        <Icon.TabBarItem
          title="nargo"
          iconName="ios-home"
          selectedIconName="ios-home"
          selected={this.state.selectedTab === 'nargo'}
          onPress={() => {
              this.setState({
                  selectedTab: 'nargo',
              });
          }}>
        </Icon.TabBarItem>
        <Icon.TabBarItem
          onPress={() => {
                this.setState({
                    selectedTab: 'chat',
                });
          }}
          selected={this.state.selectedTab === 'chat'}
          title="Chat"
          iconName="ios-chatbubbles"
          selectedIconName="ios-chatbubbles"> 
        </Icon.TabBarItem>
      </TabBarIOS>
    );
  }
}


module.exports = Main;



这是我的--nargo.js(在此代码中,问题出在哪里。单击“购买”按钮时,我想转到--buy.js页面):

'use strict';

import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Text,
  ListView,
  TouchableHighlight,
  AlertIOS,
  SwitchIOS,
  ScrollView,
  TouchableOpacity,
  Navigator
} from 'react-native';

const styles = require('./styles.js');

import * as Animatable from 'react-native-animatable';
import Collapsible from 'react-native-collapsible';
import Accordion from 'react-native-collapsible/Accordion';


class nargo extends Component {
  render() {
    var _scrollView: ScrollView;
    return (
      <View style={styles.container}>
        <ScrollView
          ref={(scrollView) => { _scrollView = scrollView; }}
          automaticallyAdjustContentInsets={false}
          scrollEventThrottle={200}
          style={styles.scrollView}>

          <TouchableOpacity
            style={styles.buttonContainer}
            onPress={() => {
              this.props.navigator.push({name: 'buy'})
            }}
            >
              <Text style={styles.buttonText}>Buy !</Text>
          </TouchableOpacity>

        </ScrollView>

      </View>
    );
  }

}

module.exports = nargo;



这是我的--buy.js

'use strict';

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

class cak extends Component {
  render() {
    return (
      <View>
        <Text>
          Holla!
        </Text>
      </View>
    );
  }
}

module.exports = cak;



我尝试了这段代码,并给了我这个错误屏幕:

屏幕截图2016-09-06 at 8.04.10 PM.png

有人可以帮我解决此问题吗?提前致谢。




=========解决了========
<nargo navigator={this.props.navigator} />在第一个TabBariOS中添加了一行。感谢那些帮助我的人。

'use strict';

import React, { Component } from 'react';
import {
  AppRegistry,
  TabBarIOS,
  StyleSheet,
  Text,
  View
} from 'react-native';
import buy from './buy';

import Icon from 'react-native-vector-icons/Ionicons';
import nargo from './nargo.ios';


class Main extends Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedTab: 'nargo'
    };
  }


  render() {
    return (
      <TabBarIOS selectedTab={this.state.selectedTab}
        barTintColor='#dcdcdc'>
        <Icon.TabBarItem
          title="nargo"
          iconName="ios-home"
          selectedIconName="ios-home"
          selected={this.state.selectedTab === 'nargo'}
          onPress={() => {
              this.setState({
                  selectedTab: 'nargo',
              });
          }}>
          <nargo navigator={this.props.navigator} />
        </Icon.TabBarItem>
        <Icon.TabBarItem
          onPress={() => {
                this.setState({
                    selectedTab: 'chat',
                });
          }}
          selected={this.state.selectedTab === 'chat'}
          title="Chat"
          iconName="ios-chatbubbles"
          selectedIconName="ios-chatbubbles"> 
        </Icon.TabBarItem>
      </TabBarIOS>
    );
  }
}


module.exports = Main;
阿卜杜勒阿齐兹·阿尔卡哈拉什(Abdulaziz Alkharashi)

如果要浏览组件,则应在选项卡栏项目内传递组件,也应通过导航器,例如:

  <TabBarIOS selectedTab={this.state.selectedTab}
    barTintColor='#dcdcdc'>
    <Icon.TabBarItem
      title="nargo"
      iconName="ios-home"
      selectedIconName="ios-home"
      selected={this.state.selectedTab === 'nargo'}
      onPress={() => {
          this.setState({
              selectedTab: 'nargo',
          });
      }}>

     //here you should pass the component and the navigator, ex:
     <ComponentName navigator={this.props.navigator} />

    </Icon.TabBarItem>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

未定义的 navigator.push React-native 0.43.4

来自分类Dev

react-router无法读取未定义的属性“ push”

来自分类Dev

react-router“无法读取未定义的属性“ push”

来自分类Dev

Typescript,React:TypeError:无法读取未定义的属性“ push”

来自分类Dev

TypeError:无法读取未定义的React Native的属性'map'

来自分类Dev

React-Native-无法读取未定义的属性“ cloneWithRowsAndSections”

来自分类Dev

React Native + Fetch => TypeError:无法读取未定义的属性“then”

来自分类Dev

TypeError:无法读取未定义的Jest测试的属性'params'-React Native

来自分类Dev

React Native JEST TDD-无法读取未定义的属性“ getByText”

来自分类Dev

如何避免TypeError:无法读取React Native中未定义的属性“ picture”?

来自分类Dev

React Native-TypeError:无法读取未定义的属性“ clean”

来自分类Dev

React Native 测试失败:“TypeError:无法读取未定义的属性‘fs’”

来自分类Dev

无法读取未定义的 Facebook Firebase 和 React-Native 的属性“凭据”

来自分类Dev

React Native Navigation 如何推送屏幕?(无法读取未定义的属性推送)

来自分类Dev

无法读取未定义的 react-native-app-auth 的属性“授权”

来自分类Dev

无法读取 React-Native 和 React-Navigation 3.x 上未定义的属性“ScrollView”

来自分类Dev

React无法读取未定义的属性

来自分类Dev

无法读取未定义的属性“字符串”试图通过 react-native-create-bridge 理解 React Native Native Modules

来自分类Dev

react-native push-notification-ios geMessage和getAlert返回未定义

来自分类Dev

TypeError:无法读取未定义的JavaScript属性“ push”

来自分类Dev

合并数组时无法读取未定义的属性“ push”

来自分类Dev

无法读取未定义Javascript的属性“ push”

来自分类Dev

Angular无法读取未定义的属性“ push”

来自分类Dev

TypeScript:无法读取[null]中未定义的属性“ push”

来自分类Dev

TypeError:无法读取JavaScript中未定义的属性“ push”

来自分类Dev

Angular FormArray:无法读取未定义的属性“ push”

来自分类Dev

NodeJS无法读取未定义的属性“ push”

来自分类Dev

TypeError:无法读取未定义ReactJS的属性“ push”

来自分类Dev

ReactJS钩子无法读取未定义错误的属性“ push”

Related 相关文章

  1. 1

    未定义的 navigator.push React-native 0.43.4

  2. 2

    react-router无法读取未定义的属性“ push”

  3. 3

    react-router“无法读取未定义的属性“ push”

  4. 4

    Typescript,React:TypeError:无法读取未定义的属性“ push”

  5. 5

    TypeError:无法读取未定义的React Native的属性'map'

  6. 6

    React-Native-无法读取未定义的属性“ cloneWithRowsAndSections”

  7. 7

    React Native + Fetch => TypeError:无法读取未定义的属性“then”

  8. 8

    TypeError:无法读取未定义的Jest测试的属性'params'-React Native

  9. 9

    React Native JEST TDD-无法读取未定义的属性“ getByText”

  10. 10

    如何避免TypeError:无法读取React Native中未定义的属性“ picture”?

  11. 11

    React Native-TypeError:无法读取未定义的属性“ clean”

  12. 12

    React Native 测试失败:“TypeError:无法读取未定义的属性‘fs’”

  13. 13

    无法读取未定义的 Facebook Firebase 和 React-Native 的属性“凭据”

  14. 14

    React Native Navigation 如何推送屏幕?(无法读取未定义的属性推送)

  15. 15

    无法读取未定义的 react-native-app-auth 的属性“授权”

  16. 16

    无法读取 React-Native 和 React-Navigation 3.x 上未定义的属性“ScrollView”

  17. 17

    React无法读取未定义的属性

  18. 18

    无法读取未定义的属性“字符串”试图通过 react-native-create-bridge 理解 React Native Native Modules

  19. 19

    react-native push-notification-ios geMessage和getAlert返回未定义

  20. 20

    TypeError:无法读取未定义的JavaScript属性“ push”

  21. 21

    合并数组时无法读取未定义的属性“ push”

  22. 22

    无法读取未定义Javascript的属性“ push”

  23. 23

    Angular无法读取未定义的属性“ push”

  24. 24

    TypeScript:无法读取[null]中未定义的属性“ push”

  25. 25

    TypeError:无法读取JavaScript中未定义的属性“ push”

  26. 26

    Angular FormArray:无法读取未定义的属性“ push”

  27. 27

    NodeJS无法读取未定义的属性“ push”

  28. 28

    TypeError:无法读取未定义ReactJS的属性“ push”

  29. 29

    ReactJS钩子无法读取未定义错误的属性“ push”

热门标签

归档