【问题标题】:Not understanding NavigatorIOS React Naitive不了解 Navigator IOS React Native
【发布时间】:2016-10-10 12:33:30
【问题描述】:

所以我的应用程序非常基本:

import React, { Component } from 'react';
import Landing from './App/pages/landing.js';

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

class twitterQue extends Component {

  _enter() {
    console.log('Hey Girl');
  }

  render() {
    return (
      <NavigatorIOS
        initialRoute={{
          component: Landing,
          title: 'Welcome!',
          passProps: {},
        }}
      />
    );
  }
}

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

然后我有一个登陆组件:

import React, { Component } from 'react';
import Button from '../components/button/buttons.js';

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

class Landing extends Component {

  _enter() {
    console.log('Hey Girl');
  }

  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Twitter Que
        </Text>
        <Button type={"primary"} buttonWidth={240} onPress={() => this._enter()}>Que Up Some Tweets!</Button>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
});

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

module.exports = Landing;

没有什么时髦的。页面上没有任何内容,也没有错误。应用程序加载,我看到“欢迎!”作为标题,但 (Landing) 组件未显示。 我错过了什么吗?

如果我将所有东西从 Landing render 移到 index.js render 中,它就可以工作。我是不是误解了docs

【问题讨论】:

    标签: javascript ios facebook react-native


    【解决方案1】:

    尝试将style={{flex:1}} 添加到 NavigatorIOS:

    <NavigatorIOS
        style={{flex:1}}
        initialRoute={{
          component: Landing,
          title: 'Welcome!',
          passProps: {},
        }}
      />
    

    NavigatorIOS 没有开箱即用的默认样式。所以基本上没有指定默认宽度或高度。这意味着,如果您不指定宽度和高度或 flex 值,则它不会显示在您的视图中。

    【讨论】:

    • 这行得通,但您能否更新您的答案以说明它为什么行得通?
    • 嘿,很高兴这有效。我已经更新了答案以给出更好的解释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多