신승미

goal app

import { useState } from "react";
import { StyleSheet, View, FlatList, Button } from "react-native";
import { StatusBar } from "expo-status-bar";
import GoalItem from "./components/GoalItem";
import GoalInput from "./components/GoalInput";
export default function App() {
const [modalIsVisible, setModalIsVisible] = useState(false);
const [goals, setGoals] = useState([]);
function startAddGoalHandler() {
setModalIsVisible(true);
}
function endAddGoalHandler() {
setModalIsVisible(false);
}
function addGoalHandler(enteredGoalText) {
setGoals((currentGoals) => [
...currentGoals,
{ text: enteredGoalText, id: Math.random().toString() },
]);
endAddGoalHandler();
}
function deleteGoalHandler(id) {
setGoals((currentGoals) => {
return currentGoals.filter((goal) => goal.id !== id);
});
}
return (
<>
<StatusBar style="light" />
<View style={styles.appContainer}>
<Button
title="Add New Goal"
color="#a065ec"
onPress={startAddGoalHandler}
/>
<GoalInput
visible={modalIsVisible}
onAddGoal={addGoalHandler}
onCancel={endAddGoalHandler}
/>
<View style={styles.goalsContainer}>
<FlatList
data={goals}
renderItem={(itemData) => {
return (
<GoalItem
text={itemData.item.text}
id={itemData.item.id}
onDeleteItem={deleteGoalHandler}
/>
);
}}
keyExtractor={(item, index) => {
return item.id;
}}
alwaysBounceVertical={false}
/>
</View>
</View>
</>
);
}
const styles = StyleSheet.create({
appContainer: {
flex: 1,
paddingTop: 50,
paddingHorizontal: 16,
},
goalsContainer: {
flex: 6,
},
});
{
"expo": {
"name": "RNC",
"slug": "RNC",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"backgroundColor": "#1e085a",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
import { useState } from "react";
import {
View,
TextInput,
Button,
StyleSheet,
Modal,
Image,
} from "react-native";
function GoalInput(props) {
const [enteredGoalText, setEnteredGoalText] = useState("");
function goalInputHandler(enteredText) {
setEnteredGoalText(enteredText);
}
function addGoalHandler() {
props.onAddGoal(enteredGoalText);
setEnteredGoalText("");
}
return (
<Modal visible={props.visible} animationType="slide">
<View style={styles.inputContainer}>
<Image
style={styles.image}
source={require("../assets/images/goal.png")}
/>
<TextInput
style={styles.textInput}
placeholder="Your goal"
onChangeText={goalInputHandler}
value={enteredGoalText}
/>
<View style={styles.buttonContainer}>
<View style={styles.button}>
<Button title="Cancel" onPress={props.onCancel} color="#f31282" />
</View>
<View style={styles.button}>
<Button title="Add Goal" onPress={addGoalHandler} color="#b180f0" />
</View>
</View>
</View>
</Modal>
);
}
export default GoalInput;
const styles = StyleSheet.create({
inputContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center",
padding: 16,
backgroundColor: "#311b6b",
},
image: {
width: 100,
height: 100,
margin: 20,
},
textInput: {
borderWidth: 1,
borderColor: "#e4d0ff",
backgroundColor: "#e4d0ff",
color: "#120438",
borderRadius: 6,
width: "100%",
padding: 8,
},
buttonContainer: {
marginTop: 16,
flexDirection: "row",
},
button: {
width: 100,
marginHorizontal: 8,
},
});
import { StyleSheet, View, Text, Pressable } from "react-native";
function GoalItem(props) {
return (
<View style={styles.goalItem}>
<Pressable
android_ripple={{ color: "#ddddd" }}
onPress={props.onDeleteItem.bind(this, props.id)}
style={({ pressed }) => pressed && styles.pressedItem}
>
<Text style={styles.goalText}>{props.text}</Text>
</Pressable>
</View>
);
}
export default GoalItem;
const styles = StyleSheet.create({
goalItem: {
margin: 8,
borderRadius: 6,
backgroundColor: "#5e0acc",
},
pressedItem: {
opacity: 0.5,
},
goalText: {
color: "white",
padding: 8,
},
});
{
"name": "rnc",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "~45.0.0",
"expo-status-bar": "~1.3.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-web": "0.17.7"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
"private": true
}
This diff could not be displayed because it is too large.