javascript - 不了解 Navigator IOS React Native

标签 javascript ios facebook react-native

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

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

最佳答案

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

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

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

关于javascript - 不了解 Navigator IOS React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37733020/

相关文章:

ios - 为什么我不能在 Swift 中重新分配实例方法?

java - Facebook 登录按钮在点击时导致应用程序崩溃

javascript - jQuery ajax 调用 php 处理表单页面未返回成功或错误

javascript - 如何使用js检测html加载的数据

ios - 重新打开后应用程序崩溃

Android/iOS OpenCV 扩眼检测

python - Facebook 评论正则表达式匹配

android - 在android facebook sdk 4中从facebook注销时检查用户是否

javascript - Django 尝试将我的数组保存到模型中

javascript - HTML 在另一个脚本完成执行后加载一个脚本