Style

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
class MyFirstReactNativeProject extends Component {
render() {
return (
<View>
<Text style={styles.justRed}>just red text</Text>
<Text style={styles.bigGreen}>just big green text</Text>
<Text style={[styles.bigGreen, styles.justRed]}>big green then red text</Text>
<Text style={[styles.justRed, styles.bigGreen]}>red then big green text</Text>
</View>
);
}
}
const styles = StyleSheet.create({
bigGreen : {
color : '#00ff00',
fontWeight : 'bold',
fontSize : 25
},
justRed : {
color : 'red',
},
});
AppRegistry.registerComponent('MyFirstReactNativeProject', () => MyFirstReactNativeProject);
Read more »

State

import React, { Component } from 'react';
import { AppRegistry, Text, View } from 'react-native';
class Blink extends Component {
constructor(props) {
super(props);
this.state = {showText: true};
setInterval(() => {
this.setState({showText: !this.state.showText});
}, 1000);
}
render() {
let display = this.state.showText ? this.props.text : '';
return (
<Text>{display}</Text>
);
}
}
class MyFirstReactNativeProject extends Component {
render() {
return (
<View>
<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>
);
}
}
AppRegistry.registerComponent('MyFirstReactNativeProject', () => MyFirstReactNativeProject);
Read more »

Props

Bananas

import React, { Component } from 'react';
import { AppRegistry, Image } from 'react-native';
class MyFirstReactNativeProject extends Component {
render() {
let pic = {
uri : 'https://upload.wikimedia.org/wikipedia/commons/d/de/Bananavarieties.jpg'
};
return (
<Image source={pic} style={{width: 193, height: 110}}/>
);
}
}
AppRegistry.registerComponent('MyFirstReactNativeProject', () => MyFirstReactNativeProject);
Read more »

Hello World again

import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
class MyFirstReactNativeProject extends Component {
render() {
return (
<Text>
Hello World!
</Text>
);
}
}
AppRegistry.registerComponent('MyFirstReactNativeProject', () => MyFirstReactNativeProject);
Read more »

Arrow Function => in ES6

Arrow Function syntax

var greet = function (message, name) {
return message + name;
}
// arrow function
var arrowGreet1 = (message, name) => {
return message + name;
}
var arrowGreet2 = (message, name) => message + name;
var square = x => x ^ 2;
Read more »

Define the models

// Define JQPerson model
#import <Foundation/Foundation.h>
@class JQChild;
typedef NS_ENUM(NSInteger, JQSex) {
JQSexMale = 0,
JQSexFemale,
JQSexUnknown
};
@interface JQPerson : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, assign) NSInteger age;
@property (nonatomic, assign) JQSex sex;
@property (nonatomic, copy) NSString *address;
@property (nonatomic, assign, getter=isMarried) BOOL marriage;
@property (nonatomic, strong) JQChild *child;
@end
/**************************************************************/
// Define JQChild model
#import <Foundation/Foundation.h>
@interface JQChild : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, assign) NSInteger age;
@end
Read more »

简介

你可以在你的 APP 中使用 UIWebView 内嵌网页内容,你也可以在网页浏览历史中前进或后退,甚至利用代码改变网页内容。除了 HTML 网页以外,UIWebView 还可以用来展示其它内容,例如:Keynote、PDF 以及 Pages 文档,但是为了富文本的更好渲染,还是最好使用 UITextView。

Read more »