算是第一个RN程序了,纪录一下

组件:

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

export default class Header extends React.Component
{
    render(){
        return (
            
               
                  网易
                  新闻
                  有态度
               
            
        );
    }
}

const styles = StyleSheet.create({
    flex:{
        marginTop:25,
        height:50,
        borderBottomWidth:3 / PixelRatio.get(),
        borderBottomColor:'#EF2D36',
        alignItems:'center'
    },
    font:{
        fontSize:25,
        fontWeight:'bold',
        textAlign:'center'
    },
    font_1:
    {
        color:'#CD1D1C'
    },
    font_2:
    {
        color:'#FFF',
        backgroundColor:'#CD1D1C'
    }
});

使用组件:

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

import Header from './header'

class hello extends Component {
  render() 
  {
    return (
      
         
); } } const styles = StyleSheet.create({ flex:{ flex:1 }, }); AppRegistry.registerComponent('hello', () => hello);

碰到最大的坑,组件名字首字母必须大写,不然不行,这坑让我发了一个小时。
效果:

算是第一个RN程序了,纪录一下_第1张图片
2786B2DA-8163-4310-A60B-027D766470A7.png

你可能感兴趣的:(算是第一个RN程序了,纪录一下)