Guest User

Untitled

a guest
Sep 12th, 2022
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {useState} from 'react'
  2. import { View, Text, Image, StyleSheet, useWindowDimensions, ScrollView, Alert, TextInput } from 'react-native'
  3. import Logo  from '../../../assets/images/logo-main.png'
  4. import CustomButton from '../../components/CustomButton/CustomButton';
  5. import CustomInput from '../../components/CustomInput/CustomInput';
  6. import { useNavigation } from '@react-navigation/native';
  7.  
  8. import {useForm} from 'react-hook-form';
  9.  
  10. import { Auth } from 'aws-amplify';
  11.  
  12. const LoginScreen = () => {
  13.  
  14.     const [loading, setLoading] = useState(false);
  15.     const {height} = useWindowDimensions();
  16.     const {control, handleSubmit, formState: { errors } } = useForm();
  17.     const navigation = useNavigation();
  18.  
  19.     const onLoginPressed = (data) => {
  20.         console.log(data, errors)
  21.         // if (loading) {
  22.         //     return;
  23.         // }
  24.         // setLoading(true);
  25.         // try {
  26.         //     response = await Auth.signIn(data.username, data.password);
  27.         //     console.log(response);
  28.         // } catch(e) {
  29.         //     Alert.alert('Opps', e.message);
  30.         // }
  31.         // setLoading(false);
  32.     };
  33.  
  34.     const onForgotPasswordPressed = () => {
  35.         navigation.navigate('ForgotPassword');
  36.     }
  37.  
  38.     const onRegisterPressed = () => {
  39.         navigation.navigate('Register')
  40.     }
  41.  
  42.   return (
  43.     <ScrollView contentContainerStyle={{ flexGrow: 1, justifyContent: 'center' }} showsVerticalScrollIndicator={false}>
  44.         <View style={styles.root}>
  45.         <Image source={Logo} style={[styles.logo, {height : height * 0.2}]} resizeMode={'contain'} />
  46.  
  47.         <CustomInput name='username' placeholder='Username' control={control} />
  48.         <CustomInput password='password' placeholder='Password' secureTextEntry={true} control={control}/>
  49.  
  50.         <TextInput placeholder='Password'/>
  51.  
  52.         <CustomButton text={loading ? 'Loading...' : 'Login Account'} onPress={handleSubmit(onLoginPressed)} />
  53.         <CustomButton text='Forgot Password?' onPress={onForgotPasswordPressed} type='TERTIARY' />
  54.         <CustomButton text="Don't have an account? Create one" onPress={onRegisterPressed} type='TERTIARY' />
  55.         </View>
  56.     </ScrollView>
  57.   );
  58. };
  59.  
  60. const styles = StyleSheet.create({
  61.     root: {
  62.         alignItems: 'center',
  63.         padding: 20,
  64.     },
  65.  
  66.     logo: {
  67.         width: 200,
  68.         maxWidth: 300,
  69.         maxHeight: 300,
  70.     },
  71. });
  72.  
  73. export default LoginScreen;
Advertisement
Add Comment
Please, Sign In to add comment