Reactive Native enables you to be able to program an app for both ios and android. It incorporates both React and Native platform capabilities.
In your terminal, type the following to install Create React Native App
globally. This uses the expo SDK, which will enable you to launch the app on a mobile device.
npm install -g create-react-native-app
Navigate to where you would like to put the project folder and then execute the following command in your terminal.
create-react-native-app <project-name>
You then want to move into that folder and start running the app. Type the following into your terminal.
cd <project-name>
yarn start
Once the server has loaded, you will see a QR code. Use the camera on your phone/ the expo app, and you app will be launched within your mobile device.
The code and each component needed.
//App.js
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import HomeScreen from './components/HomeScreen';
import NewScreen from './components/NewScreen';
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
const AppNavigator = createStackNavigator({
Home: {
screen: HomeScreen
},
New: {
screen: NewScreen
}
});
const AppContainer = createAppContainer(AppNavigator);
//components/HomeScreen.js
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
export default class Homescreen extends Component {
render() {
return (
<View>
<Button>
<Text>
Home
</Text>
</Button>
</View>
)
}
}
//components/NewScreen.js
import React, { Component } from 'react';
import { View, Text, Button } from 'react-native';
export default class Homescreen extends Component {
render() {
return (
<View>
<Button onPress={() => this.props.navigation.navigate('New')}>
<Text>
New
</Text>
</Button>
</View>
)
}
}
<Button style={styles.button} onPress={() => this.props.navigation.navigate(‘New’)}>
… const styles = StyleSheet.create({ button: { padding:‘30%’, backgroundColor:‘#07B162’ }, text: { fontSize: 20, textAlign: ‘center’, color:‘white’, fontWeight: ‘bold’ } }) …