import { StyleSheet, Text, View, KeyboardAvoidingView, Platform, Pressable, TextInput, ScrollView } from "react-native" import { router, } from "expo-router" import { useNotes } from "@/src/notes/NotesContext" import { useState, useRef } from "react" import { useSafeAreaInsets } from "react-native-safe-area-context" import { useHeaderHeight } from "@react-navigation/elements" import { useAppTheme } from "@/src/theme/AppThemeProvider" export default function NewNoteScreen() { const { addNote, errorMessage } = useNotes() const [title, setTitle] = useState("") const [content, setContent] = useState("") const [isSaving, setIsSaving] = useState(false) const [localErrorMessage, setLocalErrorMessage] = useState(null) const insets = useSafeAreaInsets() const headerHeight = useHeaderHeight() const { colorScheme, palette } = useAppTheme() const [contentHeight, setContentHeight] = useState(160) const scrollRef = useRef(null) const onSave = async () => { if(!title.trim() || !content.trim()) { setLocalErrorMessage("Title and content are required.") return } setIsSaving(true) setLocalErrorMessage(null) const wasSaved = await addNote(title, content) setIsSaving(false) if (wasSaved) { router.back() } } return ( {setContentHeight(e.nativeEvent.contentSize.height) scrollRef.current?.scrollToEnd({ animated: true }) }}/> {localErrorMessage ? ( {localErrorMessage} ) : null} {!localErrorMessage && errorMessage ? ( {errorMessage} ) : null} {isSaving ? "Saving..." : "Save note"} ) } const styles = StyleSheet.create( { keyboardAvoider: { flex: 1 }, container: { flex: 1 }, formContent: { padding: 16, gap: 12 }, titleInput: { borderWidth: 1, borderRadius: 8, padding: 12, fontSize: 22, fontWeight: "700", }, contentInput: { borderWidth: 1, borderRadius: 8, padding: 12, fontSize: 16, }, actions: { position: "absolute", left: 16, right: 16, flexDirection: "row", gap: 12, }, saveButton: { flex: 1, borderRadius: 12, paddingVertical: 14, alignItems: "center", shadowColor: "#000", shadowOpacity: 0.18, shadowOffset: { width: 0, height: 8 }, shadowRadius: 16, elevation: 8, }, saveFloatingText: { fontSize: 16, fontWeight: "700" }, errorText: { color: "#c62828" }, } )