community.infinite.red
source http://hackflow.com/blog/2015/03/08/boiling-react-down-to-few-lines-in-jquery/
Uses the built-in "native" APIs to create views, communicate with servers (network), access GPS, etc
Runs JavaScript code to determine business logic, coordinate events, resolve view changes, etc
import * as React from "react"
import { View } from "react-native"
import { Text, Button, Screen, Footer } from "../../components"
export class WelcomeScreen extends React.Component {
nextScreen = () => this.props.navigation.navigate("tabs")
render() {
return (
<Screen>
<View style={TOP_CONTAINER}>
<Text tx="welcomeScreen.header1" style={HEADER1} />
<Text tx="welcomeScreen.header2" style={HEADER2} />
<Text tx="welcomeScreen.subtitle" style={SUBHEADER} />
</View>
<Footer>
<Button
tx="welcomeScreen.nextScreenButton"
onPress={this.nextScreen}
style={{ width: 335, height: 50, borderRadius: 0 }}
textStyle={{ fontSize: 14, fontWeight: "500" }}
/>
</Footer>
</Screen>
)
}
}
$("#btn").click(function() {
if ($(this).text() === 'Add Highlight') {
$(this).addClass("highlight")
$(this).text('Remove Highlight')
} else {
$(this).removeClass("highlight")
$(this).text('Add Highlight')
}
})
toggleHighlight = () => {
this.setState({ highlight: !this.state.highlight })
}
<Btn
highlight={this.state.highlight}
onClick={this.toggleHighlight}
/>
This:
Compiles to:
<Text color="blue">Click Me</Text>
React.createElement(Text, {color: 'blue'}, 'Click Me')
<View>
<Text>Hello World</Text>
</View>
<button onClick="myFunction()">
<div>
<p>Hello World</p>
</div>
<View>
</View>
<div>
</div>
<input type="text">
<TextInput />
<Button onPress={myFunction} />
const person = { name: ‘Chris’, age: 22 }
<View>
<Text>Hello { person.name }</Text>
</View>
// "Hello Chris"
<View>
<Text>Hello!</Text>
<Text>Good to see you here.</Text>
</View>
View
ScrollView
Text
TextInput
Image
TouchableOpacity
HTML | React Native |
---|---|
<div> | <View> |
<p> | <Text> |
<input /> | <TextInput /> |
<button> | <TouchableOpacity /> |
import React from 'react'
import { View, Text } from 'react-native'
class MyComponent extends React.Component {
render() {
return (
<View>
<Text>Hello World</Text>
</View>
)
}
}
// example usage
<MyComponent />
React
class
$ react-native init HelloWorld
✨ Done in 4.01s.
To run your app on iOS:
cd /Users/aj/Projects/HelloWorld
react-native run-ios
- or -
Open ios/HelloWorld.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
cd /Users/aj/Projects/HelloWorld
Have an Android emulator running (quickest way to get started), or a device connected
react-native run-android
$ cd HelloWorld
$ react-native run-ios
App.js
style object
const styles = {
text: {
color: "red"
}
}
export App = () => {
return <Text style={styles.text}>Hello World</Text>
}
StyleSheet
// ... imports ⬆︎
export class App extends Component {
render () {
return (
<View style={styles.container}>
<Text style={styles.text}>Hello World</Text>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
width: 300,
height: 130
},
text: {
color: "red"
}
})
backgroundColor
background-color
vs
Flexbox is designed to provide a consistent layout on different screen sizes.
You will normally use a combination of:
flexDirection
alignItems
justifyContent
to achieve the right layout.