Skip to content

Commit 324cd39

Browse files
committed
React native review project 2022 added
1 parent 37d96d5 commit 324cd39

File tree

11 files changed

+206
-0
lines changed

11 files changed

+206
-0
lines changed

rn-guide/.expo-shared/assets.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
3+
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
4+
}

rn-guide/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules/
2+
.expo/
3+
dist/
4+
npm-debug.*
5+
*.jks
6+
*.p8
7+
*.p12
8+
*.key
9+
*.mobileprovision
10+
*.orig.*
11+
web-build/
12+
13+
# macOS
14+
.DS_Store

rn-guide/App.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, { useState } from "react";
2+
import { StyleSheet, View, FlatList, Button } from "react-native";
3+
4+
import GoalItem from "./components/GoalItem";
5+
import GoalInput from "./components/GoalInput";
6+
7+
export default function App() {
8+
const [courseGoals, setCourseGoals] = useState([]);
9+
const [isAddMode, setIsAddMode] = useState(false);
10+
11+
const addGoalHandler = (goalTitle) => {
12+
setCourseGoals((currentGoals) => [
13+
...currentGoals,
14+
{ key: Math.random(10).toString(), value: goalTitle },
15+
]);
16+
setIsAddMode(false);
17+
};
18+
19+
const removeGoalHandler = (goalId) => {
20+
setCourseGoals((currentGoals) => {
21+
return currentGoals.filter((goal) => goal.key !== goalId);
22+
});
23+
};
24+
25+
const cancelGoalAdditionHandler = () => {
26+
setIsAddMode(false);
27+
};
28+
29+
return (
30+
<View style={styles.screen}>
31+
<Button title="Add New Goal" onPress={() => setIsAddMode(true)} />
32+
<GoalInput
33+
visible={isAddMode}
34+
onAddGoal={addGoalHandler}
35+
onCancel={cancelGoalAdditionHandler}
36+
/>
37+
<FlatList
38+
keyExtractor={(item, index) => item.key}
39+
data={courseGoals}
40+
renderItem={(itemData) => (
41+
<GoalItem
42+
id={itemData.item.key}
43+
onDelete={removeGoalHandler}
44+
title={itemData.item.value}
45+
/>
46+
)}
47+
/>
48+
</View>
49+
);
50+
}
51+
52+
const styles = StyleSheet.create({
53+
screen: {
54+
padding: 50,
55+
},
56+
});

rn-guide/app.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"expo": {
3+
"name": "rn-guide",
4+
"slug": "rn-guide",
5+
"version": "1.0.0",
6+
"orientation": "portrait",
7+
"icon": "./assets/icon.png",
8+
"splash": {
9+
"image": "./assets/splash.png",
10+
"resizeMode": "contain",
11+
"backgroundColor": "#ffffff"
12+
},
13+
"updates": {
14+
"fallbackToCacheTimeout": 0
15+
},
16+
"assetBundlePatterns": [
17+
"**/*"
18+
],
19+
"ios": {
20+
"supportsTablet": true
21+
},
22+
"android": {
23+
"adaptiveIcon": {
24+
"foregroundImage": "./assets/adaptive-icon.png",
25+
"backgroundColor": "#FFFFFF"
26+
}
27+
},
28+
"web": {
29+
"favicon": "./assets/favicon.png"
30+
}
31+
}
32+
}

rn-guide/assets/adaptive-icon.png

17.1 KB
Loading

rn-guide/assets/favicon.png

1.43 KB
Loading

rn-guide/assets/icon.png

21.9 KB
Loading

rn-guide/assets/splash.png

46.2 KB
Loading

rn-guide/babel.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(api) {
2+
api.cache(true);
3+
return {
4+
presets: ['babel-preset-expo'],
5+
};
6+
};

rn-guide/components/GoalInput.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, { useState } from "react";
2+
import { View, TextInput, Button, StyleSheet, Modal } from "react-native";
3+
4+
// import { Container } from './styles';
5+
6+
const GoalInput = (props) => {
7+
const [enteredGoal, setEnteredGoal] = useState("");
8+
9+
const goalInputHandler = (enteredText) => {
10+
setEnteredGoal(enteredText);
11+
};
12+
13+
const addGoalHandler = () => {
14+
props.onAddGoal(enteredGoal);
15+
setEnteredGoal("");
16+
};
17+
18+
return (
19+
<Modal visible={props.visible} animationType="slide">
20+
<View style={styles.inputContainer}>
21+
<TextInput
22+
placeholder="Course Goal"
23+
style={styles.input}
24+
onChangeText={goalInputHandler}
25+
value={enteredGoal}
26+
/>
27+
<View style={styles.buttonContainer}>
28+
<View style={styles.button}>
29+
<Button title="CANCEL" color="red" onPress={props.onCancel} />
30+
</View>
31+
<View style={styles.button}>
32+
<Button title="ADD" onPress={addGoalHandler} />
33+
</View>
34+
</View>
35+
</View>
36+
</Modal>
37+
);
38+
};
39+
40+
const styles = StyleSheet.create({
41+
inputContainer: {
42+
flex: 1,
43+
justifyContent: "center",
44+
alignItems: "center",
45+
},
46+
input: {
47+
width: "80%",
48+
borderColor: "black",
49+
borderWidth: 1,
50+
padding: 10,
51+
marginBottom: 10,
52+
},
53+
buttonContainer: {
54+
flexDirection: "row",
55+
justifyContent: "space-between",
56+
width: "70%",
57+
},
58+
button: {
59+
width: "40%",
60+
},
61+
});
62+
63+
export default GoalInput;

0 commit comments

Comments
 (0)