WebとNative Appの境目はなくなりつつある
対応するためのTips
解決のためのライブラリ
import React, { Component } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}
});
import React, { Component } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}
});
<View>はレイアウトに関することのみ
import React, { Component } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Button
onPress={onPressLearnMore}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}
});
<Text>はテキストに関することのみ
代表的なコンポーネント
<View>
<Text>
<TextInput>
<Button>
<Image>
<Picker>
<Slider>
<Switch>
<WebView>
<ScrollView>
<ListView>
代表的なコンポーネント
<View>
<Text>
<TextInput>
<Button>
<Image>
<Picker>
<Slider>
<Switch>
<WebView>
<ScrollView>
<ListView>
<div>, <section>, <artcle>
<span>, <h1>, <h2>,<p>
<input>, <textarea>
<a>, <button>
<img>
<select>, <option>
render() {
return (
<ListView
refreshControl={
<RefreshControl
refreshing={this.state.refreshing}
onRefresh={this._onRefresh.bind(this)}
/>
}
...
>
...
</ListView>
);
}
render() {
return (
<View>
<TouchableOpacity
style={styles.button}
onPress={this.onPress}
>
<Text> Touch Here </Text>
</TouchableOpacity>
<TouchableHighlight
style={styles.button}
onPress={this.onPressImage}
>
<Image source={{url:...}} />
</TouchableHighlight>
</View>
)
}
render() {
return (
<View>
<ActivityIndicator size="large" color="#0000ff" />
</View>
)
}
render() {
return (
<View>
<Text
numberOfLines={2}
> Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five ce
nturies, but also the leap into electronic typesetting, remaining essentially unchanged.
</Text>
</View>
)
}
render() {
return (
<View>
<View style={{ marginBottom: 100 }}>
<Text>margin bottom 100</Text>
</View>
<View style={{ marginTop: 100 }}>
<Text>margin top 100</Text>
</View>
</View>
)
}
React Native のコンポーネント
React DOMでReact NativeコンポーネントやAPIを実行することができる。ベースはReact.js
実績
React NativeのコードをWebに展開。ベースはReact Native
ただしまだExperimental😜
まとめ