Página da disciplina de pos (Programação Orientada a Serviços) do curso técnico integrado de Informática para Internet.
Objetivos:
cd CurrencyConverter
yarn add react-navigation react-native-dropdownalert hoist-non-react-statics
yarn start
mkdir app/config
touch app/config/routes.js
app/config/routes.js
import { StackNavigator } from 'react-navigation';
import Home from '../screens/Home';
import CurrencyList from '../screens/CurrencyList';
export default StackNavigator({
Home: {
screen: Home,
},
CurrencyList: {
screen: CurrencyList
},
});
app/index.js
import React from 'react';
import EStyleSheet from 'react-native-extended-stylesheet';
import Navigator from './config/routes';
EStyleSheet.build({
$primaryBlue: '#4F6D7A',
$primaryOrange: '#D57A66',
$primaryGreen: '#00BD9D',
$primaryPurple: '#9E768F',
$white: '#FFFFFF',
$lightGray: '#F0F0F0',
$border: '#979797',
$inputText: '#797979',
$darkText: '#343434',
});
export default () => <Navigator />;
app/config/routes.js
import { StackNavigator } from 'react-navigation';
import Home from '../screens/Home';
import CurrencyList from '../screens/CurrencyList';
export default StackNavigator({
Home: {
screen: Home,
navigationOptions: {
header: () => null,
},
},
CurrencyList: {
screen: CurrencyList
},
});
app/screens/Home.js
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { KeyboardAvoidingView, StatusBar } from 'react-native';
import { Container } from '../components/Container';
import { Logo } from '../components/Logo';
import { InputWithButton } from '../components/TextInput';
import { ClearButton } from '../components/Button';
import { LastConverted } from '../components/Text';
import { Header } from '../components/Header';
const TEMP_BASE_CURRENCY = 'USD';
const TEMP_QUOTE_CURRENCY = 'GBP';
const TEMP_BASE_PRICE = '100';
const TEMP_QUOTE_PRICE = '79.74';
const TEMP_LAST_CONVERTED = new Date();
const TEMP_CONVERSION_RATE = 0.79739;
class Home extends Component {
static propTypes = {
navigation: PropTypes.object,
};
handleChangeText = () => {
console.log('change text');
};
handlePressBaseCurrency = () => {
this.props.navigation.navigate('CurrencyList');
};
handlePressQuoteCurrency = () => {
this.props.navigation.navigate('CurrencyList');
};
handle = () => {
console.log('clear button pressed');
};
handleOptionsPress = () => {
console.log('options press');
};
render() {
return (
<Container>
<StatusBar backgroundColor="blue" barStyle="light-content" />
<Header onPress={this.handleOptionsPress} />
<KeyboardAvoidingView behavior="padding">
<Logo />
<InputWithButton
buttonText={TEMP_BASE_CURRENCY}
onPress={this.handlePressBaseCurrency}
defaultValue={TEMP_BASE_PRICE}
keyboardType="numeric"
onChangeText={this.handleChangeText}
/>
<InputWithButton
editable={false}
buttonText={TEMP_QUOTE_CURRENCY}
onPress={this.handlePressQuoteCurrency}
value={TEMP_QUOTE_PRICE}
/>
<LastConverted
date={TEMP_LAST_CONVERTED}
base={TEMP_BASE_CURRENCY}
quote={TEMP_QUOTE_CURRENCY}
conversionRate={TEMP_CONVERSION_RATE}
/>
<ClearButton text="clear" onPress={this.handle} />
</KeyboardAvoidingView>
</Container>
);
}
}
export default Home;
app/config/routes.js
import { StackNavigator } from 'react-navigation';
import Home from '../screens/Home';
import CurrencyList from '../screens/CurrencyList';
export default StackNavigator(
{
Home: {
screen: Home,
navigationOptions: {
header: () => null,
},
},
CurrencyList: {
screen: CurrencyList
}
},
{
mode: 'modal',
}
);
app/screens/Home.js
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { KeyboardAvoidingView, StatusBar } from 'react-native';
import { Container } from '../components/Container';
import { Logo } from '../components/Logo';
import { InputWithButton } from '../components/TextInput';
import { ClearButton } from '../components/Button';
import { LastConverted } from '../components/Text';
import { Header } from '../components/Header';
const TEMP_BASE_CURRENCY = 'USD';
const TEMP_QUOTE_CURRENCY = 'GBP';
const TEMP_BASE_PRICE = '100';
const TEMP_QUOTE_PRICE = '79.74';
const TEMP_LAST_CONVERTED = new Date();
const TEMP_CONVERSION_RATE = 0.79739;
class Home extends Component {
static propTypes = {
navigation: PropTypes.object,
};
handleChangeText = () => {
console.log('change text');
};
handlePressBaseCurrency = () => {
this.props.navigation.navigate('CurrencyList', {title: 'Base currency'});
};
handlePressQuoteCurrency = () => {
this.props.navigation.navigate('CurrencyList', {title: 'Quote currency'});
};
handle = () => {
console.log('clear button pressed');
};
handleOptionsPress = () => {
console.log('options press');
};
render() {
return (
<Container>
<StatusBar backgroundColor="blue" barStyle="light-content" />
<Header onPress={this.handleOptionsPress} />
<KeyboardAvoidingView behavior="padding">
<Logo />
<InputWithButton
buttonText={TEMP_BASE_CURRENCY}
onPress={this.handlePressBaseCurrency}
defaultValue={TEMP_BASE_PRICE}
keyboardType="numeric"
onChangeText={this.handleChangeText}
/>
<InputWithButton
editable={false}
buttonText={TEMP_QUOTE_CURRENCY}
onPress={this.handlePressQuoteCurrency}
value={TEMP_QUOTE_PRICE}
/>
<LastConverted
date={TEMP_LAST_CONVERTED}
base={TEMP_BASE_CURRENCY}
quote={TEMP_QUOTE_CURRENCY}
conversionRate={TEMP_CONVERSION_RATE}
/>
<ClearButton text="clear" onPress={this.handle} />
</KeyboardAvoidingView>
</Container>
);
}
}
export default Home;
app/config/routes.js
import { StackNavigator } from 'react-navigation';
import Home from '../screens/Home';
import CurrencyList from '../screens/CurrencyList';
export default StackNavigator(
{
Home: {
screen: Home,
navigationOptions: {
header: () => null,
},
},
CurrencyList: {
screen: CurrencyList,
navigationOptions: ({navigation}) => ({
headerTitle: navigation.state.params.title,
}),
},
},
{
mode: 'modal',
}
);
app/screens/CurrencyList.js
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { FlatList, StatusBar, View } from 'react-native';
import currencies from '../data/currencies';
import { ListItem } from '../components/List';
const TEMP_CURRENT_CURRENCY = 'CAD';
class CurrencyList extends Component {
static propTypes = {
navigation: PropTypes.object,
};
handlePress = () => {
this.props.navigation.goBack(null);
};
render() {
return (
<View>
<StatusBar translucent={false} barStyle="default" />
<FlatList
data={currencies}
renderItem={({ item }) => (
<ListItem
text={item}
selected={item === TEMP_CURRENT_CURRENCY}
onPress={this.handlePress}
/>
)}
keyExtractor={item => item}
/>
</View>
);
}
}
export default CurrencyList;
app/config/routes.js
import { StatusBar } from 'react-native';
import { StackNavigator } from 'react-navigation';
import Home from '../screens/Home';
import CurrencyList from '../screens/CurrencyList';
export default StackNavigator(
{
Home: {
screen: Home,
navigationOptions: {
header: () => null,
},
},
CurrencyList: {
screen: CurrencyList,
navigationOptions: ({navigation}) => ({
headerTitle: navigation.state.params.title,
}),
}
},
{
mode: 'modal',
cardStyle: {
paddingTop: StatusBar.currentHeight,
},
},
);
app/components/Header/styles.js
import EStyleSheet from 'react-native-extended-stylesheet';
export default EStyleSheet.create({
container: {
position: 'absolute',
left: 0,
top: 0,
right: 0,
'@media ios': {
paddingTop: 20,
}
},
button: {
alignSelf: 'flex-end',
paddingVertical: 5,
paddingHorizontal: 20,
},
icon: {
width: 18,
},
});
app/index.js
import React from 'react';
import EStyleSheet from 'react-native-extended-stylesheet';
import Navigator from './config/routes';
EStyleSheet.build({
$primaryBlue: '#4F6D7A',
$primaryOrange: '#D57A66',
$primaryGreen: '#00BD9D',
$primaryPurple: '#9E768F',
$white: '#FFFFFF',
$lightGray: '#F0F0F0',
$border: '#979797',
$inputText: '#797979',
$darkText: '#343434',
});
export default () => <Navigator />;
app/config/routes.js
import { StatusBar } from 'react-native';
import { StackNavigator } from 'react-navigation';
import Home from '../screens/Home';
import CurrencyList from '../screens/CurrencyList';
export default StackNavigator({
Home: {
screen: Home,
navigationOptions: {
header: () => null,
},
},
CurrencyList: {
screen: CurrencyList,
navigationOptions: ({navigation}) => ({
headerTitle: navigation.state.params.title,
}),
},
{
mode: 'modal',
cardStyle: {
paddingTop: StatusBar.currentHeight,
},
},
});
app/components/Header/styles.js
import EStyleSheet from 'react-native-extended-stylesheet';
export default EStyleSheet.create({
container: {
position: 'absolute',
left: 0,
top: 0,
right: 0,
'@media ios': {
paddingTop: 20,
}
},
button: {
alignSelf: 'flex-end',
paddingVertical: 5,
paddingHorizontal: 20,
},
icon: {
width: 18,
},
});
app/screens/Home.js
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { KeyboardAvoidingView, StatusBar } from 'react-native';
import { Container } from '../components/Container';
import { Logo } from '../components/Logo';
import { InputWithButton } from '../components/TextInput';
import { ClearButton } from '../components/Button';
import { LastConverted } from '../components/Text';
import { Header } from '../components/Header';
const TEMP_BASE_CURRENCY = 'USD';
const TEMP_QUOTE_CURRENCY = 'GBP';
const TEMP_BASE_PRICE = '100';
const TEMP_QUOTE_PRICE = '79.74';
const TEMP_LAST_CONVERTED = new Date();
const TEMP_CONVERSION_RATE = 0.79739;
class Home extends Component {
static propTypes = {
navigation: PropTypes.object,
};
handleChangeText = () => {
console.log('change text');
};
handlePressBaseCurrency = () => {
this.props.navigation.navigate('CurrencyList', {title: 'Base currency'});
};
handlePressQuoteCurrency = () => {
this.props.navigation.navigate('CurrencyList', {title: 'Quote currency'});
};
handle = () => {
console.log('clear button pressed');
};
handleOptionsPress = () => {
console.log('options press');
};
render() {
return (
<Container>
<StatusBar backgroundColor="blue" barStyle="light-content" />
<Header onPress={this.handleOptionsPress} />
<KeyboardAvoidingView behavior="padding">
<Logo />
<InputWithButton
buttonText={TEMP_BASE_CURRENCY}
onPress={this.handlePressBaseCurrency}
defaultValue={TEMP_BASE_PRICE}
keyboardType="numeric"
onChangeText={this.handleChangeText}
/>
<InputWithButton
editable={false}
buttonText={TEMP_QUOTE_CURRENCY}
onPress={this.handlePressQuoteCurrency}
value={TEMP_QUOTE_PRICE}
/>
<LastConverted
date={TEMP_LAST_CONVERTED}
base={TEMP_BASE_CURRENCY}
quote={TEMP_QUOTE_CURRENCY}
conversionRate={TEMP_CONVERSION_RATE}
/>
<ClearButton text="clear" onPress={this.handle} />
</KeyboardAvoidingView>
</Container>
);
}
}
export default Home;
app/screens/CurrencyList.js
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { FlatList, StatusBar, View } from 'react-native';
import currencies from '../data/currencies';
import { ListItem } from '../components/List';
const TEMP_CURRENT_CURRENCY = 'CAD';
class CurrencyList extends Component {
static propTypes = {
navigation: PropTypes.object,
};
handlePress = () => {
this.props.navigation.goBack(null);
};
render() {
return (
<View>
<StatusBar translucent={false} barStyle="default" />
<FlatList
data={currencies}
renderItem={({ item }) => (
<ListItem
text={item}
selected={item === TEMP_CURRENT_CURRENCY}
onPress={this.handlePress}
/>
)}
keyExtractor={item => item}
/>
</View>
);
}
}
export default CurrencyList;