import { supabase } from '@/lib/supabase'; import { router } from 'expo-router'; import { useEffect, useRef, useState } from 'react'; import { Alert, Animated, Keyboard, KeyboardAvoidingView, KeyboardEvent, Platform, Pressable, ScrollView, Text, TextInput, TouchableWithoutFeedback, View, } from 'react-native'; export default function CreateUser() { const [email, SetEmail] = useState(''); const [password, SetPassword] = useState(''); const [isLoading, SetIsLoading] = useState(false); const [isKeyboardVisible, setIsKeyboardVisible] = useState(false); const scrollViewRef = useRef(null); const cardLift = useRef(new Animated.Value(0)).current; useEffect(() => { const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow'; const hideEvent = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide'; const handleKeyboardShow = (event: KeyboardEvent) => { setIsKeyboardVisible(true); const keyboardHeight = event.endCoordinates.height; const liftAmount = Math.min( Platform.OS === 'ios' ? keyboardHeight * 0.5 : keyboardHeight * 0.6, 260 ); Animated.timing(cardLift, { toValue: -liftAmount, duration: event.duration ?? 220, useNativeDriver: true, }).start(); }; const handleKeyboardHide = () => { setIsKeyboardVisible(false); Animated.timing(cardLift, { toValue: 0, duration: 220, useNativeDriver: true, }).start(); }; const showSubscription = Keyboard.addListener(showEvent, handleKeyboardShow); const hideSubscription = Keyboard.addListener(hideEvent, handleKeyboardHide); return () => { showSubscription.remove(); hideSubscription.remove(); }; }, [cardLift]); const SignUp = async () => { if (email.trim() === '' || password.trim() === '') { Alert.alert('All fields are required!'); return; } SetIsLoading(true); const { data, error } = await supabase.auth.signUp({ email: email.trim(), password, }); SetIsLoading(false); if (error) { Alert.alert(error.message, 'User could not be created, please try again'); return; } if (!data.session) { Alert.alert( 'Check your email', 'Your account was created. Please confirm your email before signing in.' ); router.replace('/login'); return; } router.replace('/setup'); }; const inputClassName = 'rounded-2xl border border-app-border bg-app-subtle px-4 py-3 text-base text-text-main'; return ( Study Sprint Organize subjects, assignments, and tasks in one calm workflow. Create account Start your next study sprint. What this app does Study Sprint helps you move from subject to assignment to task, then into a focused sprint. Why an account exists Your account keeps that structure and your tracked study progress attached to you. Email Password {isLoading ? 'Creating account...' : 'Create account'} router.push('/login')} > Already have an account? Log in ); }