美文网首页
ReactNative入门

ReactNative入门

作者: 进击的鸭子 | 来源:发表于2017-06-30 20:42 被阅读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,
      },
    });
    
    

    相关文章

      网友评论

          本文标题:ReactNative入门

          本文链接:https://www.haomeiwen.com/subject/spvicxtx.html