Skip to content

Commit 309cfde

Browse files
Finished recording 6th app
1 parent 284a827 commit 309cfde

File tree

10 files changed

+276
-122
lines changed

10 files changed

+276
-122
lines changed

Project-Six-contribution.md

Whitespace-only changes.

currencyConverter06/App.tsx

Lines changed: 0 additions & 118 deletions
This file was deleted.

currencyConverter06/__tests__/App-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'react-native';
66
import React from 'react';
7-
import App from '../App';
7+
import App from '../src/App';
88

99
// Note: test renderer must be required after react-native.
1010
import renderer from 'react-test-renderer';

currencyConverter06/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import {AppRegistry} from 'react-native';
6-
import App from './App';
6+
import App from './src/App';
77
import {name as appName} from './app.json';
88

99
AppRegistry.registerComponent(appName, () => App);

currencyConverter06/package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

currencyConverter06/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"dependencies": {
1313
"react": "18.2.0",
14-
"react-native": "0.71.4"
14+
"react-native": "0.71.4",
15+
"react-native-snackbar": "^2.4.0"
1516
},
1617
"devDependencies": {
1718
"@babel/core": "^7.20.0",

currencyConverter06/src/App.tsx

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
2+
import React, { useState } from 'react';
3+
4+
import {
5+
FlatList,
6+
Pressable,
7+
SafeAreaView,
8+
ScrollView,
9+
StatusBar,
10+
StyleSheet,
11+
Text,
12+
TextInput,
13+
useColorScheme,
14+
View,
15+
} from 'react-native';
16+
17+
18+
//Constants
19+
import { currencyByRupee } from './constants';
20+
//Component
21+
import CurrencyButton from './components/CurrencyButton';
22+
23+
import Snackbar from 'react-native-snackbar';
24+
25+
26+
27+
28+
const App = (): JSX.Element => {
29+
const [inputValue, setInputValue] = useState('')
30+
const [resultValue, setResultValue] = useState('')
31+
const [targetCurrency, setTargetCurrency] = useState('')
32+
33+
const buttonPressed = (targetValue: Currency) => {
34+
if (!inputValue) {
35+
return Snackbar.show({
36+
text: "Enter a value to convert",
37+
backgroundColor: "#EA7773",
38+
textColor: "#000000"
39+
})
40+
}
41+
42+
const inputAmount = parseFloat(inputValue)
43+
if (!isNaN(inputAmount)) {
44+
const convertedValue = inputAmount * targetValue.value
45+
const result = `${targetValue.symbol} ${convertedValue.toFixed(2) }`
46+
setResultValue(result)
47+
setTargetCurrency(targetValue.name)
48+
} else {
49+
return Snackbar.show({
50+
text: "NOt a valid number to convert",
51+
backgroundColor: "#F4BE2C",
52+
textColor: "#000000"
53+
})
54+
}
55+
}
56+
57+
return (
58+
<>
59+
<StatusBar/>
60+
<View style={styles.container}>
61+
<View style={styles.topContainer}>
62+
<View style={styles.rupeesContainer}>
63+
<Text style={styles.rupee}></Text>
64+
<TextInput
65+
maxLength={14}
66+
value={inputValue}
67+
clearButtonMode='always' //only for iOS
68+
onChangeText={setInputValue}
69+
keyboardType='number-pad'
70+
placeholder='Enter amount in Rupees'
71+
/>
72+
</View>
73+
{resultValue && (
74+
<Text style={styles.resultTxt} >
75+
{resultValue}
76+
</Text>
77+
)}
78+
</View>
79+
<View style={styles.bottomContainer}>
80+
<FlatList
81+
numColumns={3}
82+
data={currencyByRupee}
83+
keyExtractor={item => item.name}
84+
renderItem={({item}) => (
85+
<Pressable
86+
style={[
87+
styles.button,
88+
targetCurrency === item.name && styles.selected
89+
]}
90+
onPress={() => buttonPressed(item)}
91+
>
92+
<CurrencyButton {...item} />
93+
</Pressable>
94+
)}
95+
/>
96+
</View>
97+
</View>
98+
99+
</>
100+
);
101+
}
102+
103+
const styles = StyleSheet.create({
104+
container: {
105+
flex: 1,
106+
backgroundColor: '#515151',
107+
},
108+
topContainer: {
109+
flex: 1,
110+
alignItems: 'center',
111+
justifyContent: 'space-evenly',
112+
},
113+
resultTxt: {
114+
fontSize: 32,
115+
color: '#000000',
116+
fontWeight: '800',
117+
},
118+
rupee: {
119+
marginRight: 8,
120+
121+
fontSize: 22,
122+
color: '#000000',
123+
fontWeight: '800',
124+
},
125+
rupeesContainer: {
126+
flexDirection: 'row',
127+
alignItems: 'center',
128+
},
129+
inputAmountField: {
130+
height: 40,
131+
width: 200,
132+
padding: 8,
133+
borderWidth: 1,
134+
borderRadius: 4,
135+
backgroundColor: '#FFFFFF',
136+
},
137+
bottomContainer: {
138+
flex: 3,
139+
},
140+
button: {
141+
flex: 1,
142+
143+
margin: 12,
144+
height: 60,
145+
146+
borderRadius: 12,
147+
backgroundColor: '#fff',
148+
elevation: 2,
149+
shadowOffset: {
150+
width: 1,
151+
height: 1,
152+
},
153+
shadowColor: '#333',
154+
shadowOpacity: 0.1,
155+
shadowRadius: 1,
156+
},
157+
selected: {
158+
backgroundColor: '#ffeaa7',
159+
},
160+
});
161+
162+
export default App;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react'
2+
import type { PropsWithChildren } from 'react'
3+
4+
import { View, Text, StyleSheet} from 'react-native'
5+
6+
type CurrencyButtonProps = PropsWithChildren<{
7+
name: string;
8+
flag: string;
9+
}>
10+
11+
const CurrencyButton = (props: CurrencyButtonProps): JSX.Element => {
12+
return(
13+
<View style={styles.buttonContainer}>
14+
<Text style={styles.flag}>{props.flag}</Text>
15+
<Text style={styles.country}>{props.name}</Text>
16+
</View>
17+
)
18+
}
19+
20+
const styles = StyleSheet.create({
21+
buttonContainer : {
22+
alignItems: 'center'
23+
},
24+
flag: {
25+
fontSize: 28,
26+
color: "#FFFFFF",
27+
marginBottom: 4
28+
},
29+
country: {
30+
fontSize: 14,
31+
color: "#2d3436",
32+
33+
}
34+
})
35+
36+
export default CurrencyButton

0 commit comments

Comments
 (0)