React-Native应用程序不显示任何内容

时间:2017-12-22 05:29:04

标签: react-native react-native-ios

当谈到本土反应时,我是一个绝对的新手。我一直在关注教程,但并未提供所有代码。我已经做到了最好 - 应用程序编译 - 但我看到的只是iOS模拟器中的空白页面。任何人都可以帮助我理解为什么我没有看到SearchPage组件中的标签吗?

App.js:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

 'use strict';

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

import SearchPage from './SearchPage';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

export default class App extends Component<{}> {
  render() {
    return (
     <NavigatorIOS
        style={styles.container}
        initialRoute={
          {
            title: 'Property Finder',
            component: SearchPage,
          }
        } /> 
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  description: {
    fontSize: 18,
    textAlign: 'center',
    color: '#656565',
    marginTop: 65,
  },
});

SearchPage.js:

'use strict';

import React, { Component } from 'react';
import {
  StyleSheet,
  Text,
  TextInput,
  View,
  Button,
  ActivityIndicator,
  Image,
} from 'react-native';

export default class SearchPage extends Component<{}> {
    render() {
      return (
        <View style={styles.container}>
          <Text style={styles.description}>
            Search for houses to buy!
          </Text>
          <Text style={styles.description}>
            Search by place-name or postcode.
          </Text>
        </View>
      );
    }
  }


  const styles = StyleSheet.create({
    description: {
      marginBottom: 20,
      fontSize: 18,
      textAlign: 'center',
      color: '#656565'
    },
    container: {
      padding: 30,
      marginTop: 65,
      alignItems: 'center'
    },
  });

如果我用SearchPage.render()的内容替换App.render(),那么我确实看到了2个标签。

本教程是针对iOS的。模拟器是iPhone 6 iOS 11.2。 如果需要任何其他信息,请发表评论。

0 个答案:

没有答案