ReactNative入门

2017-06-30  本文已影响0人  进击的鸭子

在index.ios.js文件中注册并导入组件WeatherProject

/**
 * Sample React Native App
 * index.ios.js 
 * @flow
 */
import React from 'react-native';
import {
  AppRegistry,
} from  'react-native';

import WeatherProject from './WeatherProject';
AppRegistry.registerComponent('AwesomProject', ()=> WeatherProject);

在WeatherProject组件中设置相关的内容:

/**
 * Sample React Native App
 * WeatherProject.js
 * @flow
 */

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

export default class AwesomProject extends Component {
  constructor(props){
    super(props);
    this.state = {
      text:''
    }; 
  }

  _handleTextChange (event) {
    this.setState({
      text:event.nativeEvent.text
    });
  }

  render() {
    return (
      <View style = {styles.container}>
        <Text style = {styles.welcome}>
         you input {this.state.text}.
        </Text>
        <TextInput style = {styles.input} onSubmitEditing = {() => this._handleTextChange()} />
      </View>
     
    );
  }
}

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

上一篇下一篇

猜你喜欢

热点阅读