Created
July 22, 2022 12:46
-
-
Save happyharis/c8d8b56abe7727f750a83b16ceb9a5a9 to your computer and use it in GitHub Desktop.
PCMOB6 NotesScreenDetails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FontAwesome } from "@expo/vector-icons"; | |
import { useNavigation, useRoute } from "@react-navigation/native"; | |
import React, { useRef, useState } from "react"; | |
import { | |
KeyboardAvoidingView, | |
Platform, | |
StyleSheet, | |
Text, | |
TextInput, | |
TouchableOpacity, | |
View, | |
} from "react-native"; | |
export default function NotesScreenDetails() { | |
const route = useRoute(); | |
const titleInputRef = useRef(); | |
const navigation = useNavigation(); | |
const params = route.params; | |
const [noteTitle, setNoteTitle] = useState(params.title); | |
const [noteBody, setNoteBody] = useState(params.content); | |
const [editable, setEditable] = useState(false); | |
return ( | |
<KeyboardAvoidingView | |
style={styles.container} | |
behavior={Platform.OS === "ios" ? "padding" : "height"} | |
> | |
<View style={{ flexDirection: "row", alignItems: "center" }}> | |
<TouchableOpacity onPress={() => navigation.goBack()}> | |
<FontAwesome name={"arrow-left"} size={24} color={"black"} /> | |
</TouchableOpacity> | |
<View style={{ flex: 1 }} /> | |
<TouchableOpacity | |
onPress={() => { | |
setEditable(!editable); | |
if (!editable) { | |
setTimeout(() => titleInputRef.current.focus(), 100); | |
} else { | |
setTimeout(() => titleInputRef.current.blur(), 100); | |
} | |
}} | |
> | |
<FontAwesome | |
name={"pencil"} | |
size={24} | |
color={editable ? "forestgreen" : "black"} | |
/> | |
</TouchableOpacity> | |
<TouchableOpacity onPress={() => {}} style={{ marginLeft: 15 }}> | |
<FontAwesome name={"trash"} size={24} color={"black"} /> | |
</TouchableOpacity> | |
</View> | |
<TextInput | |
style={styles.noteTitle} | |
placeholder={"note title"} | |
value={noteTitle} | |
onChangeText={(text) => setNoteTitle(text)} | |
selectionColor={"gray"} | |
editable={editable} | |
ref={titleInputRef} | |
/> | |
<TextInput | |
style={styles.noteBody} | |
placeholder={"Add your notes"} | |
value={noteBody} | |
onChangeText={(text) => setNoteBody(text)} | |
selectionColor={"gray"} | |
editable={editable} | |
multiline={true} | |
/> | |
<View style={{ flex: 1 }} /> | |
<TouchableOpacity style={styles.button} onPress={async () => {}}> | |
<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", | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment