第一个react-native工程,简单点

推荐一个学习react-native的好网站,是将react-native在github上面的文章翻译过来的中文网站,挺适合一个入门react-native的人学习,http://reactnative.cn/,学的时候最好选择最新的学习,我选择的是0.39版本。
附上截图:
这里写图片描述
也没啥好讲的,自己也是刚学没几天,就当做个笔记吧。修改的是index.android.js这个文件,修改之后安装到手机上就可以看见,写的乱糟糟的,瞎看看。

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */
import React from 'react';
import { AppRegistry, StyleSheet, Text, View, ListView, Image} from 'react-native';

class Greeting extends React.Component {
  render() {
    return (
      <Text>
        Hello {this.props.name}!
      </Text>
    );
  }
}

class Blink extends React.Component {
  constructor(props) {
    super(props);
    this.state = { showText: true };

    // 每1000毫秒对showText状态做一次取反操作
    setInterval(() => {
      this.setState({ showText: !this.state.showText });
    }, 500);
  }

  render() {
    // 根据当前showText的值决定是否显示text内容
    let display = this.state.showText ? this.props.text : "么得";
    return (
      <Text>{display}</Text>
    );
  }
}

class test extends React.Component {
  // 初始化模拟数据
  constructor(props) {
    super(props);
    var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      dataSource: ds.cloneWithRows(['John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie', 'caojunsheng', 'hahaha', 'demo', 'hello', 'Jimmy', 'Jackson', 'Jillian', 'Julie', 'caojunsheng', 'hahaha'])
    };
  }
  render() {
    let pic = {
      uri: 'http://pic37.nipic.com/20140104/9885883_151644517000_2.jpg'
    };
    return (
      <View>
        <Text>
          <Text>First part and </Text>
          <Text>second part</Text>
        </Text>

        <View>
          <Text>First part and </Text>
          <Text>second part</Text>
        </View>
        <Text style={{fontWeight: 'bold'}}>
          I am bold
          <Text style={{color: 'red'}}>
            {' and red'}
          </Text>
        </Text>
        <Blink text='I love to blink' />
        <Blink text='Yes blinking is so great' />
        <Blink text='Why did they ever take this out of HTML' />
        <Blink text='Look at me look at me look at me' />
        <View>
          <Greeting name='Rexxar' />
          <Greeting name='Jaina' />
          <Greeting name='Valeera' />
        </View>
        <Image source={pic} style={{width:200,height: 110}} />
        <Text style={styles.textstyle1}>
          {"一个listview列表啊"}
        </Text>
        <ListView
          dataSource={this.state.dataSource}
          renderRow={(rowData) => <Text style={styles.textstyle}>{rowData}</Text>}
          style={styles.container}
        />
      </View>
    );
  }
}
class LotsOfGreetings extends React.Component {
  render() {
    return (
      <View style={{alignItems: 'center'}}>
        <Greeting name='Rexxar' />
        <Greeting name='Jaina' />
        <Greeting name='Valeera' />
      </View>
    );
  }
}
const styles = StyleSheet.create({
  container: {
    backgroundColor: '#F5FCFF',
  },
  textstyle:{
    marginLeft:20,
    fontSize: 30
  },
  textstyle1:{
    textAlignVertical: 'center',
    fontSize: 30,
    color: "#FF4500"
  },
});
AppRegistry.registerComponent('test', () => test);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值