首页 > 其他 > 详细

react-native初探——helloworld demo

时间:2019-01-24 23:54:43      阅读:222      评论:0      收藏:0      [点我收藏+]

一、代码结构

技术分享图片

不同于mac开发环境,拥有index.ios.js和index.android.js两个编译文件,此处windows下仅在app.js中编译;

 二、简单的helloword一闪闪效果

app.js

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

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

    // 每1000毫秒对showText状态做一次取反操作
    setInterval(() => {
      this.setState(previousState => {
        return { showText: !previousState.showText };
      });
    }, 1000);
  }
  render() {
    // 根据当前showText的值决定是否显示text内容
    let display = this.state.showText ? this.props.text : ‘ ‘;
    return (
        <View>
          <Text style={[styles.bigblue, {color: ‘red‘}]}>{display}</Text>
        </View>
    );
  }
}

export default class App extends Component {
  render() {
    return (
      <View>
        <HelloWorldApp text=‘Hello world‘ />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  bigblue: {
    color: ‘blue‘,
    fontWeight: ‘bold‘,
    fontSize: 30,
  }
});

 三、涉及知识点

多用es6语法、react语法、jsx语法和RN语法及开发思想(组件化)等等。RN运行环境:移动端(真机或模拟器)。

react-native初探——helloworld demo

原文:https://www.cnblogs.com/bbcfive/p/10317543.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!