Skip to content

Instantly share code, notes, and snippets.

@happyharis
Last active October 14, 2023 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save happyharis/fa8b26e45178fcd856f2a069fa20b0a6 to your computer and use it in GitHub Desktop.
Save happyharis/fa8b26e45178fcd856f2a069fa20b0a6 to your computer and use it in GitHub Desktop.
PCMOB4 Notes Starter Code
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import React from "react";
import NotesScreenAdd from "./screens/NotesScreenAdd";
import NotesScreenHome from "./screens/NotesScreenHome";
const Stack = createStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={NotesScreenHome}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Add"
component={NotesScreenAdd}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
const { getDefaultConfig } = require("@expo/metro-config");
const defaultConfig = getDefaultConfig(__dirname);
defaultConfig.resolver.assetExts.push("cjs");
module.exports = defaultConfig;
import { FontAwesome } from "@expo/vector-icons";
import { useNavigation } from "@react-navigation/native";
import React, { useState } from "react";
import {
KeyboardAvoidingView,
Platform,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from "react-native";
export default function NotesScreenAdd() {
const navigation = useNavigation();
const [noteTitle, setNoteTitle] = useState("");
async function savePost() {}
return (
<KeyboardAvoidingView
style={styles.container}
behavior={Platform.OS === "ios" ? "padding" : "height"}
>
<TouchableOpacity onPress={() => navigation.goBack()}>
<FontAwesome name={"arrow-left"} size={24} color={"black"} />
</TouchableOpacity>
<TextInput
style={styles.noteTitle}
placeholder={"note title"}
value={noteTitle}
onChangeText={(text) => setNoteTitle(text)}
selectionColor={"gray"}
/>
<View style={{ flex: 1 }} />
<TouchableOpacity
style={styles.button}
onPress={async () => await savePost()}
>
<Text style={styles.buttonText}>Save</Text>
</TouchableOpacity>
</KeyboardAvoidingView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
paddingTop: 60,
padding: 25,
},
noteTitle: {
fontSize: 24,
fontWeight: "600",
marginTop: 30,
marginBottom: 25,
},
noteBody: {
fontSize: 15,
fontWeight: "400",
},
button: {
backgroundColor: "black",
borderRadius: 15,
width: "100%",
marginBottom: 20,
},
buttonText: {
textAlign: "center",
fontWeight: "400",
fontSize: 17,
padding: 20,
color: "white",
},
});
import { useNavigation } from "@react-navigation/native";
import React from "react";
import {
FlatList,
StyleSheet,
Text,
TouchableOpacity,
View,
} from "react-native";
import { FontAwesome } from "@expo/vector-icons";
export default function NotesScreenHome() {
const navigation = useNavigation();
const posts = [
{ title: "Add new notes", content: "New notes are everything", id: "1" },
];
function renderItem({ item }) {
return (
<View style={styles.noteCard}>
<Text style={styles.noteCardTitle}>{item.title}</Text>
<TouchableOpacity onPress={() => {}}>
<FontAwesome name={"remove"} size={24} color={"black"} />
</TouchableOpacity>
</View>
);
}
return (
<View style={styles.container}>
<Text style={styles.title}>notes</Text>
<FlatList
data={posts}
renderItem={renderItem}
keyExtractor={(post) => post.id.toString()}
/>
<View style={{ flex: 1 }} />
<TouchableOpacity
style={styles.button}
onPress={() => navigation.navigate("Add")}
>
<Text style={styles.buttonText}>Add</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
noteCard: {
borderColor: "gray",
borderWidth: 1,
padding: 15,
borderRadius: 5,
marginBottom: 15,
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
},
noteCardTitle: {
fontSize: 13,
fontWeight: "500",
},
container: {
flex: 1,
backgroundColor: "#fff",
paddingTop: 100,
padding: 25,
},
title: {
fontWeight: "bold",
fontSize: 40,
marginBottom: 20,
},
button: {
backgroundColor: "black",
borderRadius: 15,
width: "100%",
},
buttonText: {
textAlign: "center",
fontWeight: "400",
fontSize: 17,
padding: 20,
color: "white",
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment